예제 #1
0
        static void Play(EngineRepository repository, string engineId)
        {
            IEngine trained;

            if (String.IsNullOrEmpty(engineId))
            {
                trained = repository.GetTopEngines(1).First();
            }
            else
            {
                trained = repository.Load(engineId);
            }

            int White = 0;
            int Black = 0;

            do
            {
                IEngine randomEngine = repository.CreateRandom();
                var     game         = new Game(randomEngine, trained);
                var     printer      = new TicTacToePrinter(game.Board);

                CellValue color = game.Play();

                if (color == CellValue.White)
                {
                    White++;
                }
                else if (color == CellValue.Black)
                {
                    Black++;
                }

                Console.Write(printer.Print());

                Console.WriteLine($"{color} has won");
                Console.WriteLine($"White: {White} Black: {Black}");
            }while (Console.ReadKey(true).KeyChar != 'q');
        }
예제 #2
0
        static void PlayAgainsHuman(EngineRepository repository, string engineId)
        {
            IEngine engine;
            IEngine human = new Human();

            if (String.IsNullOrEmpty(engineId))
            {
                engine = repository.GetTopEngines(1).First();
            }
            else
            {
                engine = repository.Load(engineId);
            }

            var game    = new Game(human, engine);
            var color   = game.Play();
            var printer = new TicTacToePrinter(game.Board);

            Console.Write(printer.Print());
            Console.WriteLine($"{color} has won");
            Console.ReadKey(true);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var playerOne = Player.NewPlayer("1");
            var game      = TicTacToeGame.NewTicTacToeGame("1", playerOne);

            var playerTwo = Player.NewPlayer("2");

            game.JoinGame(playerTwo);

            var gamePrinter = new TicTacToePrinter(game);

            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            game.MarkLocation(0, 0);
            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            game.MarkLocation(0, 1);
            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            game.MarkLocation(1, 0);
            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            game.MarkLocation(2, 1);
            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            game.MarkLocation(2, 0);
            Console.WriteLine(gamePrinter.PrintBoard());
            Console.ReadLine();

            Console.WriteLine("Is game over?: " + game.IsGameOver);
            Console.WriteLine("Winner: " + gamePrinter.PrintWinner());
            Console.ReadLine();
        }