Esempio n. 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');
        }
Esempio n. 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);
        }