Exemplo n.º 1
0
        public static bool rules(Point piece, Point destination)
        {
            int xDistance = Math.Abs(piece.X - destination.X);
            int yDistance = Math.Abs(piece.Y - destination.Y);

            if (xDistance == yDistance)
            {
                return(IterationCheck.isNoPieceBetweenDiagonal(piece, destination));
            }
            else if ((xDistance > 0 && yDistance == 0) || (yDistance > 0 && xDistance == 0))
            {
                return(IterationCheck.isNoPieceBetweenLinear(piece, destination));
            }

            return(false);
        }
Exemplo n.º 2
0
        public static bool rules(Point piece, Point destination, GameState gs)
        {
            int xDistance = Math.Abs(piece.X - destination.X);
            int yDistance = Math.Abs(piece.Y - destination.Y);

            if (xDistance == 0 || yDistance == 0)
            {
                return(false);
            }
            else if (xDistance != yDistance)
            {
                return(false);
            }
            else if (xDistance > 0)
            {
                return(IterationCheck.isNoPieceBetweenDiagonal(piece, destination, gs));
            }

            return(false);
        }
Exemplo n.º 3
0
        public static bool rules(Point piece, Point destination)
        {
            int xDistance = Math.Abs(piece.X - destination.X);
            int yDistance = Math.Abs(piece.Y - destination.Y);

            if (Board.board[piece].firstMove == true)
            {
                Point tempKingPoint = new Point('e', piece.Y);

                if (destination.X == tempKingPoint.X && destination.Y == tempKingPoint.Y)
                {
                    Piece tempKingPiece = Board.board[tempKingPoint];

                    if (tempKingPiece.type == PieceType.King && tempKingPiece.colour == Board.board[piece].colour &&
                        IterationCheck.isNoPieceBetweenLinear(piece, tempKingPoint) && tempKingPiece.firstMove == true)
                    {
                        Logic.castling = true;
                        return(true);
                    }
                }
            }

            if (xDistance != 0 && yDistance != 0)
            {
                return(false);
            }
            else if (xDistance > 0 && yDistance > 0)
            {
                return(false);
            }
            else if (xDistance > 0 || yDistance > 0)
            {
                if (!IterationCheck.isNoPieceBetweenLinear(piece, destination))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public static bool rules(Point piece, Point destination, GameState gs, MinimaxBoardLogic logic)
        {
            int xDistance = Math.Abs(piece.X - destination.X);
            int yDistance = Math.Abs(piece.Y - destination.Y);

            if (gs.state[piece].firstMove == true)
            {
                Point tempRookPoint = piece;

                if (piece.X - destination.X > 0)
                {
                    tempRookPoint = new Point('a', piece.Y);
                }
                else if (piece.X - destination.X < 0)
                {
                    tempRookPoint = new Point('h', piece.Y);
                }


                if (destination.X == tempRookPoint.X && destination.Y == tempRookPoint.Y)
                {
                    Piece tempRookPiece = gs.state[tempRookPoint];

                    if (tempRookPiece.type == PieceType.Rook && tempRookPiece.colour == gs.state[piece].colour &&
                        IterationCheck.isNoPieceBetweenLinear(piece, tempRookPoint, gs) && tempRookPiece.firstMove == true)
                    {
                        logic.castling = true;
                        return(true);
                    }
                }
            }

            if (xDistance > 1 || yDistance > 1)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool rules(Point piece, Point destination, bool from1to8, bool?computerPawnPromotion = false)
        {
            int  xDistance      = Math.Abs(piece.X - destination.X);
            int  yDistance      = piece.Y - destination.Y;
            bool pawnsFirstMove = Board.board[piece].firstMove;

            if (from1to8)
            {
                if (yDistance != -1 && yDistance != -2)
                {
                    return(false);
                }
                else if (yDistance == -2 && !pawnsFirstMove)
                {
                    return(false);
                }
                else if (!IterationCheck.isNoPieceBetweenLinear(piece, destination))
                {
                    return(false);
                }
            }
            else
            {
                if (yDistance != 1 && yDistance != 2)
                {
                    return(false);
                }
                else if (yDistance == 2 && !pawnsFirstMove)
                {
                    return(false);
                }
                else if (!IterationCheck.isNoPieceBetweenLinear(piece, destination))
                {
                    return(false);
                }
            }

            if (xDistance != 0 && xDistance != 1)
            {
                return(false);
            }
            else if (xDistance == 0 && Board.board[destination].type != PieceType.Blank)
            {
                return(false);
            }
            else if (xDistance == 1 && Board.board[destination].type == PieceType.Blank &&
                     Board.board[new Point(destination.X, piece.Y)].type != PieceType.Pawn)
            {
                return(false);
            }
            else if (xDistance == 1 && Board.board[destination].type == PieceType.Blank &&
                     Board.board[new Point(destination.X, piece.Y)].type == PieceType.Pawn &&
                     Board.board[new Point(destination.X, piece.Y)].pawnDoubleSpace == false) // En passant
            {
                return(false);
            }

            if (Math.Abs(yDistance) == 2)
            {
                Board.board[piece].pawnDoubleSpace = true;
            }

            if (xDistance == 1 && Board.board[destination].type == PieceType.Blank &&
                Board.board[new Point(destination.X, piece.Y)].type == PieceType.Pawn &&
                Board.board[new Point(destination.X, piece.Y)].colour != Board.board[piece].colour &&
                Board.board[new Point(destination.X, piece.Y)].pawnDoubleSpace == true)
            {
                Logic.enPassant = true;
            }

            if (((from1to8 && (destination.Y == 8)) ||
                 (!from1to8 && (destination.Y == 1))))
            {
                char inputChar;
                bool promotionCompleted = false;

                while (!promotionCompleted)
                {
                    if (!computerPawnPromotion.Value)
                    {
                        Console.WriteLine("Pawn promotion! Please select a new peice:");
                        inputChar = char.ToLower(Console.ReadKey().KeyChar);
                    }
                    else
                    {
                        inputChar = 'q';
                    }

                    switch (inputChar)
                    {
                    case 'q':
                        Board.board[piece].type = PieceType.Queen;
                        promotionCompleted      = true;
                        break;

                    case 'r':
                        Board.board[piece].type = PieceType.Rook;
                        promotionCompleted      = true;
                        break;

                    case 'n':
                        Board.board[piece].type = PieceType.Knight;
                        promotionCompleted      = true;
                        break;

                    case 'b':
                        Board.board[piece].type = PieceType.Bishop;
                        promotionCompleted      = true;
                        break;

                    default:
                        Console.WriteLine("Incorrect entry - please enter what new piece you would like (q, r, n, b)");
                        break;
                    }
                }
            }

            return(true);
        }