Skip to content

Commit

Permalink
Move more info to ServerVariants enum
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jan 12, 2025
1 parent df91b11 commit c0e81a6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion server/auto_pair.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from itertools import product
from random import random

from const import BYOS
from variants import BYOS
from misc import time_control_str
from newid import new_id
from seek import Seek
Expand Down
13 changes: 0 additions & 13 deletions server/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,6 @@ class GameStatus(IntEnum):
"flag": GameStatus.FLAG,
}

GRANDS = ("xiangqi", "manchu", "grand", "grandhouse", "shako", "janggi")
BYOS = (
"shogi",
"minishogi",
"kyotoshogi",
"dobutsu",
"gorogoroplus",
"torishogi",
"cannonshogi",
"janggi",
"shogun",
)

CONSERVATIVE_CAPA_FEN = "arnbqkbnrc/pppppppppp/10/10/10/10/PPPPPPPPPP/ARNBQKBNRC w KQkq - 0 1"
LOOKING_GLASS_ALICE_FEN = "|r|n|b|q|k|b|n|r/|p|p|p|p|p|p|p|p/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1"
MANCHU_FEN = "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/9/9/M1BAKAB2 w - - 0 1"
Expand Down
21 changes: 16 additions & 5 deletions server/deprecated.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Create mappings to compress variant, result and uci/usi move lists a little
# DEPRECATED (this is in ServerVariants enum from now on)
# All of this deprecated info is stored in ServerVariants enum now

GRANDS = ("xiangqi", "manchu", "grand", "grandhouse", "shako", "janggi")

BYOS = (
"shogi",
"minishogi",
"kyotoshogi",
"dobutsu",
"gorogoroplus",
"torishogi",
"cannonshogi",
"janggi",
"shogun",
)

V2C_ORIG = {
"ataxx": "Z",
"chess": "n",
Expand Down Expand Up @@ -59,7 +73,6 @@
}


# DEPRECATED (this is in ServerVariants enum from now on)
VARIANTS_ORIG = (
"chess",
"chess960",
Expand Down Expand Up @@ -135,7 +148,6 @@
"ataxx",
)

# DEPRECATED (this is in ServerVariants enum from now on)
VARIANT_ICONS_ORIG = {
"ataxx": "☣",
"makruk": "Q",
Expand Down Expand Up @@ -209,7 +221,6 @@
}


# DEPRECATED (this is in ServerVariants enum from now on)
def variant_display_name_orig(variant):
if variant == "seirawan":
return "S-CHESS"
Expand Down
3 changes: 1 addition & 2 deletions server/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
VARIANT_960_TO_PGN,
LOSERS,
VARIANTEND,
GRANDS,
CASUAL,
RATED,
IMPORTED,
Expand All @@ -38,7 +37,7 @@
from settings import URI
from spectators import spectators
from logger import log
from variants import get_server_variant
from variants import get_server_variant, GRANDS

if TYPE_CHECKING:
from pychess_global_app_state import PychessGlobalAppState
Expand Down
4 changes: 2 additions & 2 deletions server/game_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import pymongo

from compress import get_decode_method, C2R, decode_move_standard
from const import DARK_FEN, GRANDS, STARTED, MATE, INVALIDMOVE, VARIANTEND, CLAIM
from const import DARK_FEN, STARTED, MATE, INVALIDMOVE, VARIANTEND, CLAIM
from convert import zero2grand
from settings import ADMINS
from tournaments import get_tournament_name
from utils import pgn
from pychess_global_app_state_utils import get_app_state
from logger import log
from variants import C2V, get_server_variant, VARIANTS
from variants import C2V, GRANDS, get_server_variant, VARIANTS

GAME_PAGE_SIZE = 12

