Ejemplo n.º 1
0
        public void SetRemoveOperation_Test()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startKnightPosition = new Models.Position.Position(0, 1);
            var knightPosition1     = new Models.Position.Position(2, 1);
            var knightPosition2     = new Models.Position.Position(3, 0);

            // act
            var check0 = board.FigureAt(knightPosition1);
            var knight = board.RemoveFigure(startKnightPosition);

            board.SetFigure(knight, knightPosition1);
            var check1 = board.FigureAt(startKnightPosition);
            var check2 = board.FigureAt(knightPosition1);

            board.RemoveFigure(knightPosition1);
            board.SetFigure(knight, knightPosition2);
            var check3 = board.FigureAt(knightPosition1);
            var check4 = board.FigureAt(knightPosition2);

            // assert
            Assert.AreEqual(null, check0);
            Assert.AreEqual(null, check1);
            Assert.AreEqual(FigureType.Knight, check2.FigureType);
            Assert.AreEqual(null, check3);
            Assert.AreEqual(FigureType.Knight, check4.FigureType);
        }
        public void CanMove_Bishop_EnemyBlockPath_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBishopPosition    = new Models.Position.Position(0, 2);
            var destBishopPosition     = new Models.Position.Position(5, 7);
            var pawnPosition           = new Models.Position.Position(1, 3);
            var startEnemyPawnPosition = new Models.Position.Position(6, 6);
            var destEnemyPawnPosition  = new Models.Position.Position(4, 6);

            board.RemoveFigure(pawnPosition);
            var enemyPawn = board.RemoveFigure(startEnemyPawnPosition);

            enemyPawn.Move(destEnemyPawnPosition);
            board.SetFigure(enemyPawn, destEnemyPawnPosition);


            var bishop    = board.FigureAt(startBishopPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destBishopPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Queen_EnemyBlockPath_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startQueenPosition     = new Models.Position.Position(0, 3);
            var destQueenPosition      = new Models.Position.Position(4, 7);
            var pawnPosition           = new Models.Position.Position(1, 4);
            var enemyPawnStartPosition = new Models.Position.Position(6, 6);
            var enemyPawnEndPosition   = new Models.Position.Position(3, 6);

            board.RemoveFigure(pawnPosition);
            var enemyPawn = board.RemoveFigure(enemyPawnStartPosition);

            enemyPawn.Move(enemyPawnEndPosition);
            board.SetFigure(enemyPawn, enemyPawnEndPosition);

            var queen     = board.FigureAt(startQueenPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destQueenPosition);

            // assert
            Assert.False(result.Item1);
        }
Ejemplo n.º 4
0
        public void DefaultConstructor_InitializationTest()
        {
            // arrange

            // act
            var board       = new OrdinaryChessBoard();
            var whiteRock   = board.FigureAt(new Models.Position.Position(0, 0));
            var blackKnight = board.FigureAt(new Models.Position.Position(7, 1));
            var whiteBishop = board.FigureAt(new Models.Position.Position(0, 5));
            var blackQueen  = board.FigureAt(new Models.Position.Position(7, 3));
            var whiteKing   = board.FigureAt(new Models.Position.Position(0, 4));
            var blackPawn   = board.FigureAt(new Models.Position.Position(6, 2));

            // assert
            Assert.AreEqual(FigureType.Rook, whiteRock.FigureType);
            Assert.AreEqual(TeamColor.White, whiteRock.TeamColor);
            Assert.AreEqual(FigureType.Knight, blackKnight.FigureType);
            Assert.AreEqual(TeamColor.Black, blackKnight.TeamColor);
            Assert.AreEqual(FigureType.Bishop, whiteBishop.FigureType);
            Assert.AreEqual(TeamColor.White, whiteBishop.TeamColor);
            Assert.AreEqual(FigureType.Queen, blackQueen.FigureType);
            Assert.AreEqual(TeamColor.Black, blackQueen.TeamColor);
            Assert.AreEqual(FigureType.King, whiteKing.FigureType);
            Assert.AreEqual(TeamColor.White, whiteKing.TeamColor);
            Assert.AreEqual(FigureType.Pawn, blackPawn.FigureType);
            Assert.AreEqual(TeamColor.Black, blackPawn.TeamColor);
        }
