예제 #1
0
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "print")
                {
                    LearningAI lai = new LearningAI(1);
                    lai.printProbabilities();
                    return;
                }

                if (args.Length == 2)
                {
                    int amount;
                    if (args[0] == "teach" && Int32.TryParse(args[1], out amount))
                    {
                        Game teachingGame = new Game(amount);
                        return;
                    }
                }
                Console.WriteLine("Usage: mono TicTacToe.exe print");
                Console.WriteLine("or");
                Console.WriteLine("Usage: mono TicTacToe.exe teach <AmountOfGamesToPlay>");
            }
            else
            {
                Game game = new Game();
                game.SetupGame();
                game.PlayGame();
            }
        }
예제 #2
0
 public Game(int amount)
 {
     p1  = new MiniMax(1);
     p2  = new LearningAI(-1);
     lai = (LearningAI)p2;
     Teach(amount);
 }
예제 #3
0
        public void PlayGame()
        {
            lai = p1 is LearningAI ? (LearningAI)p1 : (p2 is LearningAI ? (LearningAI)p2 : null);

            List <Board> aftermath = new List <Board>();

            Player curPlayer = p1;

            int[] pMove = new int[2] {
                -1, -1
            };

            bd.printBoard();

            while (!bd.isDone() && !bd.isFull())
            {
                pMove = curPlayer.move(bd);

                if (!bd.setMark(pMove[0], pMove[1], curPlayer.Mark))
                {
                    Console.Clear();
                    Console.WriteLine("Invalid input");
                    bd.printBoard();
                    continue;
                }

                if (lai != null)
                {
                    aftermath.Add(new Board(bd.copyBoard()));
                }

                curPlayer = curPlayer == p1 ? p2 : p1;

                bd.printBoard();
            }

            if (lai != null)
            {
                aftermath.Add(new Board(bd.copyBoard()));
                lai.updateProbabilities(aftermath, bd.getWinnerMark());
            }

            Rematch();
        }
예제 #4
0
 public Game()
 {
     rnd = new Random();
     lai = null;
 }