public bool LogicMove(int x1, int y1, int x2, int y2, Board board) { if (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)) { //es Knight if (piece.GetType() == typeof(Knight)) { if (board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); return(true); } if (!board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); return(true); } } else //no es Knight { if (board.IsEmpty(x2, y2) && !IsCastling(x1, y1, x2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board) && !board.IsPawn(x1, y1)) { if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && IsDiagonalEmpty(x1, y1, x2, y2, board)) || IsLineEmpty(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); CastlingChanges(x1, y1, x2, y2, piece); return(true); } } if (!board.IsEmpty(x2, y2) && !IsAlly(x1, y1, x2, y2, board) && !IsCastling(x1, y1, x2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board) && !board.IsPawn(x1, y1)) { if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && IsDiagonalEmpty(x1, y1, x2, y2, board)) || IsLineEmpty(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); CastlingChanges(x1, y1, x2, y2, piece); return(true); } } if (board.IsEmpty(x2, y2) && IsCastling(x1, y1, x2, board) && CanCastling(x1, y1, x2, board)) { board.Move(x1, y1, x2, y2); piece.CanCastling = false; MoveRookCastling(x1, y1, x2, board); return(true); } if (IsPawn(piece) && IsPawnCapturing(x1, x2) && !board.IsEmpty(x2, y2) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Remove(x2, y2); board.Move(x1, y1, x2, y2); if (Promoting(y2)) { board.Promotion(x2, y2, board.Turn); } return(true); } if (IsPawn(piece) && IsPawnCapturing(x1, x2) && EnPassant(x1, y1, x2, y2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.RemoveCapturePassant(x1, y1, x2, y2); board.Move(x1, y1, x2, y2); return(true); } if (IsPawn(piece) && !IsPawnCapturing(x1, x2) && board.IsEmpty(x2, y2) && IsLineEmpty(x1, y1, x2, y2, board) && !CantMoveIsCheck(x1, y1, x2, y2, board)) { board.Move(x1, y1, x2, y2); UpDateEnPassant(y1, y2, piece, board); if (Promoting(y2)) { board.Promotion(x2, y2, board.Turn); } return(true); } } } } return(false); }