Exemple #1
0
        public void Teach(int amount)
        {
            List <Board> aftermath = new List <Board>();
            Player       curPlayer = p1;

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

            Console.WriteLine("\n >> Teaching...");

            double curPercent      = 0.0;
            int    pointOnePercent = amount / 10000;

            for (int i = 0; i < amount; i++)
            {
                if (i % pointOnePercent == 0)
                {
                    curPercent = curPercent + 0.01;
                    Console.Write(String.Format(" >> {0:F1}%", curPercent));
                    Console.CursorLeft = 0;
                }

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

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

                    bd.setMark(pMove[0], pMove[1], curPlayer.Mark);

                    aftermath.Add(new Board(bd.copyBoard()));

                    curPlayer = curPlayer == p1 ? p2 : p1;
                }

                aftermath.Add(new Board(bd.copyBoard()));
                lai.updateProbabilities(aftermath, bd.getWinnerMark());
            }

            Console.CursorLeft = 0;
            Console.Write(" >> 100.0%");

            Console.WriteLine("\n >> Saving data...\n");
            lai.saveData();
        }
Exemple #2
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();
        }