Пример #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)
        {
            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;
        }
Пример #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
        public Game()
        {
            chessBoard = new ChessBoard();
            viewer = new BoardViewer();
            while (true)
            {
                viewer.Show(chessBoard.Board);
                makeMove(viewer.getMoveInput());

            }
        }
Пример #5
0
 internal abstract bool validateMove(Move move, ChessBoard board);
Пример #6
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     throw new NotImplementedException();
 }
Пример #7
0
 internal override bool validateMove(Move move, ChessBoard board)
 {
     throw new NotImplementedException();
 }