Beispiel #1
0
        private static void TrainGames(QLearningAI ai1, RandomMoveAI ai2, int numGames)
        {
            GameState initialGameState = Simulate.CreateNewGameState();

            for (int game = 0; game < numGames; game++)
            {
                GameState gameState0 = initialGameState;
                while (true)
                {
                    PlayerInput playerInput0 = ai1.GetPlayerInput(gameState0, true);
                    GameState   gameState1   = Simulate.Tick(gameState0, playerInput0);

                    if (gameState1.Winner != BoardState.Winner.None)
                    {
                        ai1.UpdateQ(gameState0.BoardState, playerInput0, gameState1.BoardState);
                        break;
                    }

                    PlayerInput playerInput1 = ai2.GetPlayerInput(gameState1);
                    GameState   gameState2   = Simulate.Tick(gameState1, playerInput1);

                    if (gameState2.Winner != BoardState.Winner.None)
                    {
                        ai1.UpdateQ(gameState1.BoardState, playerInput1, gameState2.BoardState);
                        break;
                    }

                    ai1.UpdateQ(gameState0.BoardState, playerInput0, gameState2.BoardState);

                    gameState0 = gameState2;
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            GameState gameState = Simulate.CreateNewGameState();

            int          randomSeed = (int)((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
            RandomMoveAI ai         = new RandomMoveAI(randomSeed);

            while (gameState.Winner == BoardState.Winner.None)
            {
                Display.PrintGame(gameState);

                PlayerInput playerInput;
                if (gameState.NextPlayer == BoardState.Player.Player1)
                {
                    playerInput = KeyboardInput.GetPlayerInput(gameState);
                }
                else
                {
                    playerInput = ai.GetPlayerInput(gameState);
                }

                gameState = Simulate.Tick(gameState, playerInput);
            }

            Display.PrintGame(gameState);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            GameState gameState = Simulate.CreateNewGameState();

            while (gameState.Winner == BoardState.Winner.None)
            {
                Display.PrintGame(gameState);
                PlayerInput playerInput = KeyboardInput.GetPlayerInput(gameState);
                gameState = Simulate.Tick(gameState, playerInput);
            }

            Display.PrintGame(gameState);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            int width        = 40;
            int height       = 20;
            int maxRockets   = 3;
            int initialLives = 3;

            WorldState worldState = Simulate.CreateNewWorldState(width, height, maxRockets, width / 2, height / 4, initialLives);

            while (!worldState.GameProgressState.GameOver)
            {
                Simulate.PlayerInput playerInput = KeyboardInput.ReadPlayerInput();
                Display.PrintWorld(worldState);
                worldState = Simulate.Tick(worldState, playerInput);
                Thread.Sleep(250);
            }
        }