コード例 #1
0
        public static void CheckUndo()
        {
            var moves  = 0;
            var board  = new Board();
            var player = Player.X;
            var states = new Player[Board.Dimension, Board.Dimension];

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(0, 0), new Point(0, 4));
            moves++;

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 2), new Point(0, 2));
            moves++;

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(2, 0), new Point(2, 4));
            moves++;

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 0), new Point(0, 0));
            moves++;

            ValidGameTests.UpdateStates(states,
                                        new Point[] { new Point(0, 4), new Point(2, 4) },
                                        new Point[] { new Point(0, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, moves);

            // Back to O's turn
            board.Undo();
            ValidGameTests.UpdateStates(states,
                                        new Point[] { new Point(0, 4), new Point(2, 4) },
                                        new Point[] { new Point(0, 2) });
            ValidGameTests.Verify(board, states, Player.None, Player.O, --moves);

            // Back to O's turn
            board.Undo(2);
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4) }, null);
            moves -= 2;
            ValidGameTests.Verify(board, states, Player.None, Player.O, moves);

            // Back to the start.
            board.Undo();
            ValidGameTests.UpdateStates(states, null, null);
            ValidGameTests.Verify(board, states, Player.None, Player.X, --moves);

            // This should be quietly ignore.
            board.Undo();
            ValidGameTests.UpdateStates(states, null, null);
            ValidGameTests.Verify(board, states, Player.None, Player.X, 0);
        }
コード例 #2
0
        public static void PlayValidGame()
        {
            var moves  = 0;
            var board  = new Board();
            var player = Player.X;
            var states = new Player[Board.Dimension, Board.Dimension];

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(0, 0), new Point(0, 4));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4) }, null);
            ValidGameTests.Verify(board, states, Player.None, Player.O, ++moves);

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 2), new Point(0, 2));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4) }, new Point[] { new Point(0, 2) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, ++moves);

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(2, 0), new Point(2, 4));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(2, 4) },
                                        new Point[] { new Point(0, 2) });
            ValidGameTests.Verify(board, states, Player.None, Player.O, ++moves);

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 0), new Point(0, 0));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(2, 4) },
                                        new Point[] { new Point(0, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, ++moves);

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 4), new Point(0, 4));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4) },
                                        new Point[] { new Point(0, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.O, ++moves);

            // 0
            ValidGameTests.MakeMove(board, ref player, states, new Point(0, 2), new Point(4, 2));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4) },
                                        new Point[] { new Point(4, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, ++moves);

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(3, 0), new Point(3, 4));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4), new Point(3, 3) },
                                        new Point[] { new Point(4, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.O, ++moves);

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 3), new Point(0, 3));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4), new Point(4, 3) },
                                        new Point[] { new Point(0, 3), new Point(4, 2), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, ++moves);

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 4), new Point(4, 0));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4), new Point(4, 4), new Point(4, 0) },
                                        new Point[] { new Point(0, 3), new Point(4, 3), new Point(0, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.O, ++moves);

            // O
            ValidGameTests.MakeMove(board, ref player, states, new Point(4, 2), new Point(4, 0));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(3, 4), new Point(4, 4), new Point(4, 1) },
                                        new Point[] { new Point(0, 3), new Point(4, 3), new Point(0, 0), new Point(4, 0) });
            ValidGameTests.Verify(board, states, Player.None, Player.X, ++moves);

            // X
            ValidGameTests.MakeMove(board, ref player, states, new Point(2, 4), new Point(0, 4));
            ValidGameTests.UpdateStates(states, new Point[] { new Point(0, 4), new Point(1, 4), new Point(2, 4), new Point(3, 4), new Point(4, 4), new Point(4, 1) },
                                        new Point[] { new Point(0, 3), new Point(4, 3), new Point(0, 0), new Point(4, 0) });
            ValidGameTests.Verify(board, states, Player.X, Player.None, ++moves);
        }