Skip to content

Commit

Permalink
fix timer on main
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannSab committed Jun 5, 2024
1 parent 09b0272 commit e54d8ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
15 changes: 3 additions & 12 deletions src/seahorse/game/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
log_level: str = "INFO",
port: int =8080,
hostname: str ="localhost",
time_limit: int = 15*60,
time_limit: int = 1e9,
) -> None:
"""
Initializes a new instance of the GameMaster class.
Expand All @@ -57,7 +57,6 @@ def __init__(
log_level (str): The name of the log file.
"""
self.timetol = 1e-1
# self.recorded_plays = []
self.name = name
self.current_game_state = initial_game_state
self.players = initial_game_state.players
Expand Down Expand Up @@ -96,9 +95,8 @@ async def step(self) -> GameState:
possible_actions = self.current_game_state.get_possible_heavy_actions()

start = time.time()
# next_player.start_timer()
logger.info(f"time : {self.remaining_time[next_player.get_id()]}")

logger.info(f"time : {self.remaining_time[next_player.get_id()]}")
if isinstance(next_player,EventSlave):
action = await next_player.play(self.current_game_state, remaining_time=self.remaining_time[next_player.get_id()])
else:
Expand Down Expand Up @@ -145,12 +143,9 @@ async def play_game(self) -> list[Player]:
try:
logger.info(f"Player now playing : {self.get_game_state().get_next_player().get_name()} - {self.get_game_state().get_next_player().get_id()}")
self.current_game_state = await self.step()
<<<<<<< remove_timer

# self.recorded_plays.append(self.current_game_state.__class__.from_json(json.dumps(self.current_game_state.to_json(),default=lambda x:x.to_json())))
=======
self.recorded_plays.append(self.current_game_state.__class__.from_json(json.dumps(self.current_game_state.to_json(),default=lambda x:x.to_json())))

>>>>>>> main
except (ActionNotPermittedError,SeahorseTimeoutError,StopAndStartError) as e:
if isinstance(e,SeahorseTimeoutError):
logger.error(f"Time credit expired for player {self.current_game_state.get_next_player()}")
Expand Down Expand Up @@ -203,13 +198,9 @@ async def play_game(self) -> list[Player]:
logger.info(f"Winner - {player.get_name()}")

await self.emitter.sio.emit("done",json.dumps(self.get_scores()))
<<<<<<< remove_timer
logger.verdict(f"{','.join(w.get_name() for w in self.get_winner())} has won the game")
=======
logger.verdict(f"{verdict_scores[::-1]}")

print(f"Time taken for the whole game : {time.time()-time_start}")
>>>>>>> main

return self.winner

Expand Down
5 changes: 1 addition & 4 deletions src/seahorse/player/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from seahorse.game.game_state import GameState


class Player(Serializable):#,TimeMixin):
class Player(Serializable):
"""
A base class representing a player in the game.
Expand All @@ -28,18 +28,15 @@ def __init__(self, name: str = "bob",*,id:int | None = None,**_) -> None:
Args:
name (str, optional): The name of the player. Defaults to "bob".
time_limit (float, optional): The time limit for the player's moves. Defaults to 1e6.
hard_id (int, optional, keyword-only): Set the player's id in case of distant loading
"""
self.name = name
if id is None:
self.id = builtins.id(self)
else:
self.id = id
# self.init_timer(time_limit)


# @timed_function
def play(self, current_state: GameState, remaining_time: int) -> Action:
"""
Implements the player's logic and calls compute_action with minimal information.
Expand Down

0 comments on commit e54d8ad

Please sign in to comment.