private void PlayGame(bool humanFirst, int size, params ValueTuple <int, int>[] moves)
        {
            viewModel = new TicTacToeViewModel();

            viewModel.AutoStartComputerMove = false;
            // Computer doesn't automatically start thinking about it's move when it's the computer's turn
            // so that we can examine the state of the system before the computer move starts

            // viewModel.StartNewGame(size, humanFirst);

            square1 = viewModel.FindSquare(0, 0);
            square2 = viewModel.FindSquare(0, 1);
            square3 = viewModel.FindSquare(0, 2);
            square4 = viewModel.FindSquare(1, 0);
            square5 = viewModel.FindSquare(1, 1);
            square6 = viewModel.FindSquare(1, 2);
            square7 = viewModel.FindSquare(2, 0);
            square8 = viewModel.FindSquare(2, 1);
            square9 = viewModel.FindSquare(2, 2);

            foreach (var move in moves)
            {
                viewModel.HumanMove(viewModel.FindSquare(move.Item1, move.Item2));
            }
        }
Пример #2
0
        // Called when it's the computer's turn to make a move
        public async Task <TicTacToeSquareModel> ComputerMove()
        {
            System.Diagnostics.Debug.Assert(IsComputerTurn);

            startThinking = DateTime.Now;
            parent.Idle   = false;

            // wait until the computer has finished deciding
            var move = await ComputerThink();

            finishThinking = DateTime.Now;
            parent.Idle    = true;

            var square = parent.FindSquare(move.Row, move.Col);

            // apply the chosen move to update the state of the game
            MakeMove(square);

            return(square);
        }
        public void Test()
        {
            PlayGame(true, 3);

            // test that the outcome is as expected ...
            Assert.AreEqual("Your turn ...", viewModel.Message);
            Assert.IsFalse(viewModel.IsGameOver);
            Assert.IsTrue(viewModel.IsHumanTurn);

            for (int row = 0; row < 3; row++)
            {
                for (int col = 0; col < 3; col++)
                {
                    var square = viewModel.FindSquare(row, col);
                    Assert.IsTrue(square.IsHumanTurn);
                    Assert.IsTrue(square.IsEnabled);
                    Assert.IsFalse(square.HighLight);
                    Assert.AreEqual("", square.Piece);
                    Assert.AreEqual(row, square.row);
                    Assert.AreEqual(col, square.col);
                }
            }
        }