예제 #1
0
        internal override bool validateMove(Move move, ChessBoard board)
        {
            int dir = Colour == "BLACK" ? -1 : 1;

            if (move.to.Item2 - move.from.Item2 == dir)
            {
                //Moving forward
                if (Math.Abs(move.to.Item1 - move.from.Item1) == 0)
                {
                    return(board.getSquare(move.to).Piece == null);
                }
                //Moving sideways
                if (Math.Abs(move.to.Item1 - move.from.Item1) == 1)
                {
                    return(board.getSquare(move.to).Piece != null && board.getSquare(move.to).Piece.Colour != Colour);
                }

                //Cheating
                return(false);
            }
            else if (!Moved && move.to.Item2 - move.from.Item2 == 2 * dir)
            {
                return(board.getSquare(move.to).Piece == null);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        internal override bool validateMove(Move move, ChessBoard board)
        {
            int dir = Colour == "BLACK" ? -1 : 1;

            if (move.to.Item2 - move.from.Item2 == dir)
            {
                //Moving forward
                if (Math.Abs(move.to.Item1 - move.from.Item1) == 0)
                {
                    return (board.getSquare(move.to).Piece == null);
                }
                //Moving sideways
                if (Math.Abs(move.to.Item1 - move.from.Item1) == 1)
                {
                    return (board.getSquare(move.to).Piece != null && board.getSquare(move.to).Piece.Colour != Colour);
                }

                //Cheating
                return false;
            }
            else if (!Moved && move.to.Item2 - move.from.Item2 == 2 * dir)
            {
                return (board.getSquare(move.to).Piece == null);
            }
            else
            {
                return false;
            }
        }
예제 #3
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     if ( Math.Abs(move.to.Item1-move.from.Item1) <= 1  && Math.Abs(move.to.Item2 - move.from.Item2) <= 1  &&
         ((Math.Abs(move.to.Item1 - move.from.Item1) + Math.Abs(move.to.Item2 - move.from.Item2) > 0)))
     {
         return board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour;
     }
     return false;
 }
예제 #4
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     if (Math.Abs(move.to.Item1 - move.from.Item1) <= 1 && Math.Abs(move.to.Item2 - move.from.Item2) <= 1 &&
         ((Math.Abs(move.to.Item1 - move.from.Item1) + Math.Abs(move.to.Item2 - move.from.Item2) > 0)))
     {
         return(board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour);
     }
     return(false);
 }
예제 #5
0
        private void makeMove(Move move)
        {
            Piece piece = chessBoard.getSquare(move.from).Piece;

            if (piece == null || !piece.validateMove(move, chessBoard))
            {
                Console.WriteLine("Invalid move.");
                return;
            }
            chessBoard.getSquare(move.to).Piece = piece;
            piece.Moved = true;
            chessBoard.getSquare(move.from).Piece = null;
        }
예제 #6
0
        internal override bool validateMove(Move move, ChessBoard board)
        {
            if ((Math.Abs(move.to.Item1 - move.from.Item1) > 0) ^ (Math.Abs(move.to.Item2 - move.from.Item2) > 0))
            {
                // End position possible
                if (Math.Abs(move.to.Item1 - move.from.Item1) > 0)
                {
                    int numberOfMoves = Math.Abs(move.to.Item1 - move.from.Item1)-1;
                    int movePosition = move.from.Item1;
                    int dir = move.to.Item1 - move.from.Item1 > 0 ? 1: -1;
                    for (int i = 0; i < numberOfMoves; i++)
                    {
                        movePosition += dir;
                        if (board.Board[movePosition, move.from.Item2].Piece != null)
                        {
                            return false;
                        }
                    }
                    return board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour;
                }
                if (Math.Abs(move.to.Item2 - move.from.Item2) > 0)
                {
                    int numberOfMoves = Math.Abs(move.to.Item2 - move.from.Item2)-1;
                    int movePosition = move.from.Item2;
                    int dir = move.to.Item2 - move.from.Item2 > 0 ? 1 : -1;
                    for (int i = 0; i < numberOfMoves; i++)
                    {
                        movePosition += dir;
                        if (board.Board[move.from.Item1,movePosition].Piece != null)
                        {
                            return false;
                        }
                    }

                    return board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour;
                }
            }
            return false;
        }
예제 #7
0
        internal override bool validateMove(Move move, ChessBoard board)
        {
            if ((Math.Abs(move.to.Item1 - move.from.Item1) > 0) ^ (Math.Abs(move.to.Item2 - move.from.Item2) > 0))
            {
                // End position possible
                if (Math.Abs(move.to.Item1 - move.from.Item1) > 0)
                {
                    int numberOfMoves = Math.Abs(move.to.Item1 - move.from.Item1) - 1;
                    int movePosition  = move.from.Item1;
                    int dir           = move.to.Item1 - move.from.Item1 > 0 ? 1: -1;
                    for (int i = 0; i < numberOfMoves; i++)
                    {
                        movePosition += dir;
                        if (board.Board[movePosition, move.from.Item2].Piece != null)
                        {
                            return(false);
                        }
                    }
                    return(board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour);
                }
                if (Math.Abs(move.to.Item2 - move.from.Item2) > 0)
                {
                    int numberOfMoves = Math.Abs(move.to.Item2 - move.from.Item2) - 1;
                    int movePosition  = move.from.Item2;
                    int dir           = move.to.Item2 - move.from.Item2 > 0 ? 1 : -1;
                    for (int i = 0; i < numberOfMoves; i++)
                    {
                        movePosition += dir;
                        if (board.Board[move.from.Item1, movePosition].Piece != null)
                        {
                            return(false);
                        }
                    }

                    return(board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour);
                }
            }
            return(false);
        }