Expand Down
3 changes: 1 addition & 2 deletions server/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from const import (
ARENA,
CATEGORIES,
GRANDS,
SCHEDULE_MAX_DAYS,
TYPE_CHECKING,
DAILY,
Expand All @@ -22,7 +21,7 @@

from tournaments import new_tournament
from logger import log
from variants import get_server_variant
from variants import get_server_variant, GRANDS

from calendar import MONDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY

Expand Down
3 changes: 1 addition & 2 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
STARTED,
VARIANT_960_TO_PGN,
INVALIDMOVE,
GRANDS,
UNKNOWNFINISH,
CASUAL,
RATED,
Expand Down Expand Up @@ -50,7 +49,7 @@
from pychess_global_app_state import PychessGlobalAppState
from pychess_global_app_state_utils import get_app_state
from logger import log
from variants import C2V
from variants import C2V, GRANDS


async def tv_game(app_state: PychessGlobalAppState):
Expand Down
42 changes: 26 additions & 16 deletions server/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Variant:
display_name: str
icon: str
chess960: bool = False
grand: bool = False
byo: bool = False
bug: bool = False
move_encoding: Callable = encode_move_standard
move_decoding: Callable = decode_move_standard
Expand All @@ -37,6 +39,9 @@ def __init__(self, variant):
self.display_name = variant.display_name.upper()
self.translated_name = variant.display_name
self.icon = variant.icon
self.chess960 = variant.chess960
self.grand = variant.grand
self.byo = variant.byo

CHESS = Variant("n", "chess", _("Chess"), "M")
CHESS960 = Variant("n", "chess", _("Chess960"), "V", chess960=True)
Expand Down Expand Up @@ -67,17 +72,17 @@ def __init__(self, variant):
SITTUYIN = Variant("y", "sittuyin", _("Sittuyin"), ":")
ASEAN = Variant("S", "asean", _("ASEAN"), "♻")

SHOGI = Variant("g", "shogi", _("Shogi"), "K")
SHOGI = Variant("g", "shogi", _("Shogi"), "K", byo=True)
MINISHOGI = Variant("a", "minishogi", _("Minishogi"), "6")
KYOTOSHOGI = Variant("k", "kyotoshogi", _("Kyoto Shogi"), ")", move_encoding=encode_move_flipping, move_decoding=decode_move_flipping) # fmt: skip
DOBUTSU = Variant("D", "dobutsu", _("Dobutsu"), "8")
GOROGOROPLUS = Variant("G", "gorogoroplus", _("Gorogoro+"), "🐱")
TORISHOGI = Variant("T", "torishogi", _("Tori Shogi"), "🐦")
CANNONSHOGI = Variant("W", "cannonshogi", _("Cannon Shogi"), "💣")

XIANGQI = Variant("x", "xiangqi", _("Xiangqi"), "|")
MANCHU = Variant("M", "manchu", _("Manchu+"), "{")
JANGGI = Variant("j", "janggi", _("Janggi"), "=")
KYOTOSHOGI = Variant("k", "kyotoshogi", _("Kyoto Shogi"), ")", byo=True, move_encoding=encode_move_flipping, move_decoding=decode_move_flipping) # fmt: skip
DOBUTSU = Variant("D", "dobutsu", _("Dobutsu"), "8", byo=True)
GOROGOROPLUS = Variant("G", "gorogoroplus", _("Gorogoro+"), "🐱", byo=True)
TORISHOGI = Variant("T", "torishogi", _("Tori Shogi"), "🐦", byo=True)
CANNONSHOGI = Variant("W", "cannonshogi", _("Cannon Shogi"), "💣", byo=True)

XIANGQI = Variant("x", "xiangqi", _("Xiangqi"), "|", grand=True)
MANCHU = Variant("M", "manchu", _("Manchu+"), "{", grand=True)
JANGGI = Variant("j", "janggi", _("Janggi"), "=", grand=True, byo=True)
MINIXIANGQI = Variant("e", "minixiangqi", _("Minixiangqi"), "7")

SHATRANJ = Variant("†", "shatranj", _("Shatranj"), "🐘")
Expand All @@ -92,10 +97,10 @@ def __init__(self, variant):
SEIRAWAN = Variant("s", "seirawan", _("S-Chess"), "L")
SEIRAWAN960 = Variant("s", "seirawan", _("S-Chess960"), "}", chess960=True)
SHOUSE = Variant("z", "shouse", _("S-House"), "$")
GRAND = Variant("q", "grand", _("Grand"), "(")
GRANDHOUSE = Variant("r", "grandhouse", _("Grandhouse"), "*")
SHOGUN = Variant("u", "shogun", _("Shogun"), "-")
SHAKO = Variant("d", "shako", _("Shako"), "9")
GRAND = Variant("q", "grand", _("Grand"), "(", grand=True)
GRANDHOUSE = Variant("r", "grandhouse", _("Grandhouse"), "*", grand=True)
SHOGUN = Variant("u", "shogun", _("Shogun"), "-", byo=True)
SHAKO = Variant("d", "shako", _("Shako"), "9", grand=True)
HOPPELPOPPEL = Variant("w", "hoppelpoppel", _("Hoppel-Poppel"), "`")
MANSINDAM = Variant("I", "mansindam", _("Mansindam"), "⛵")

Expand All @@ -114,7 +119,7 @@ def __init__(self, variant):

@property
def server_name(self):
return self.value.uci_variant + ("960" if self.value.chess960 else "")
return self.uci_variant + ("960" if self.chess960 else "")


del _
Expand Down Expand Up @@ -142,7 +147,7 @@ def get_server_variant(uci_variant, chess960):
variant.server_name: variant for variant in ServerVariants if variant not in OLD_VARIANTS
}

VARIANT_ICONS = {variant.server_name: variant.value.icon for variant in ServerVariants}
VARIANT_ICONS = {variant.server_name: variant.icon for variant in ServerVariants}

# Remove new variants on prod site until they stabilize
if PROD:
Expand All @@ -151,8 +156,13 @@ def get_server_variant(uci_variant, chess960):

C2V = {variant.code: variant.uci_variant for variant in ServerVariants}

GRANDS = tuple(variant.server_name for variant in ServerVariants if variant.grand)

BYOS = tuple(variant.server_name for variant in ServerVariants if variant.byo)


if __name__ == "__main__":
print(GRANDS)

from deprecated import VARIANT_ICONS_ORIG, V2C_ORIG

Expand Down

0 comments on commit c0e81a6

Please sign in to comment.