Skip to content

Commit

Permalink
game: Add no of players and preset no of rounds to /status
Browse files Browse the repository at this point in the history
Addresses #26
  • Loading branch information
mhthies committed Jun 28, 2020
1 parent 4a2b9c1 commit 0ce3bfd
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 159 deletions.
27 changes: 21 additions & 6 deletions qaqa_bot/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def start_game(self, session: Session, chat_id: int) -> List[TranslatedMessage]:

# Set number of rounds if unset
if game.rounds is None:
game.rounds = max(6, math.floor(len(game.participants)/2)*2)
game.rounds = calculate_preset_rounds(len(game.participants))
logger.debug("Setting game %s's rounds automatically to %s", game.id, game.rounds)

logger.info("Starting game %s", game.id)
Expand Down Expand Up @@ -709,7 +709,8 @@ def get_group_status(self, session: Session, chat_id: int) -> List[TranslatedMes
if current_game.participants
else GetText("– none –"))
configuration = GetText("Rounds: {num_rounds}\nSynchronous: {synchronous}")\
.format(num_rounds=(GetText('– number of players –')
.format(num_rounds=(GetText('{number} (based on no. of players)')
.format(number=calculate_preset_rounds(len(players)))
if current_game.rounds is None
else current_game.rounds),
synchronous=GetText('yes') if current_game.is_synchronous else GetText('no'))
Expand All @@ -736,16 +737,20 @@ def get_group_status(self, session: Session, chat_id: int) -> List[TranslatedMes
.format(trans_num_sheets=NGetText('One sheet is', '{n} sheets are', len(sheet_infos))
.format(n=len(sheet_infos)),
sheets_stats=sheets_stats, pending_users=pending_users,
trans_reg_players=NGetText('Registered player', 'Registered players',
len(current_game.participants)),
trans_reg_players=NGetText('Registered player', 'Registered players ({number})',
len(players))
.format(number=len(players)),
players=players_text, configuration=configuration)
else:
status = GetText("The game has been created and waits to be started. 🕰\n"
"Use /{command} to start the game.\n\n"
"Registered players:\n"
"{trans_reg_players}:\n"
"{players}\n\n"
"Game configuration:\n{configuration}")\
.format(command=COMMAND_START_GAME, players=players_text, configuration=configuration)
.format(command=COMMAND_START_GAME, players=players_text, configuration=configuration,
trans_reg_players=NGetText('Registered player', 'Registered players ({number})',
len(players))
.format(number=len(players)))
return self._get_translations([Message(chat_id, status)], session)

# ###########################################################################
Expand Down Expand Up @@ -1004,3 +1009,13 @@ def truncate_string(s, length=200, end="…"):
return s
result = s[: length - len(end)].rsplit(" ", 1)[0]
return result + end


def calculate_preset_rounds(player_number):
"""
Calculation function for the number of rounds preset, based on the number of players
:param player_number: Number of players in the game
:return: Preset number of rounds of the game
"""
return max(6, math.floor(player_number / 2) * 2)
Loading

0 comments on commit 0ce3bfd

Please sign in to comment.