Simple PyClient bug fixes

main
Bram van den Heuvel 2026-06-05 17:03:48 +02:00
parent e4c40d2d97
commit 99e5cafa89
2 changed files with 9 additions and 4 deletions

View File

@ -42,6 +42,7 @@ class PyClient:
""" """
Play a given game. Ask the registered agents to participate. Play a given game. Ask the registered agents to participate.
""" """
agents = [ agent for agent in self.agents if name in agent.games ]
states = [] states = []
current_state = game.empty() current_state = game.empty()
@ -49,13 +50,13 @@ class PyClient:
while current_state.winner() is None: while current_state.winner() is None:
player : int = current_state.player_to_move() player : int = current_state.player_to_move()
if len(self.agents) < player: if len(agents) < player:
raise KeyError( raise KeyError(
f"The client does not have access to {player} players" f"{player} players for game {name}, found only {len(agents)}"
) )
# Ask for move # Ask for move
agent = self.agents[player] agent = agents[player-1]
payload = agent.poll( payload = agent.poll(
game=current_state.action_name(), game=current_state.action_name(),
payload=current_state.to_dict(), payload=current_state.to_dict(),

View File

@ -276,7 +276,7 @@ class TicTacToe:
""" """
Returns whether the board indicates that there's a winner. Returns whether the board indicates that there's a winner.
:return: The winning player, or None if there's no winner yet. :return: The winning player, zero in case of a tie, or None if there's no winner yet.
:rtype: int | None :rtype: int | None
""" """
win_lines = [ win_lines = [
@ -297,5 +297,9 @@ class TicTacToe:
if all(d[str(w)] == symbol for w in win_line): if all(d[str(w)] == symbol for w in win_line):
return player return player
else: else:
# Check for draw
if all(item != Field.empty for item in d.values()):
return 0
return None return None