Skip to content

Commit

Permalink
Enums (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami authored Jan 12, 2025
1 parent 6b97b81 commit 797b472
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
88 changes: 61 additions & 27 deletions server/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from datetime import timedelta
from enum import global_enum, IntEnum, StrEnum
import re

from settings import static_url, PROD
Expand Down Expand Up @@ -39,14 +40,36 @@
# Show the number of spectators only after this limit
MAX_NAMED_SPECTATORS = 20


# tournament status
T_CREATED, T_STARTED, T_ABORTED, T_FINISHED, T_ARCHIVED = range(5)
@global_enum
class TStatus(IntEnum):
T_CREATED = 0
T_STARTED = 1
T_ABORTED = 2
T_FINISHED = 3
T_ARCHIVED = 4


# tournament frequency
HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY, MARATHON, SHIELD = "h", "d", "w", "m", "y", "a", "s"
@global_enum
class TFreq(StrEnum):
HOURLY = "h"
DAILY = "d"
WEEKLY = "w"
MONTHLY = "m"
YEARLY = "y"
MARATHON = "a"
SHIELD = "s"


# tournament pairing
ARENA, RR, SWISS = range(3)
@global_enum
class TPairing(IntEnum):
ARENA = 0
RR = 1
SWISS = 2


# translations
LANGUAGES = [
Expand All @@ -70,37 +93,48 @@
"zh_TW",
]


# fishnet work types
MOVE, ANALYSIS = 0, 1
@global_enum
class WorkType(IntEnum):
MOVE = 0
ANALYSIS = 1


# game types
CASUAL, RATED, IMPORTED = 0, 1, 2
@global_enum
class GameType(IntEnum):
CASUAL = 0
RATED = 1
IMPORTED = 2


# game status
(
CREATED,
STARTED,
ABORTED,
MATE,
RESIGN,
STALEMATE,
TIMEOUT,
DRAW,
FLAG,
ABANDON,
CHEAT,
BYEGAME,
INVALIDMOVE,
UNKNOWNFINISH,
VARIANTEND,
CLAIM,
) = range(-2, 14)
@global_enum
class GameStatus(IntEnum):
CREATED = -2
STARTED = -1
ABORTED = 0
MATE = 1
RESIGN = 2
STALEMATE = 3
TIMEOUT = 4
DRAW = 5
FLAG = 6
ABANDON = 7
CHEAT = 8
BYEGAME = 9
INVALIDMOVE = 10
UNKNOWNFINISH = 11
VARIANTEND = 12
CLAIM = 13


LOSERS = {
"abandon": ABANDON,
"abort": ABORTED,
"resign": RESIGN,
"flag": FLAG,
"abandon": GameStatus.ABANDON,
"abort": GameStatus.ABORTED,
"resign": GameStatus.RESIGN,
"flag": GameStatus.FLAG,
}

GRANDS = ("xiangqi", "manchu", "grand", "grandhouse", "shako", "janggi")
Expand Down
11 changes: 7 additions & 4 deletions server/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
ARENA,
CATEGORIES,
GRANDS,
variant_display_name,
SCHEDULE_MAX_DAYS,
TYPE_CHECKING,
DAILY,
WEEKLY,
MONTHLY,
YEARLY,
SHIELD,
variant_display_name,
SCHEDULE_MAX_DAYS,
TYPE_CHECKING,
)

if TYPE_CHECKING:
Expand All @@ -23,8 +24,8 @@
from tournaments import new_tournament
from logger import log

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

MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)
Plan = namedtuple("Plan", "freq, date, hour, variant, is960, base, inc, byo, duration")

SHIELDS = ["crazyhouse960", "atomic960", "kingofthehill960", "3check960", "makruk"]
Expand Down Expand Up @@ -269,6 +270,8 @@ def new_scheduled_tournaments(already_scheduled, now=None):

if plan.freq == SHIELD:
name = "%s Shield Arena" % variant_name
elif plan.freq == YEARLY:
name = "Yearly %s Arena" % variant_name
elif plan.freq == MONTHLY:
if plan.variant in CATEGORIES["makruk"]:
name = "SEAturday %s Arena" % variant_name
Expand Down
2 changes: 0 additions & 2 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from const import SHIELD, SCHEDULE_MAX_DAYS
from scheduler import new_scheduled_tournaments, MONTHLY_VARIANTS, SHIELDS, Scheduler

MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)

# Crazhouse960 Shield scheduled at second MONDAY of month
SHIELD_ZH_2021_09 = (
SHIELD,
Expand Down

0 comments on commit 797b472

Please sign in to comment.