Skip to content

Commit

Permalink
Use VARIANTS from variants.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jan 12, 2025
1 parent 7956ab8 commit 3557e3d
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 26 deletions.
3 changes: 2 additions & 1 deletion server/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions server/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions server/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "")
]

Expand Down
3 changes: 2 additions & 1 deletion server/game_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion server/generate_highscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion server/generate_shield.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions server/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
4 changes: 2 additions & 2 deletions server/pychess_global_app_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from ai import BOT_task
from const import (
NONE_USER,
VARIANTS,
LANGUAGES,
MAX_CHAT_LINES,
MONTHLY,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/tournaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
T_FINISHED,
T_ARCHIVED,
SHIELD,
VARIANTS,
MAX_CHAT_LINES,
CATEGORIES,
TRANSLATED_FREQUENCY_NAMES,
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion server/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
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
from notify import notify
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
Expand Down
3 changes: 2 additions & 1 deletion server/users.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions server/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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]

0 comments on commit 3557e3d

Please sign in to comment.