示例#1
0
        public void Game_3x3_IsGameOver2()
        {
            bool won  = false;
            var  game = GameBoardFactory.Create(3);

            game.GameWon += (s, e) =>
            {
                Assert.AreEqual(GameBoard.Player.Cross, e.Player);
                won = true;
            };

            //    0   1   2
            // 0 [x] [o] [x]
            // 1 [o] [o] [x]
            // 2 [ ] [ ] [x]

            game.Move(GameBoard.Player.Cross, 0, 0)
            .Move(GameBoard.Player.Circle, 0, 1)
            .Move(GameBoard.Player.Cross, 0, 2)
            .Move(GameBoard.Player.Circle, 1, 0)
            .Move(GameBoard.Player.Circle, 1, 1)
            .Move(GameBoard.Player.Cross, 1, 2)
            .Move(GameBoard.Player.Cross, 2, 2);

            Assert.IsTrue(game.IsGameOver);
            Assert.IsTrue(won);
        }
示例#2
0
        public void Game_3x3_ThrowsIfCantMove()
        {
            var game = GameBoardFactory.Create(3);

            Assert.IsTrue(game.CanMove(0, 0));
            game.Move(GameBoard.Player.Circle, 0, 0);
            game.Move(GameBoard.Player.Cross, 0, 0);
        }
示例#3
0
        public void Game_3x3_MoveToEmpty()
        {
            var game = GameBoardFactory.Create(3);

            Assert.IsTrue(game.CanMove(0, 0));
            game.Move(GameBoard.Player.Circle, 0, 0);
            Assert.IsFalse(game.CanMove(0, 0));
        }
        public void TestInitialize()
        {
            var board = GameBoardFactory.Create(3);

            p1       = new TestPlayer(GameBoard.Player.Circle);
            p2       = new TestPlayer(GameBoard.Player.Cross);
            observer = new TestObserver();
            game     = new Game(board, p1, p2, observer);
        }
示例#5
0
        public void Game_3x3_CanMoveToEmpty()
        {
            var game = GameBoardFactory.Create(3);

            Assert.IsTrue(game.CanMove(0, 0));
            Assert.IsTrue(game.CanMove(2, 2));
            Assert.IsTrue(game.CanMove(2, 0));
            Assert.IsTrue(game.CanMove(0, 2));
        }
示例#6
0
        public void Game_3x3_MoveToEmpty_EventRaised()
        {
            var moved = false;
            var game  = GameBoardFactory.Create(3);

            game.PlayerMoved += (s, e) => { moved = true; };
            game.Move(GameBoard.Player.Circle, 0, 0);
            Assert.IsTrue(moved);
        }
示例#7
0
        public void Winkelzug(string name, string gameBoardData, string moves, string expectedResult, int boardDimension)
        {
            var gameBoardFactory = new GameBoardFactory();
            IList<Field> gameBoard = gameBoardFactory.Create(gameBoardData, boardDimension);

            Moves moveHelper = new Moves(gameBoard);
            moveHelper.PerformMoves(moves);

            gameBoardFactory.VerifyFields(gameBoard, expectedResult);
        }
示例#8
0
        public void IsFinishedEqualsTrueWhenThirdMoveIsMade(string gameBoardData, string moves, int boardDimension, bool expectedResultForIsFinished)
        {
            var gameBoardFactory = new GameBoardFactory();
            IList<Field> gameBoard = gameBoardFactory.Create(gameBoardData, boardDimension);

            Moves moveHelper = new Moves(gameBoard);
            moveHelper.PerformMoves(moves);

            moveHelper.IsActualMoveFinished.Should().Be(expectedResultForIsFinished);
        }
示例#9
0
        public void IsAsExpectedWhenWinkelzugIsMade(string gameBoardData, string moves, int boardDimension, bool expectedResultForIsValidMove)
        {
            var gameBoardFactory = new GameBoardFactory();
            IList<Field> gameBoard = gameBoardFactory.Create(gameBoardData, boardDimension);

            Moves moveHelper = new Moves(gameBoard);
            moveHelper.PerformMoves(moves);

            moveHelper.IsActualMoveValid.Should().Be(expectedResultForIsValidMove);
        }
示例#10
0
        /// <summary>
        /// Creates 3x3 game with give player and other player as BOT.
        /// </summary>
        public static Game CreateGameWithBot(IPlayer player)
        {
            var board = GameBoardFactory.Create(3);
            var game  = new Game(
                board,
                player,
                new SimpleBot(player.Id.Other()),
                new DefaultGameObserver());

            return(game);
        }
示例#11
0
        public static Game Create1v1Game(IPlayer p1, IPlayer p2, IGameStateObserver observer)
        {
            var board = GameBoardFactory.Create(3);
            var game  = new Game(
                board,
                p1,
                p2,
                observer);

            return(game);
        }
示例#12
0
        /// <summary>
        /// Creates 3x3 game with give player and other player as BOT.
        /// </summary>
        public static Game CreateGameWithBot(IPlayer player, IGameStateObserver observer)
        {
            var board = GameBoardFactory.Create(3);
            var game  = new Game(
                board,
                player,
                new AdvancedBot(player.Id.Other()),
                observer);

            return(game);
        }
示例#13
0
        public void Game_3x3_Winner3()
        {
            bool won  = false;
            var  game = GameBoardFactory.Create(3);

            game.GameWon += (s, e) =>
            {
                Assert.AreEqual(GameBoard.Player.Cross, e.Player);
                won = true;
            };
            game.Move(GameBoard.Player.Cross, 0, 0);
            game.Move(GameBoard.Player.Cross, 1, 1);
            game.Move(GameBoard.Player.Cross, 2, 2);

            Assert.IsTrue(won);
        }
示例#14
0
        public void Game_2x2_SmokeTest()
        {
            var won  = false;
            var game = GameBoardFactory.Create(2);

            game.GameWon += (s, e) =>
            {
                Assert.AreEqual(GameBoard.Player.Circle, e.Player);
                won = true;
            };

            game.Move(GameBoard.Player.Circle, 0, 0)
            .Move(GameBoard.Player.Cross, 1, 0)
            .Move(GameBoard.Player.Circle, 0, 1);

            Assert.IsTrue(won);
            Assert.IsTrue(game.IsGameOver);
        }
示例#15
0
 public static void Main(string[] args)
 {
     var gameBoardFactory = new GameBoardFactory();
     var tmp = gameBoardFactory.Create();
 }