Ejemplo n.º 5
0
        public void CopyConstructor_InitializationTest()
        {
            // arrange
            var baseBoard                 = new OrdinaryChessBoard();
            var expectedFigureType        = FigureType.Knight;
            var destinationPosition       = new Models.Position.Position(2, 1);
            var secondDestinationPosition = new Models.Position.Position(3, 0);

            // act
            var knight = baseBoard.RemoveFigure(new Models.Position.Position(0, 1));

            knight.Move(destinationPosition);
            baseBoard.SetFigure(knight, destinationPosition);
            var copyBoard = new OrdinaryChessBoard(baseBoard);

            baseBoard.RemoveFigure(destinationPosition);
            knight.Move(secondDestinationPosition);
            baseBoard.SetFigure(knight, secondDestinationPosition);

            // assert
            Assert.AreEqual(expectedFigureType, copyBoard.FigureAt(destinationPosition).FigureType);
            Assert.AreEqual(null, copyBoard.FigureAt(secondDestinationPosition));
        }
        public void CanMove_Rook_OutOfBoundaries_ShouldReturnFalse()
        {
            // arrange
            var board             = new OrdinaryChessBoard();
            var startRookPosition = new Models.Position.Position(0, 0);
            var destRookPosition  = new Models.Position.Position(-1, 0);
            var queen             = board.FigureAt(startRookPosition);
            var validator         = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destRookPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Queen_PositionAlreadyTakenByAlly_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startQueenPosition = new Models.Position.Position(0, 3);
            var destQueenPosition  = new Models.Position.Position(1, 4);
            var queen     = board.FigureAt(startQueenPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destQueenPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_King_PositionAlreadyTakenByAlly_ShouldReturnFalse()
        {
            // arrange
            var board        = new OrdinaryChessBoard();
            var destPosition = new Models.Position.Position(1, 4);
            var kingPosition = new Models.Position.Position(0, 4);
            var king         = board.FigureAt(kingPosition);
            var validator    = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(king, destPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Bishop_AllyBlockPath_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBishopPosition = new Models.Position.Position(0, 2);
            var destBishopPosition  = new Models.Position.Position(5, 7);

            var bishop    = board.FigureAt(startBishopPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destBishopPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Pawn_CanMove_ShouldReturnTrue()
        {
            // arrange
            var board             = new OrdinaryChessBoard();
            var startPawnPosition = new Models.Position.Position(1, 0);
            var destPawnPosition  = new Models.Position.Position(2, 0);

            var pawn      = board.FigureAt(startPawnPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(pawn, destPawnPosition);

            // assert
            Assert.True(result.Item1);
        }
        public void CanMove_Knight_OutOfBoundaries_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startKnightPosition = new Models.Position.Position(0, 1);
            var destKnightPosition  = new Models.Position.Position(-1, 3);

            var bishop    = board.FigureAt(startKnightPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destKnightPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Knight_AllyBlockPath_CanMove_ShouldReturnTrue()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startKnightPosition = new Models.Position.Position(0, 1);
            var destKnightPosition  = new Models.Position.Position(2, 2);

            var bishop    = board.FigureAt(startKnightPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destKnightPosition);

            // assert
            Assert.True(result.Item1);
        }
        public void CanMove_King_CanMove_ShouldReturnTrue()
        {
            // arrange
            var board        = new OrdinaryChessBoard();
            var destPosition = new Models.Position.Position(1, 4);
            var kingPosition = new Models.Position.Position(0, 4);

            board.RemoveFigure(destPosition);
            var king      = board.FigureAt(kingPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(king, destPosition);

            // assert
            Assert.True(result.Item1);
        }
        public void CanMove_Queen_CanMove_ShouldReturnTrue()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startQueenPosition = new Models.Position.Position(0, 3);
            var destQueenPosition  = new Models.Position.Position(4, 7);
            var pawnPosition       = new Models.Position.Position(1, 4);

            board.RemoveFigure(pawnPosition);
            var queen     = board.FigureAt(startQueenPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destQueenPosition);

            // assert
            Assert.True(result.Item1);
        }
        public void CanMove_Bishop_OutOfBoundaries_ShouldReturnFalse()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startBishopPosition = new Models.Position.Position(0, 2);
            var destBishopPosition  = new Models.Position.Position(5, 8);
            var pawnPosition        = new Models.Position.Position(1, 3);

            board.RemoveFigure(pawnPosition);
            var bishop    = board.FigureAt(startBishopPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destBishopPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Rook_EnemyBlockPath_ShouldReturnFalse()
        {
            // arrange
            var board             = new OrdinaryChessBoard();
            var startRookPosition = new Models.Position.Position(0, 0);
            var destRookPosition  = new Models.Position.Position(7, 0);
            var pawnPosition      = new Models.Position.Position(1, 0);

            board.RemoveFigure(pawnPosition);

            var queen     = board.FigureAt(startRookPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destRookPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Pawn_PositionAlreadyTakenByEnemy_NotAttack_ShouldReturnFalse()
        {
            // arrange
            var board              = new OrdinaryChessBoard();
            var startPawnPosition  = new Models.Position.Position(1, 0);
            var destPawnPosition   = new Models.Position.Position(2, 0);
            var enemyStartPosition = new Models.Position.Position(6, 0);

            var enemy = board.RemoveFigure(enemyStartPosition);

            enemy.Move(destPawnPosition);
            board.SetFigure(enemy, destPawnPosition);

            var pawn      = board.FigureAt(startPawnPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(pawn, destPawnPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_Rook_PositionAlreadyTakenByAlly_ShouldReturnFalse()
        {
            // arrange
            var board             = new OrdinaryChessBoard();
            var startRookPosition = new Models.Position.Position(0, 0);
            var destRookPosition  = new Models.Position.Position(4, 0);
            var pawnPosition      = new Models.Position.Position(1, 0);

            var pawn = board.RemoveFigure(pawnPosition);

            pawn.Move(destRookPosition);
            board.SetFigure(pawn, destRookPosition);

            var queen     = board.FigureAt(startRookPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(queen, destRookPosition);

            // assert
            Assert.False(result.Item1);
        }
        public void CanMove_King_PositionAlreadyTakenByEnemy_ShouldReturnTrue()
        {
            // arrange
            var board              = new OrdinaryChessBoard();
            var destPosition       = new Models.Position.Position(1, 4);
            var startEnemyPosition = new Models.Position.Position(6, 4);
            var kingPosition       = new Models.Position.Position(0, 4);

            board.RemoveFigure(destPosition);
            var enemyPawn = board.RemoveFigure(startEnemyPosition);

            enemyPawn.Move(destPosition);
            board.SetFigure(enemyPawn, destPosition);

            var king      = board.FigureAt(kingPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(king, destPosition);

            // assert
            Assert.True(result.Item1);
        }
        public void CanMove_Knight_PositionAlreadyTakenByEnemy_ShouldReturnTrue()
        {
            // arrange
            var board = new OrdinaryChessBoard();
            var startKnightPosition    = new Models.Position.Position(0, 1);
            var destKnightPosition     = new Models.Position.Position(2, 2);
            var enemyPawnStartPosition = new Models.Position.Position(6, 2);
            var enemyPawnEndPosition   = new Models.Position.Position(2, 2);

            var enemy = board.RemoveFigure(enemyPawnStartPosition);

            enemy.Move(enemyPawnEndPosition);
            board.SetFigure(enemy, enemyPawnEndPosition);

            var bishop    = board.FigureAt(startKnightPosition);
            var validator = new OrdinaryBoardMoveValidator(board);

            // act
            var result = validator.CanMove(bishop, destKnightPosition);

            // assert
            Assert.True(result.Item1);
        }