Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server variants #1748

Merged
merged 13 commits into from
Jan 13, 2025
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -40,7 +40,7 @@ def add_to_auto_pairings(app_state, user, data):
if (
(byoyomi_period > 0 and variant not in BYOS)
or (byoyomi_period == 0 and variant in BYOS)
or variant.startswith("bughouse")
or variant.startswith("bug")
):
continue

Expand Down
6 changes: 4 additions & 2 deletions server/bug/game_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
CASUAL,
RATED,
IMPORTED,
variant_display_name,
MAX_CHAT_LINES,
POCKET_PATTERN,
)
from fairy import FairyBoard, BLACK, WHITE
from spectators import spectators
from variants import get_server_variant

MAX_HIGH_SCORE = 10
MAX_PLY = 2 * 600
Expand Down Expand Up @@ -79,10 +79,12 @@ def __init__(
self.create = create
self.imported_by = ""

self.server_variant = get_server_variant(variant, chess960)

self.berserk_time = self.base * 1000 * 30

self.browser_title = "%s • %s+%s vs %s+%s" % (
variant_display_name(self.variant + ("960" if self.chess960 else "")).title(),
self.server_variant.display_name.title(),
self.wplayerA.username,
self.bplayerB.username,
self.wplayerB.username,
Expand Down
13 changes: 8 additions & 5 deletions server/bug/import_bugh_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
IMPORTED,
)
from datetime import datetime, timezone
from compress import R2C, V2C, encode_move_standard
from compress import R2C, encode_move_standard
from newid import new_id
from aiohttp import web
from bugchess.pgn import read_game, Game
from logger import log
from variants import get_server_variant


def get_main_variation(game: Game, base_tc_ms: int) -> [list, list]:
Expand Down Expand Up @@ -93,8 +94,10 @@ async def import_game_bpgn(request):
wplayer_a, bplayer_a, wplayer_b, bplayer_b = init_players(app_state, wp_a, bp_a, wp_b, bp_b)

variant = "bughouse"
chess960 = False # variant.endswith("960")
# variant = variant.removesuffix("960")
chess960 = variant.endswith("960")
variant = variant.removesuffix("960")

server_variant = get_server_variant(variant, chess960)

# todo: replace with valid initial fen for now - maybe fix the problematic fen that ends with / instead of [] eventually - that is how chess.com fen looks like and doesn't parse well here
initial_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[] w KQkq - 0 1 | rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[] w KQkq - 0 1" # first_game.headers.get("FEN", "")
Expand Down Expand Up @@ -159,7 +162,7 @@ async def import_game_bpgn(request):
document = {
"_id": game_id,
"us": [wplayer_a.username, bplayer_a.username, wplayer_b.username, bplayer_b.username],
"v": V2C[variant],
"v": server_variant.code,
"b": base,
"i": inc,
"bp": 0,
Expand All @@ -175,7 +178,7 @@ async def import_game_bpgn(request):
"r": R2C[result],
"x": 0,
"y": IMPORTED,
"z": int(False), # int(new_game.chess960),
"z": int(chess960),
"by": first_game.headers.get("username"),
}

Expand Down
5 changes: 3 additions & 2 deletions server/bug/utils_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pychess_global_app_state import PychessGlobalAppState
from user import User
from compress import R2C, C2R, V2C, C2V, decode_move_standard
from compress import R2C, C2R, decode_move_standard
from bug.game_bug import GameBug
from const import (
STARTED,
Expand All @@ -18,6 +18,7 @@
from utils import remove_seek, round_broadcast, sanitize_fen
from websocket_utils import ws_send_json
from logger import log
from variants import C2V


def init_players(app_state: PychessGlobalAppState, wp_a, bp_a, wp_b, bp_b):
Expand Down Expand Up @@ -347,7 +348,7 @@ async def insert_game_to_db_bughouse(game: GameBug, app_state: PychessGlobalAppS
"p1": {"e": game.brating_a},
"p2": {"e": game.wrating_b},
"p3": {"e": game.brating_b},
"v": V2C[game.variant],
"v": game.server_variant.code,
"b": game.base,
"i": game.inc,
# "bp": game.byoyomi_period,
Expand Down
2 changes: 1 addition & 1 deletion server/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def restart(self, secs=None):
self.secs = secs
else:
# give some time to make first move
if self.ply < 2 and self.game.variant != "bughouse":
if self.ply < 2 and not self.game.server_variant.bug:
if self.game.tournamentId is None:
# Non tournament games are not timed for the first moves of either
# player. We stop the clock to prevent unnecessary clock
Expand Down
78 changes: 0 additions & 78 deletions server/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,6 @@
https://lichess.org/blog/Wqa7GiAAAOIpBLoY/developer-update-275-improved-game-compression
"""

# Create mappings to compress variant, result and uci/usi move lists a little
V2C = {
"ataxx": "Z",
"chess": "n",
"capablanca": "c",
"capahouse": "i",
"crazyhouse": "h",
"bughouse": "F",
"atomic": "A",
"makruk": "m",
"placement": "p",
"dragon": "R",
"seirawan": "s",
"shogi": "g",
"minishogi": "a",
"shouse": "z",
"sittuyin": "y",
"xiangqi": "x",
"grand": "q",
"grandhouse": "r",
"gothic": "o",
"gothhouse": "t",
"embassy": "E",
"cambodian": "b",
"shako": "d",
"minixiangqi": "e",
"kyotoshogi": "k",
"shogun": "u",
"janggi": "j",
"makpong": "l",
"orda": "f",
"khans": "L",
"synochess": "v",
"hoppelpoppel": "w",
"manchu": "M",
"dobutsu": "D",
"gorogoroplus": "G",
"cannonshogi": "W",
"shinobi": "J",
"shinobiplus": "K",
"empire": "P",
"ordamirror": "O",
"torishogi": "T",
"asean": "S",
"chak": "C",
"chennis": "H",
"mansindam": "I",
"duck": "U",
"spartan": "N",
"kingofthehill": "B",
"3check": "X",
"alice": "Y",
"fogofwar": "Q",
"antichess": "’",
"racingkings": "°",
"horde": "š",
"shatranj": "†",
}
C2V = {v: k for k, v in V2C.items()}

R2C = {"1-0": "a", "0-1": "b", "1/2-1/2": "c", "*": "d"}
C2R = {v: k for k, v in R2C.items()}

Expand Down Expand Up @@ -132,15 +72,6 @@ def encode_move_standard(move):
return chr(M2C[move[0:2]]) + chr(M2C[move[2:4]]) + (move[4] if len(move) == 5 else "")


def get_encode_method(variant):
if variant in ("kyotoshogi", "chennis"):
return encode_move_flipping
elif variant == "duck":
return encode_move_duck
else:
return encode_move_standard


def decode_move_flipping(move):
return (
C2M[ord(move[0])] + "@" + C2M[ord(move[1])]
Expand All @@ -162,12 +93,3 @@ def decode_move_duck(move):

def decode_move_standard(move):
return C2M[ord(move[0])] + C2M[ord(move[1])] + (move[2] if len(move) == 3 else "")


def get_decode_method(variant):
if variant in ("kyotoshogi", "chennis"):
return decode_move_flipping
elif variant == "duck":
return decode_move_duck
else:
return decode_move_standard
Loading
Loading