Пример #1
0
        public Direction ChooseDirection(SnakeControllerInputs controllerInputs)
        {
            var inputs = new AiControllerInputBuilder(controllerInputs)
                         .LookRight()
                         .LookLeft()
                         .LookUp()
                         .LookDown()
                         .LookForFood()
                         .BuildInputs();

            var outputs = neuralNetwork.GetOutputs(Vector.Build.DenseOfEnumerable(inputs));

            return((Direction)outputs.MaximumIndex());
        }
Пример #2
0
        public Direction ChooseDirection(SnakeControllerInputs controllerInputs)
        {
            var kb = Keyboard.GetState();

            if (kb.IsKeyDown(Keys.W))
            {
                return(Direction.Up);
            }
            if (kb.IsKeyDown(Keys.A))
            {
                return(Direction.Left);
            }
            if (kb.IsKeyDown(Keys.S))
            {
                return(Direction.Down);
            }
            if (kb.IsKeyDown(Keys.D))
            {
                return(Direction.Right);
            }

            return(Direction.None);
        }
 public AiControllerInputBuilder(SnakeControllerInputs controllerInputs)
 {
     this.controllerInputs = controllerInputs;
     inputs = new List <float>();
 }