From c0e81a670f33592139690c7b0cece4db1579dc77 Mon Sep 17 00:00:00 2001 From: gbtami Date: Sun, 12 Jan 2025 23:27:54 +0100 Subject: [PATCH] Move more info to ServerVariants enum --- server/auto_pair.py | 2 +- server/const.py | 13 ------------- server/deprecated.py | 21 ++++++++++++++++----- server/game.py | 3 +-- server/game_api.py | 4 ++-- server/scheduler.py | 3 +-- server/utils.py | 3 +-- server/variants.py | 42 ++++++++++++++++++++++++++---------------- 8 files changed, 48 insertions(+), 43 deletions(-) diff --git a/server/auto_pair.py b/server/auto_pair.py index 4017f8d90..40580a02a 100644 --- a/server/auto_pair.py +++ b/server/auto_pair.py @@ -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 diff --git a/server/const.py b/server/const.py index bc0789b4f..726b181ed 100644 --- a/server/const.py +++ b/server/const.py @@ -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" diff --git a/server/deprecated.py b/server/deprecated.py index 740f083b5..4e0764429 100644 --- a/server/deprecated.py +++ b/server/deprecated.py @@ -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", @@ -59,7 +73,6 @@ } -# DEPRECATED (this is in ServerVariants enum from now on) VARIANTS_ORIG = ( "chess", "chess960", @@ -135,7 +148,6 @@ "ataxx", ) -# DEPRECATED (this is in ServerVariants enum from now on) VARIANT_ICONS_ORIG = { "ataxx": "☣", "makruk": "Q", @@ -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" diff --git a/server/game.py b/server/game.py index 2983941ac..9f436b4ba 100644 --- a/server/game.py +++ b/server/game.py @@ -22,7 +22,6 @@ VARIANT_960_TO_PGN, LOSERS, VARIANTEND, - GRANDS, CASUAL, RATED, IMPORTED, @@ -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 diff --git a/server/game_api.py b/server/game_api.py index 468cb31f3..8c9c21409 100644 --- a/server/game_api.py +++ b/server/game_api.py @@ -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 diff --git a/server/scheduler.py b/server/scheduler.py index e1d02cb07..83d568015 100644 --- a/server/scheduler.py +++ b/server/scheduler.py @@ -7,7 +7,6 @@ from const import ( ARENA, CATEGORIES, - GRANDS, SCHEDULE_MAX_DAYS, TYPE_CHECKING, DAILY, @@ -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 diff --git a/server/utils.py b/server/utils.py index 87ca0dc68..f6b06921a 100644 --- a/server/utils.py +++ b/server/utils.py @@ -20,7 +20,6 @@ STARTED, VARIANT_960_TO_PGN, INVALIDMOVE, - GRANDS, UNKNOWNFINISH, CASUAL, RATED, @@ -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): diff --git a/server/variants.py b/server/variants.py index cc20f052c..4f4ae5a12 100644 --- a/server/variants.py +++ b/server/variants.py @@ -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 @@ -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) @@ -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"), "🐘") @@ -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"), "⛵") @@ -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 _ @@ -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: @@ -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