예제 #1
0
        public void Valid_King_Movement_Should_Satisfy()
        {
            Piece whiteKing = Piece.Create(PieceType.King, PieceColor.White);
            Piece blackKing = Piece.Create(PieceType.King, PieceColor.Black);

            ISpecification <PieceMovement> specification = MovementValidator.ResolveSpecification(_board, PieceType.King);

            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("E2")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("F1")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("D2")))
                );

            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("E7")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("F8")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("F7")))
                );
        }
예제 #2
0
        public void Valid_Queen_Movement_Should_Satisfy()
        {
            Piece whiteQueen = Piece.Create(PieceType.Queen, PieceColor.White);
            Piece blackQueen = Piece.Create(PieceType.Queen, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Queen);

            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteQueen, Position.Create("D1"), Position.Create("H1")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteQueen, Position.Create("D1"), Position.Create("D8")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whiteQueen, Position.Create("D1"), Position.Create("G4")))
                );

            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackQueen, Position.Create("D8"), Position.Create("A8")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackQueen, Position.Create("D8"), Position.Create("D3")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackQueen, Position.Create("D8"), Position.Create("H4")))
                );
        }
        public bool IsSatisfied(PieceMovement candidate)
        {
            var isMovementAllowedSpecification  = MovementValidator.ResolveSpecification(_board, candidate.Piece.Type);
            var isLandableMovementSpecification = LandableMovementSpecification.Create(_board);

            return(SpecificationEvaluator.And(candidate,
                                              isMovementAllowedSpecification,
                                              isLandableMovementSpecification));
        }
예제 #4
0
        public void Diagonal_Pawn_Movement_Should_Not_Satisfy()
        {
            Piece whitePawn = Piece.Create(PieceType.Pawn, PieceColor.White);

            _board.AddPiece(whitePawn, "D4");

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Pawn);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whitePawn, Position.Create("D4"), Position.Create("C5")))
                );
        }
예제 #5
0
        public void Inalid_Rook_Movement_Should_Not_Satisfy()
        {
            Piece whiteRook = Piece.Create(PieceType.Rook, PieceColor.White);
            Piece blackRook = Piece.Create(PieceType.Rook, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Rook);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteRook, Position.Create("A1"), Position.Create("C3")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackRook, Position.Create("A8"), Position.Create("C6")))
                );
        }
예제 #6
0
        public void NotInitial_Valid_Pawn_Movement_Should_Satisfy()
        {
            Piece whitePawn = Piece.Create(PieceType.Pawn, PieceColor.White);
            Piece blackPawn = Piece.Create(PieceType.Pawn, PieceColor.Black);

            whitePawn.Moved();
            blackPawn.Moved();

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Pawn);

            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(whitePawn, Position.Create("A2"), Position.Create("A3")))
                );
            Assert.IsTrue(
                specification.IsSatisfied(PieceMovement.Create(blackPawn, Position.Create("A7"), Position.Create("A6")))
                );
        }
예제 #7
0
        public void Initial_Invalid_Pawn_Movement_Should_Not_Satisfy()
        {
            Piece whitePawn = Piece.Create(PieceType.Pawn, PieceColor.White);
            Piece blackPawn = Piece.Create(PieceType.Pawn, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Pawn);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whitePawn, Position.Create("A2"), Position.Create("A5")))
                );
            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whitePawn, Position.Create("A2"), Position.Create("A1")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackPawn, Position.Create("A7"), Position.Create("A4")))
                );
            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackPawn, Position.Create("A7"), Position.Create("A8")))
                );
        }
예제 #8
0
        public void Inalid_King_Movement_Should_Not_Satisfy()
        {
            Piece whiteKing = Piece.Create(PieceType.King, PieceColor.White);
            Piece blackKing = Piece.Create(PieceType.King, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.King);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("E3")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteKing, Position.Create("E1"), Position.Create("H1")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("G6")))
                );
            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackKing, Position.Create("E8"), Position.Create("E1")))
                );
        }
예제 #9
0
        public void Inalid_Knight_Movement_Should_Not_Satisfy()
        {
            Piece whiteKnight = Piece.Create(PieceType.Knight, PieceColor.White);
            Piece blackKnight = Piece.Create(PieceType.Knight, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Knight);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteKnight, Position.Create("B1"), Position.Create("B3")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteKnight, Position.Create("B1"), Position.Create("C2")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackKnight, Position.Create("B8"), Position.Create("B5")))
                );
            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackKnight, Position.Create("B8"), Position.Create("D8")))
                );
        }
예제 #10
0
        public void Inalid_Bishop_Movement_Should_Not_Satisfy()
        {
            Piece whiteBishop = Piece.Create(PieceType.Bishop, PieceColor.White);
            Piece blackBishop = Piece.Create(PieceType.Bishop, PieceColor.Black);

            ISpecification <PieceMovement> specification = specification = MovementValidator.ResolveSpecification(_board, PieceType.Bishop);

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteBishop, Position.Create("C1"), Position.Create("C3")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(whiteBishop, Position.Create("C1"), Position.Create("H1")))
                );

            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackBishop, Position.Create("C8"), Position.Create("D6")))
                );
            Assert.IsFalse(
                specification.IsSatisfied(PieceMovement.Create(blackBishop, Position.Create("C8"), Position.Create("A8")))
                );
        }