From 87f722f43e4e69949dd68c9aa5cacb303ea7c6b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 09:40:15 +0000 Subject: [PATCH 1/2] Initial plan From c80fe8892906e82d736f9809f2ed39cdf9593d69 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 09:44:07 +0000 Subject: [PATCH 2/2] Fix percentage rounding: use round() instead of int() to match overlay's Math.round() Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com> --- bot/bot.py | 8 ++++---- tests/test_commands.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 290c9e5..6c69527 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -197,12 +197,12 @@ async def guess(self, ctx: commands.Context, word: str = "") -> None: await ctx.send(f"🎉 {ctx.author.name} found the word '{word}'!") elif result.already_cited: if result.entry.score is not None: - pct = int(result.entry.score * 100) + pct = round(result.entry.score * 100) await ctx.send(f"'{word}' has already been suggested ({pct}% similarity).") else: await ctx.send(f"'{word}' has already been suggested.") elif result.entry.score is not None: - pct = int(result.entry.score * 100) + pct = round(result.entry.score * 100) await ctx.send(f"'{word}': {pct}% similarity") else: await ctx.send(f"'{word}' is not in the vocabulary.") @@ -273,7 +273,7 @@ async def hint(self, ctx: commands.Context) -> None: return parts = [ - f"{i + 1}. {e.raw_word} ({int((e.score or 0.0) * 100)}%)" + f"{i + 1}. {e.raw_word} ({round((e.score or 0.0) * 100)}%)" for i, e in enumerate(top) ] await ctx.send("Top guesses: " + " | ".join(parts)) @@ -300,7 +300,7 @@ async def status(self, ctx: commands.Context) -> None: top = self._game_state.top_guesses(1) if top: best = top[0] - pct = int((best.score or 0.0) * 100) + pct = round((best.score or 0.0) * 100) await ctx.send( f"Game in progress. {attempts} attempt(s). " f"Best guess: '{best.raw_word}' ({pct}%)." diff --git a/tests/test_commands.py b/tests/test_commands.py index 1e08d50..a78b5cb 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -364,6 +364,27 @@ async def test_guess_near_match_shows_similarity(self): message = ctx.send.call_args[0][0] assert "%" in message + async def test_guess_percentage_uses_rounding_not_truncation(self): + """Chat must show the same rounded percentage as the overlay (Math.round).""" + + class _RoundingScorer: + """Returns 0.475 so that truncation gives 47% but rounding gives 48%.""" + + def score_guess(self, guess: str, target: str) -> float | None: + from game.word_utils import clean_word + if clean_word(guess) == clean_word(target): + return 1.0 + return 0.475 + + bot = _make_bot(cooldown=0) + bot._game_state = GameState(scorer=_RoundingScorer()) + bot._game_state.start_new_game("chat", Difficulty.EASY) + ctx = _make_ctx() + ctx.author.name = "alice" + await _guess_fn(bot, ctx, "chien") + message = ctx.send.call_args[0][0] + assert "48%" in message, f"Expected 48% (rounded), got: {message}" + async def test_guess_unknown_word_reports_vocabulary_miss(self): bot = _make_bot(cooldown=0) bot._game_state.start_new_game("chat", Difficulty.EASY)