Exemplo n.º 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;
            }
        }
Exemplo n.º 2
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;
                }
            }
            else if (Math.Abs(move.to.Item1 - move.from.Item1) == Math.Abs(move.to.Item2 - move.from.Item2))
            {
                // End position possible
                int numberOfMoves = Math.Abs(move.to.Item1 - move.from.Item1) - 1;
                int moveYPosition = move.from.Item2;
                int moveXPosition = move.from.Item1;
                int Xdir = move.to.Item1 - move.from.Item1 > 0 ? 1 : -1;
                int Ydir = move.to.Item2 - move.from.Item2 > 0 ? 1 : -1;
                for (int i = 0; i < numberOfMoves; i++)
                {
                    moveXPosition += Xdir;
                    moveYPosition += Ydir;
                    if (board.Board[moveXPosition, moveYPosition].Piece != null)
                    {
                        return false;
                    }
                }
                return board.getSquare(move.to).Piece == null || board.getSquare(move.to).Piece.Colour != Colour;
            }
            return false;
        }
Exemplo n.º 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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 internal abstract bool validateMove(Move move, ChessBoard board);
Exemplo n.º 6
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     throw new NotImplementedException();
 }