Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jan 14, 2025
1 parent a57d120 commit 9e804ee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/fairy.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def shuffle_start(variant):
else:
body = "/pppppppp/8/8/8/8/PPPPPPPP/"

if variant in ("crazyhouse", "capahouse", "bughouse", "supply"):
if variant in ("crazyhouse", "capahouse", "bughouse"):
holdings = "[]"
elif seirawan:
holdings = "[HEhe]"
Expand Down
12 changes: 8 additions & 4 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,18 @@ def pgn(doc):
)


def sanitize_fen(variant, initial_fen, chess960):
def sanitize_fen(variant, initial_fen, chess960, base=False):
server_variant = get_server_variant(variant, chess960)
if server_variant.bug:
if server_variant.bug and not base:
fens = initial_fen.split(" | ")
fen_a = fens[0]
fen_b = fens[1]
fen_valid_a, sanitized_fen_a = sanitize_fen("crazyhouse", fen_a, chess960)
fen_valid_b, sanitized_fen_b = sanitize_fen("crazyhouse", fen_b, chess960)
fen_valid_a, sanitized_fen_a = sanitize_fen(
server_variant.base_variant, fen_a, chess960, base=True
)
fen_valid_b, sanitized_fen_b = sanitize_fen(
server_variant.base_variant, fen_b, chess960, base=True
)
return fen_valid_a and fen_valid_b, sanitized_fen_a + " | " + sanitized_fen_b

# Prevent alternate FENs to fail on our general castling check
Expand Down
14 changes: 9 additions & 5 deletions server/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Variant:
grand: bool = False
byo: bool = False
bug: bool = False
base_variant: str = ""
move_encoding: Callable = encode_move_standard
move_decoding: Callable = decode_move_standard

Expand All @@ -43,13 +44,14 @@ def __init__(self, variant):
self.grand = variant.grand
self.byo = variant.byo
self.bug = variant.bug
self.base_variant = variant.base_variant
self.move_encoding = variant.move_encoding
self.move_decoding = variant.move_decoding

CHESS = Variant("n", "chess", _("Chess"), "M")
CHESS960 = Variant("n", "chess", _("Chess960"), "V", chess960=True)
BUGHOUSE = Variant("F", "bughouse", _("Bughouse"), "¢", bug=True)
BUGHOUSE960 = Variant("F", "bughouse", _("Bughouse960"), "⌀", chess960=True, bug=True)
BUGHOUSE = Variant("F", "bughouse", _("Bughouse"), "¢", bug=True, base_variant="crazyhouse")
BUGHOUSE960 = Variant("F", "bughouse", _("Bughouse960"), "⌀", chess960=True, bug=True, base_variant="crazyhouse") # fmt: skip
CRAZYHOUSE = Variant("h", "crazyhouse", _("Crazyhouse"), "+")
CRAZYHOUSE960 = Variant("h", "crazyhouse", _("Crazyhouse960"), "%", chess960=True)
ATOMIC = Variant("A", "atomic", _("Atomic"), "~")
Expand Down Expand Up @@ -84,7 +86,8 @@ def __init__(self, variant):
CANNONSHOGI = Variant("W", "cannonshogi", _("Cannon Shogi"), "💣", byo=True)

XIANGQI = Variant("x", "xiangqi", _("Xiangqi"), "|", grand=True)
SUPPLY = Variant("@", "supply", _("Supply Chess"), "¢", grand=True, bug=True)
XIANGQIHOUSE = Variant("x", "xiangqihouse", _("Xiangqihouse"), "|", grand=True)
SUPPLY = Variant("@", "supply", _("Supply Chess"), "¢", grand=True, bug=True, base_variant="xiangqihouse") # fmt: skip
MANCHU = Variant("M", "manchu", _("Manchu+"), "{", grand=True)
JANGGI = Variant("j", "janggi", _("Janggi"), "=", grand=True, byo=True)
MINIXIANGQI = Variant("e", "minixiangqi", _("Minixiangqi"), "7")
Expand Down Expand Up @@ -133,11 +136,12 @@ def get_server_variant(uci_variant, chess960):
return ALL_VARIANTS[uci_variant + ("960" if chess960 else "")]


OLD_VARIANTS = (
NO_VARIANTS = (
ServerVariants.EMBASSY,
ServerVariants.GOTHIC,
ServerVariants.GOTHHOUSE,
ServerVariants.SHINOBI,
ServerVariants.XIANGQIHOUSE,
)

BUG_VARIANTS = tuple(variant for variant in ServerVariants if variant.bug)
Expand All @@ -146,7 +150,7 @@ def get_server_variant(uci_variant, chess960):
ALL_VARIANTS = {variant.server_name: variant for variant in ServerVariants}

VARIANTS = {
variant.server_name: variant for variant in ServerVariants if variant not in OLD_VARIANTS
variant.server_name: variant for variant in ServerVariants if variant not in NO_VARIANTS
}

VARIANT_ICONS = {variant.server_name: variant.icon for variant in ServerVariants}
Expand Down
15 changes: 15 additions & 0 deletions variants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,18 @@ commoner = k
castlingKingPiece = k
extinctionValue = loss
extinctionPieceTypes = k

# Hybrid variant of xiangqi and crazyhouse
[xiangqihouse:xiangqi]
startFen = rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR[] w - - 0 1
pieceDrops = true
capturesToHand = true
dropChecks = false
whiteDropRegion = *1 *2 *3 *4 *5
blackDropRegion = *6 *7 *8 *9 *10
mobilityRegionWhiteFers = d1 f1 e2 d3 f3
mobilityRegionBlackFers = d8 f8 e9 d10 f10
mobilityRegionWhiteElephant = c1 g1 a3 e3 i3 c5 g5
mobilityRegionBlackElephant = c6 g6 a8 e8 i8 c10 g10
mobilityRegionWhiteSoldier = a4 a5 c4 c5 e4 e5 g4 g5 i4 i5 *6 *7 *8 *9 *10
mobilityRegionBlackSoldier = *1 *2 *3 *4 *5 a6 a7 c6 c7 e6 e7 g6 g7 i6 i7

0 comments on commit 9e804ee

Please sign in to comment.