diff --git a/pyclient/__init__.py b/pyclient/__init__.py index d246d77..0e7e37f 100644 --- a/pyclient/__init__.py +++ b/pyclient/__init__.py @@ -42,6 +42,7 @@ class PyClient: """ Play a given game. Ask the registered agents to participate. """ + agents = [ agent for agent in self.agents if name in agent.games ] states = [] current_state = game.empty() @@ -49,13 +50,13 @@ class PyClient: while current_state.winner() is None: player : int = current_state.player_to_move() - if len(self.agents) < player: + if len(agents) < player: 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 - agent = self.agents[player] + agent = agents[player-1] payload = agent.poll( game=current_state.action_name(), payload=current_state.to_dict(), diff --git a/pyclient/games/tic_tac_toe.py b/pyclient/games/tic_tac_toe.py index d1cb471..76b2c9f 100644 --- a/pyclient/games/tic_tac_toe.py +++ b/pyclient/games/tic_tac_toe.py @@ -276,7 +276,7 @@ class TicTacToe: """ 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 """ win_lines = [ @@ -297,5 +297,9 @@ class TicTacToe: if all(d[str(w)] == symbol for w in win_line): return player else: + # Check for draw + if all(item != Field.empty for item in d.values()): + return 0 + return None