Пример #1
0
 public TrainingModel(TTTModel model)
 {
     MoveX   = model.Move.X;
     MoveY   = model.Move.Y;
     Board   = model.Board;
     Winnner = ChangeCharPlayerToDouble(model.Winnner);
 }
Пример #2
0
        private static void PlayGame()
        {
            TTTGame         game   = new TTTGame();
            TTTModel        model  = new TTTModel();
            List <TTTModel> models = new List <TTTModel>();
            char            player = 'x';

            ShowBoard(game.Board);

            do
            {
                TTTCoord move;

                do
                {
                    Console.WriteLine("Vertical coordinate:");
                    string vert = Console.ReadLine();

                    Console.WriteLine("Horizontal coordinate:");
                    string hori = Console.ReadLine();

                    move = new TTTCoord(Convert.ToInt32(vert) - 1, Convert.ToInt32(hori) - 1);
                } while (!game.CheckMove(player, move));

                model  = game.PlayMove(player, move);
                player = game.Turn;

                models.Add(model);

                ShowBoard(game.Board);

                Console.WriteLine();
            } while (model.Winnner == default);

            char result = model.Winnner;

            if (result != default)
            {
                Console.WriteLine(result + " wins! " + game.MovesLeft + " moves left.");
            }
            else
            {
                Console.WriteLine("No one wins.");
            }

            Console.WriteLine("\nSaving game to file...\n");

            TSVRecorder tsvRecorder = new TSVRecorder();

            tsvRecorder.SaveGameToCSV(models.ToArray());

            Console.WriteLine("Game saved.");
        }
Пример #3
0
        private static void PlayRandomGames(int numberOfGames)
        {
            char   startPlayer = 'x';
            Random random      = new Random();

            for (int i = 0; i < numberOfGames; i++)
            {
                TTTGame         game   = new TTTGame();
                TTTModel        model  = new TTTModel();
                List <TTTModel> models = new List <TTTModel>();
                char            player = startPlayer;

                do
                {
                    TTTCoord move;

                    do
                    {
                        move = new TTTCoord(random.Next(3), random.Next(3));
                    } while (!game.CheckMove(player, move));

                    model  = game.PlayMove(player, move);
                    player = game.Turn;

                    models.Add(model);
                } while (model.Winnner == default && game.MovesLeft > 0);

                ShowBoard(game.Board);

                char result = model.Winnner;

                if (result != default)
                {
                    Console.WriteLine(result + " wins! " + game.MovesLeft + " moves left.");
                }
                else
                {
                    Console.WriteLine("No one wins.");
                }

                Console.WriteLine("\nSaving game to file...\n");

                TSVRecorder tsvRecorder = new TSVRecorder();
                tsvRecorder.SaveGameToCSV(models.ToArray());

                Console.WriteLine($"Game {i + 1} saved.");

                startPlayer = game.OppositePlayer(player);
            }
        }
Пример #4
0
        public TTTGame(ITTTSystemGUI _SystemGUI)
        {
            SystemGUI = _SystemGUI;

            tttModel   = new TTTModel(this);
            tttView    = new TTTView(this);
            tttControl = new TTTControl(this);

            tttModel.Init();
            tttView.Init();
            tttControl.Init();

            tttControl.Reset();
        }