From 08d7a50965b41bf5f74c57c1698272bb4456e5e4 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 8 Nov 2021 15:13:51 +0100 Subject: [PATCH] Initialize Game with the first round --- orochi/bot.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/orochi/bot.py b/orochi/bot.py index 01b70d3..ebe6cb0 100644 --- a/orochi/bot.py +++ b/orochi/bot.py @@ -61,9 +61,9 @@ class Player: @dataclass class RoundVote: player1: Player - player2: Player | None - vote: Vote - timestamp: datetime + player2: Player | None = None + vote: Vote | None = None + timestamp: datetime | None = None @property def players(self): @@ -116,6 +116,23 @@ class Game: self.players[name] = player return player + def default_first_round(self) -> Round: + return Round( + round=1, + room_a=RoundRoom(room=Room.A, + vote1=RoundVote(player1=GAME.players['Tora']), + vote2=RoundVote(player1=GAME.players['Kamui'], + player2=GAME.players['Philia'])), + room_b=RoundRoom(room=Room.A, + vote1=RoundVote(player1=GAME.players['Dan']), + vote2=RoundVote(player1=GAME.players['Ennea'], + player2=GAME.players['Delphine'])), + room_c=RoundRoom(room=Room.A, + vote1=RoundVote(player1=GAME.players['Hanabi']), + vote2=RoundVote(player1=GAME.players['Nona'], + player2=GAME.players['Oji'])), + ) + def save(self, filename: str) -> None: """ Uses pickle to save the current state of the game. @@ -227,6 +244,11 @@ async def on_ready(): GAME.register_player(player.name, config.vote_channels[player.name.lower()]) GAME.save('game.save') + # Setup first round if not exists + if not GAME.rounds: + GAME.rounds.append(GAME.default_first_round()) + GAME.save('game.save') + if not config.telepathy_channel: channel: TextChannel = await secret_category.create_text_channel("bigbrain") config.telepathy_channel = channel.id