Пример #1
0
        private bool IsMovePathClear(IChessPiece piece, int toXCoordinate, int toYCoordinate)
        {
            var yDirection = MovementDirection(toYCoordinate, piece.YCoordinate);
            var xDirection = MovementDirection(toXCoordinate, piece.XCoordinate);

            var y = piece.YCoordinate + yDirection;
            var x = piece.XCoordinate + xDirection;

            while ((yDirection == 0 || y != toYCoordinate) && (xDirection == 0 || x != toXCoordinate))
            {
                if (pieces[x, y] != null)
                {
                    return(false);
                }
                y += yDirection;
                x += xDirection;
            }

            //TODO - this should be an indicator, not a type-specific check
            if (piece.GetType() == typeof(Pawn))
            {
                //if destination has a piece, reject this move
                if (pieces[toXCoordinate, toYCoordinate] != null)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Determines of the container has capacity for the passed in chess piece
        /// </summary>
        /// <param name="piece">The <see cref="IChessPiece"/> to be added</param>
        /// <returns>True if there is enough capacity</returns>
        public bool HasCapacityFor(IChessPiece piece)
        {
            Type pieceType = piece.GetType();

            if (piece.PieceColor == PieceColor.Black)
            {
                return(BlackPieces.Where(p => p.GetType() == pieceType).Count() < piece.NumberPiecesAllowedPerColour);
            }
            else
            {
                return(WhitePieces.Where(p => p.GetType() == pieceType).Count() < piece.NumberPiecesAllowedPerColour);
            }
        }
Пример #3
0
 private IChessPiece TakingEnPassant(IChessPiece piece, int toXCoordinate, int toYCoordinate)
 {
     if (piece.GetType() == typeof(Pawn))
     {
         var opponentPiece = pieces[toXCoordinate, piece.YCoordinate];
         if (opponentPiece.GetType() == typeof(Pawn) &&
             opponentPiece.PieceColor != piece.PieceColor &&
             opponentPiece.LastMoveNumber == moveCounter)
         {
             return(opponentPiece);
         }
     }
     return(null);
 }