diff --git a/server/admin.py b/server/admin.py index 1e3d6ff3f..0d3e4a3fb 100644 --- a/server/admin.py +++ b/server/admin.py @@ -2,11 +2,12 @@ import collections from broadcast import broadcast_streams -from const import NONE_USER, TYPE_CHECKING, VARIANTS +from const import NONE_USER, TYPE_CHECKING from generate_crosstable import generate_crosstable from generate_highscore import generate_highscore from login import logout from settings import ADMINS, FISHNET_KEYS +from variants import VARIANTS if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState diff --git a/server/const.py b/server/const.py index 5fdfa6c35..275620aad 100644 --- a/server/const.py +++ b/server/const.py @@ -156,7 +156,7 @@ class GameStatus(IntEnum): MANCHU_R_FEN = "m1bakab1r/9/9/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1" DARK_FEN = "********/********/********/********/********/********/********/******** w - - 0 1" -VARIANTS = ( +VARIANTS_ORIG = ( "chess", "chess960", "bughouse", @@ -233,9 +233,9 @@ class GameStatus(IntEnum): # Remove new variants on prod site until they stabilize if PROD: - VARIANTS = tuple(e for e in VARIANTS if e not in ["bughouse", "bughouse960"]) + VARIANTS_ORIG = tuple(e for e in VARIANTS_ORIG if e not in ["bughouse", "bughouse960"]) -VARIANT_ICONS = { +VARIANT_ICONS_ORIG = { "ataxx": "☣", "makruk": "Q", "makpong": "O", diff --git a/server/game.py b/server/game.py index fbad320b5..5fe59d6e6 100644 --- a/server/game.py +++ b/server/game.py @@ -39,7 +39,7 @@ from settings import URI from spectators import spectators from logger import log -from variants import SERVER_VARIANTS +from variants import VARIANTS if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState @@ -100,7 +100,7 @@ def __init__( self.create = create self.imported_by = "" - self.server_variant = SERVER_VARIANTS[ + self.server_variant = VARIANTS[ ("_" if variant[0].isdigit() else "") + variant + ("960" if chess960 else "") ] diff --git a/server/game_api.py b/server/game_api.py index 7f1e4a8da..229dc0d4e 100644 --- a/server/game_api.py +++ b/server/game_api.py @@ -11,13 +11,14 @@ import pymongo from compress import get_decode_method, C2V, V2C, C2R, decode_move_standard -from const import DARK_FEN, GRANDS, STARTED, MATE, VARIANTS, INVALIDMOVE, VARIANTEND, CLAIM +from const import DARK_FEN, GRANDS, 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 VARIANTS GAME_PAGE_SIZE = 12 diff --git a/server/generate_highscore.py b/server/generate_highscore.py index c60c2db2e..2fec2c2aa 100644 --- a/server/generate_highscore.py +++ b/server/generate_highscore.py @@ -4,7 +4,8 @@ from sortedcollections import ValueSortedDict -from const import VARIANTS, HIGHSCORE_MIN_GAMES, MAX_HIGHSCORE_ITEM_LIMIT +from const import HIGHSCORE_MIN_GAMES, MAX_HIGHSCORE_ITEM_LIMIT +from variants import VARIANTS async def generate_highscore(app_state, one_variant=None): diff --git a/server/generate_shield.py b/server/generate_shield.py index 7b5925d99..ca0c2b1ec 100644 --- a/server/generate_shield.py +++ b/server/generate_shield.py @@ -1,6 +1,7 @@ from __future__ import annotations from compress import V2C -from const import SHIELD, VARIANTS, T_STARTED, TYPE_CHECKING +from const import SHIELD, T_STARTED, TYPE_CHECKING +from variants import VARIANTS if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState diff --git a/server/index.py b/server/index.py index 90a95406b..959a601b8 100644 --- a/server/index.py +++ b/server/index.py @@ -57,7 +57,7 @@ ) from custom_trophy_owners import CUSTOM_TROPHY_OWNERS from logger import log -from variants import SERVER_VARIANTS, VARIANT_ICONS +from variants import VARIANTS, VARIANT_ICONS async def index(request): @@ -243,7 +243,7 @@ def video_target(target): return web.HTTPFound("/") variant = request.match_info.get("variant") - if (variant is not None) and ((variant not in SERVER_VARIANTS) and variant != "terminology"): + if (variant is not None) and ((variant not in VARIANTS) and variant != "terminology"): log.debug("Invalid variant %s in request", variant) raise web.HTTPNotFound() @@ -396,7 +396,7 @@ def video_target(target): "profile": profileId if profileId is not None else "", "variant": variant if variant is not None else "", "fen": fen.replace(".", "+").replace("_", " ") if fen is not None else "", - "variants": SERVER_VARIANTS, + "variants": VARIANTS, "variant_display_name": variant_display_name, "tournamentdirector": user.username in TOURNAMENT_DIRECTORS, } @@ -439,7 +439,7 @@ def video_target(target): if profileId in CUSTOM_TROPHY_OWNERS: trophies = CUSTOM_TROPHY_OWNERS[profileId] for v, kind in trophies: - if v in SERVER_VARIANTS: + if v in VARIANTS: render["trophies"].append((v, kind)) render["title"] = "Profile • " + profileId @@ -487,7 +487,7 @@ def video_target(target): render["highscore"] = { variant: dict(app_state.highscore[variant].items()[:10]) for variant in app_state.highscore - if variant in SERVER_VARIANTS + if variant in VARIANTS } else: hs = app_state.highscore[variant] @@ -518,10 +518,10 @@ def video_target(target): else: puzzleId = request.match_info.get("puzzleId") - if puzzleId in SERVER_VARIANTS: + if puzzleId in VARIANTS: user.puzzle_variant = puzzleId puzzleId = None - elif variant in SERVER_VARIANTS: + elif variant in VARIANTS: user.puzzle_variant = variant else: user.puzzle_variant = None diff --git a/server/puzzle.py b/server/puzzle.py index 7c7a0fc35..20a88e6d4 100644 --- a/server/puzzle.py +++ b/server/puzzle.py @@ -8,10 +8,10 @@ from mongomock_motor import AsyncMongoMockClient -from const import VARIANTS from fairy import FairyBoard from glicko2.glicko2 import MU, gl2, Rating, rating from pychess_global_app_state_utils import get_app_state +from variants import VARIANTS # variants having 0 puzzle so far NO_PUZZLE_VARIANTS = ( diff --git a/server/pychess_global_app_state.py b/server/pychess_global_app_state.py index 628192e68..8d9424d31 100644 --- a/server/pychess_global_app_state.py +++ b/server/pychess_global_app_state.py @@ -22,7 +22,6 @@ from ai import BOT_task from const import ( NONE_USER, - VARIANTS, LANGUAGES, MAX_CHAT_LINES, MONTHLY, @@ -64,6 +63,7 @@ from videos import VIDEOS from youtube import Youtube from logger import log +from variants import VARIANTS GAME_KEEP_TIME = 1800 # keep game in app[games_key] for GAME_KEEP_TIME secs @@ -378,7 +378,7 @@ def __init_translations(self): translation.install() - for variant in VARIANTS + PAUSED_MONTHLY_VARIANTS: + for variant in tuple(VARIANTS.keys()) + PAUSED_MONTHLY_VARIANTS: if ( variant in MONTHLY_VARIANTS or variant in NEW_MONTHLY_VARIANTS diff --git a/server/tournaments.py b/server/tournaments.py index b31994bc4..7d2607149 100644 --- a/server/tournaments.py +++ b/server/tournaments.py @@ -18,7 +18,6 @@ T_FINISHED, T_ARCHIVED, SHIELD, - VARIANTS, MAX_CHAT_LINES, CATEGORIES, TRANSLATED_FREQUENCY_NAMES, @@ -35,6 +34,7 @@ from swiss import SwissTournament from tournament import GameData, PlayerData, SCORE_SHIFT, Tournament from logger import log +from variants import VARIANTS async def create_or_update_tournament( diff --git a/server/user.py b/server/user.py index 5e338d9bb..6e6bd1f41 100644 --- a/server/user.py +++ b/server/user.py @@ -9,7 +9,7 @@ from aiohttp.web_ws import WebSocketResponse from broadcast import round_broadcast -from const import ANON_PREFIX, STARTED, VARIANTS, TEST_PREFIX +from const import ANON_PREFIX, STARTED, TEST_PREFIX from glicko2.glicko2 import gl2, DEFAULT_PERF, Rating from login import RESERVED_USERS from newid import id8 @@ -17,6 +17,7 @@ from const import BLOCK, MAX_USER_BLOCK, TYPE_CHECKING from seek import Seek from websocket_utils import ws_send_json +from variants import VARIANTS if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState diff --git a/server/users.py b/server/users.py index f8682be24..8e7059e71 100644 --- a/server/users.py +++ b/server/users.py @@ -1,10 +1,11 @@ from __future__ import annotations from collections import UserDict -from const import ANON_PREFIX, BLOCK, MAX_USER_BLOCK, NONE_USER, VARIANTS, TYPE_CHECKING +from const import ANON_PREFIX, BLOCK, MAX_USER_BLOCK, NONE_USER, TYPE_CHECKING from glicko2.glicko2 import DEFAULT_PERF from user import User from logger import log +from variants import VARIANTS if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState diff --git a/server/variants.py b/server/variants.py index 4d55d1652..195307c28 100644 --- a/server/variants.py +++ b/server/variants.py @@ -117,7 +117,7 @@ def server_name(self): ServerVariants.BUGHOUSE960, ) -SERVER_VARIANTS = { +VARIANTS = { variant.server_name: variant for variant in ServerVariants if variant not in OLD_VARIANTS } VARIANT_ICONS = { @@ -129,15 +129,15 @@ def server_name(self): # Remove new variants on prod site until they stabilize if PROD: for variant in DEV_VARIANTS: - del SERVER_VARIANTS[variant.server_name] + del VARIANTS[variant.server_name] if __name__ == "__main__": - from const import VARIANT_ICONS as VARIANT_ICONS_ORIG + from const import VARIANT_ICONS_ORIG from compress import V2C - for sn, variant in SERVER_VARIANTS.items(): + for sn, variant in VARIANTS.items(): print(variant.value.code, variant.value.icon, sn) assert variant.value.code == V2C[variant.value.uci_variant] assert variant.value.icon == VARIANT_ICONS_ORIG[variant.server_name]