Beispiel #1
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }

                    if (!board.IsEmpty(x2, y2) && !boardLogic.IsAlly(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Remove(x2, y2);
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (boardLogic.IsPawnCapturing(x1, x2) && !board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Remove(x2, y2);
                        board.Move(x1, y1, x2, y2);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }

                    if (boardLogic.IsPawnCapturing(x1, x2) && boardLogic.EnPassant(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.RemoveCapturePassant(x1, y1, x2, y2);
                        board.Move(x1, y1, x2, y2);
                        return(true);
                    }

                    if (!boardLogic.IsPawnCapturing(x1, x2) && board.IsEmpty(x2, y2) && boardLogic.IsLineEmpty(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        boardLogic.UpDateEnPassant(y1, y2, piece, board);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }