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));
            }
        }
Beispiel #2
0
        // Called when either the Computer or the human has chosen a move
        public void MakeMove(TicTacToeSquareModel square)
        {
            //  convert the square coordinates into a move object for the model
            var move = TicTacToeModel.CreateMove(square.row, square.col);
            // apply the move to the current game to get a new game state
            var newGame = TicTacToeModel.ApplyMove(gameState, move);

            // !! Hack to trick system into thinking that Stateful game states have actually changed
            gameState = default(Game);
            // update the current game state to this new game state
            gameState = newGame;
        }
Beispiel #3
0
        // called when a new game is to be started
        public void StartNewGame(int size, bool humanFirst)
        {
            lastSize = size;
            squares.Clear();
            // the new game may be a different size, so recreate all squares and connect their select commands to the HumanMove method
            for (int row = 0; row < size; row++)
            {
                for (int col = 0; col < size; col++)
                {
                    var square = new TicTacToeSquareModel(row, col);
                    square.SelectCommand.Subscribe(HumanMove);
                    squares.Add(square);
                }
            }

            // create a new model for the new game
            viewModelChild.StartNewGame(size, humanFirst);
        }
Beispiel #4
0
 // Called with the human has selected a square as their move
 public void HumanMove(TicTacToeSquareModel square)
 {
     // delegate the the model specific part of view model
     viewModelChild.HumanMove(square);
 }
Beispiel #5
0
 // Called when the human has selected a square
 public void HumanMove(TicTacToeSquareModel square)
 {
     //System.Diagnostics.Debug.Assert(IsHumanTurn);
     MakeMove(square);
 }