예제 #1
0
        public bool IsMoveLegal(BoardCoordinate origin, BoardCoordinate destination)
        {
            var isCapture = destination.IsCoordinateValidForBoardSize(_boardSize) && GetPiece(destination) != null;

            var isIllegalCapture    = isCapture && !GetPiece(origin).IsCaptureAllowed(origin, destination);
            var isIllegalNonCapture = !isCapture && !GetPiece(origin).IsNonCaptureAllowed(origin, destination);

            return(!isIllegalCapture && !isIllegalNonCapture && destination.IsCoordinateValidForBoardSize(_boardSize) &&
                   !IsBlocked(origin, destination) && !DoesFriendlyPieceExistAt(origin, destination));
        }
예제 #2
0
        public void AddPiece(Piece piece, BoardCoordinate moveTarget)
        {
            if (piece == null)
                throw new ArgumentNullException("piece");
            if (!moveTarget.IsCoordinateValidForBoardSize(_boardSize))
                throw new ArgumentException("moveTarget");

            SetPiece(piece, moveTarget);
        }
예제 #3
0
 private void SetEnPassantIfPawnExistsAtTarget(BoardCoordinate destination, BoardCoordinate enPassantTarget)
 {
     if (enPassantTarget.IsCoordinateValidForBoardSize(_boardSize))
     {
         var targetPawn = GetPiece(enPassantTarget) as Pawn;
         if (targetPawn != null)
         {
             targetPawn.SetCanPerformEnPassantOn(destination);
         }
     }
 }
예제 #4
0
        public void AddPiece(Piece piece, BoardCoordinate moveTarget)
        {
            if (piece == null)
            {
                throw new ArgumentNullException("piece");
            }
            if (!moveTarget.IsCoordinateValidForBoardSize(_boardSize))
            {
                throw new ArgumentException("moveTarget");
            }

            SetPiece(piece, moveTarget);
        }
예제 #5
0
        private bool IsMoveLegal(BoardCoordinate origin, BoardCoordinate destination)
        {
            var isCapture = destination.IsCoordinateValidForBoardSize(_boardSize) && GetPiece(destination) != null;

            var isIllegalCapture = isCapture && !GetPiece(origin).IsCaptureAllowed(origin, destination);
            var isIllegalNonCapture = !isCapture && !GetPiece(origin).IsNonCaptureAllowed(origin, destination);

            return !isIllegalCapture && !isIllegalNonCapture && destination.IsCoordinateValidForBoardSize(_boardSize) &&
                !IsBlocked(origin, destination) && !DoesFriendlyPieceExistAt(origin, destination);
        }
예제 #6
0
 private void SetEnPassantIfPawnExistsAtTarget(BoardCoordinate destination, BoardCoordinate enPassantTarget)
 {
     if (enPassantTarget.IsCoordinateValidForBoardSize(_boardSize))
     {
         var targetPawn = GetPiece(enPassantTarget) as Pawn;
         if (targetPawn != null)
             targetPawn.SetCanPerformEnPassantOn(destination);
     }
 }
예제 #7
0
            public void Returns_False_For_Y_Less_Than_Zero()
            {
                var coordinate = new BoardCoordinate(1, -23);

                Assert.IsFalse(coordinate.IsCoordinateValidForBoardSize(8));
            }
예제 #8
0
            public void Returns_False_For_X_Less_Than_Zero()
            {
                var coordinate = new BoardCoordinate(-12, 2);

                Assert.IsFalse(coordinate.IsCoordinateValidForBoardSize(5));
            }