Exemplo n.º 1
0
        public void MajorDiagonalWinRegistersProperly()
        {
            /*   |1| | | |
             *   |0|1| |0|
             *   |1|0|1|0|
             *   |0|1|0|1|
             * */

            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 2));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 3));
            var move5     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 1));
            var move6     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move7     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));
            var move8     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 2));
            var move9     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move10    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move11    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move12             = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);
        }
Exemplo n.º 2
0
        public void GetGameMovesIsEmptyForNewGame()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var moves     = GameKeeper.GetGameMoves(newGameId);

            Assert.IsEmpty(moves);
        }
Exemplo n.º 3
0
        public void CanGetGameState()
        {
            var gameId1   = GameKeeper.AddGame(4, 4, players);
            var gameState = GameKeeper.GetGameState(gameId1);

            Assert.IsNotNull(gameState);
            Assert.AreEqual(Game.GameStates.IN_PROGRESS, gameState.State);
            Assert.IsNull(gameState.Winner);
            Assert.AreEqual(players, gameState.Players);
        }
Exemplo n.º 4
0
        public void CanGetGameIds()
        {
            var gameId1 = GameKeeper.AddGame(4, 4, players);
            var gameId2 = GameKeeper.AddGame(4, 4, players);
            var gameIds = GameKeeper.GetGameIds();

            Assert.IsNotEmpty(gameIds);
            Assert.Contains(gameId1, gameIds);
            Assert.Contains(gameId2, gameIds);
        }
Exemplo n.º 5
0
        public void SamePlayerCantPlayTwoTokenMovesInARow()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);

            GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));

            Assert.Throws <OutOfTurnException>(new TestDelegate(() =>
            {
                GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            }));
        }
Exemplo n.º 6
0
        public void CanGetAllGameMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var moves = GameKeeper.GetGameMoves(newGameId);

            Assert.AreEqual(4, moves.Count());
        }
Exemplo n.º 7
0
        public void CanAddGamesWithExpectedIds()
        {
            var gameId1 = GameKeeper.AddGame(4, 4, players);
            var gameId2 = GameKeeper.AddGame(4, 4, players);

            Assert.NotNull(gameId1);
            Assert.NotNull(gameId2);
            Assert.AreNotEqual(string.Empty, gameId1);
            Assert.AreNotEqual(string.Empty, gameId2);
            Assert.AreEqual("Game0", gameId1);
            Assert.AreEqual("Game1", gameId2);
        }
Exemplo n.º 8
0
        public void PuttingTokenInFullColumnWillThrow()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));

            // the first column should now be full...try one more
            Assert.Throws <IllegalMoveException>(() => {
                var move5 = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            });
        }
Exemplo n.º 9
0
        public void CanPostMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));

            Assert.AreEqual(0, move1);
            Assert.AreEqual(1, move2);

            var moves = GameKeeper.GetGameMoves(newGameId);

            Assert.AreEqual(2, moves.Count());
        }
Exemplo n.º 10
0
        public void CanGetFirstTwoGameMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var moves = GameKeeper.GetGameMoves(newGameId, 0, 1);

            Assert.AreEqual(2, moves.Count());
            Assert.AreEqual(0, ((TokenMove)moves.First()).Column);
            Assert.AreEqual(1, ((TokenMove)moves.Last()).Column);
        }
Exemplo n.º 11
0
        public void PlayerCanQuitEvenWhenNotThatPlayersTurn()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move2 = GameKeeper.RegisterMove(newGameId, new QuitMove(players[0]));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);     // the player that didn't quit is the winner
        }
Exemplo n.º 12
0
        public void CanGetFirstGameMove()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var move = GameKeeper.GetGameMove(newGameId, move1);

            Assert.AreEqual(players[0], move.Player);
            Assert.AreEqual(DropTokenGame.MoveTypes.MOVE, move.MoveType);
            Assert.AreEqual(0, ((TokenMove)move).Column);
        }
Exemplo n.º 13
0
 public CreateGameResponse CreateGame(CreateGameRequest request)
 {
     try
     {
         var gameId = GameKeeper.AddGame(request.rows, request.columns, request.players);
         return(new CreateGameResponse()
         {
             gameId = gameId
         });
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
         {
             Content = new StringContent(ex.Message)
         });
     }
 }
Exemplo n.º 14
0
        public void RowWinRegistersProperly()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 1));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move5     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 2));
            var move6     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 2));

            // each player should have 3 tokens on the board - player 0 in column 3 should win with one more token there...

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move7 = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[0], afterMoveGameState.Winner);
        }