Restrict participation to clients that want to participate

bram/mute
Bram van den Heuvel 2026-07-01 21:54:24 +02:00
parent ca7bfdc50a
commit 36d5aa30fc
2 changed files with 17 additions and 2 deletions

View File

@ -20,6 +20,7 @@ class RemoteAgent(Agent):
""" """
url : str url : str
games : set[str]
def __init__(self, url : str, timeout : float = 1.0) -> None: def __init__(self, url : str, timeout : float = 1.0) -> None:
""" """
@ -57,6 +58,8 @@ class RemoteAgent(Agent):
profile=content, profile=content,
) )
self.games = set()
games = content.get("games") games = content.get("games")
if isinstance(games, dict): if isinstance(games, dict):
if "tic-tac-toe" in games: if "tic-tac-toe" in games:
@ -64,6 +67,13 @@ class RemoteAgent(Agent):
on_move=lambda x : self.poll("tic-tac-toe", "", x), on_move=lambda x : self.poll("tic-tac-toe", "", x),
profile=games["tic-tac-toe"], profile=games["tic-tac-toe"],
) )
if "royal-game-of-ur" in games:
self.add_royal_game_of_ur(
on_move=lambda x : self.poll("royal-game-of-ur", "", x),
profile=games["royal-game-of-ur"],
)
self.games = set(games.keys())
def get_action(self, game: str, action: str | None) -> Callable[[dict[str, Any]], dict[str, Any]] | None: def get_action(self, game: str, action: str | None) -> Callable[[dict[str, Any]], dict[str, Any]] | None:
""" """

View File

@ -452,7 +452,12 @@ class EloTracker:
self.load_players() self.load_players()
with self.__lock: with self.__lock:
available = len(self.players) players = [
player for player in self.players
if game.game_name() in player.games
]
available = len(players)
if available < player_count: if available < player_count:
self.__debug( self.__debug(
@ -461,7 +466,7 @@ class EloTracker:
) )
else: else:
self.__debug( self.__debug(
"Playing a new scheduled match" f"Playing a new scheduled match of {game.game_name()}"
) )
self.play_random_match(game=game, player_count=player_count) self.play_random_match(game=game, player_count=player_count)
except Exception as exc: except Exception as exc: