bug(copi): highest_scoring_cards_in_game applies special_lead_cards across all rounds before grouping by round
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read lib/copi/cornucopia.ex, especially highest_scoring_cards_in_game/1 and special_lead_cards/1; the issue includes a two-round regression example for test/copi/cornucopia_logic_test.exs. Check how round grouping affects lead suit, trump, and joker filtering, then run the focused test. Done when each round returns its own highest scoring card and the regression tests pass.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
In copi.owasp.org/lib/copi/cornucopia.ex (lines 404–411), highest_scoring_cards_in_game/1 calls special_lead_cards/1 on the flat list of all played cards across the entire game before grouping cards by played_in_round:
def highest_scoring_cards_in_game(game) do
Enum.reduce(game.players, [], fn player, cards -> (player.dealt_cards |> played_cards) ++ cards end) # Combine all played cards from all players
|> lead_suit_cards # Filter to just the lead suit cards
|> scoring_cards(Enum.count(game.players)) # Filter to just the cards that scored
|> special_lead_cards # Filter to just the special lead cards (jokers, trump cards, or lead suit cards)
|> Enum.group_by(fn card -> card.played_in_round end) # Convert to map where {round, [scoring_cards]}
|> Enum.flat_map(fn {_, cards} -> highest_card(cards) end) # Back to a list of just the highest scoring card in each round
end
Because lead_suit_cards/1 flattens all rounds back into a single list via Enum.flat_map/2, special_lead_cards/1 (lines 431–457) evaluates jokers, trump suits, and lead_suit = List.first(ordered_played_cards).card.category across all rounds combined instead of per round:
- Different lead suits across rounds: If Round 1 is led with
"Authentication"and Round 2 is led with"Cryptography"(with no jokers or trumps in either round),List.first(ordered_played_cards)inspecial_lead_cards/1hascategory: "Authentication", soEnum.filter(ordered_played_cards, &(&1.card.category == lead_suit))discards all"Cryptography"cards from Round 2. - Trump card in one round wipes out non-trump rounds: If any card from a trump suit (
Cornucopia,Dataset Risk,Elevation of Privilege) scores in Round 1,trumps != []is true for the whole-game list andspecial_lead_cards/1discards all non-trump scoring cards from every other round. - Joker in one round wipes out non-joker rounds: If
JokerAorJokerBscores in Round 1,jokers != []is true for the whole-game list andspecial_lead_cards/1discards all non-joker scoring cards from every other round.
As a result, highest_scoring_card_in_round(game, round) returns nil for affected rounds and highest_scoring_cards_for_player(player, game) omits the round winner's Highest Card Bonus point on the scoreboard (CopiWeb.GameComponents.game_scores/1).
Proof / Reproduction
In copi.owasp.org/test/copi/cornucopia_logic_test.exs, existing tests only play cards in round 1. Playing two rounds with different lead suits reproduces the bug:
test "highest_scoring_card_in_round evaluates each round independently", %{game: game, p1: p1, p2: p2} do
{:ok, r1_c1} = create_card("Authentication", "K")
{:ok, r1_c2} = create_card("Authentication", "5")
{:ok, r2_c1} = create_card("Cryptography", "Q")
{:ok, r2_c2} = create_card("Cryptography", "3")
# Round 1: Authentication lead suit
d1 = play_card(p1, r1_c1, 1)
d2 = play_card(p2, r1_c2, 1)
Repo.insert!(%Copi.Cornucopia.Vote{dealt_card_id: d1.id, player_id: p2.id})
Repo.insert!(%Copi.Cornucopia.Vote{dealt_card_id: d2.id, player_id: p1.id})
# Round 2: Cryptography lead suit
d3 = play_card(p2, r2_c1, 2)
d4 = play_card(p1, r2_c2, 2)
Repo.insert!(%Copi.Cornucopia.Vote{dealt_card_id: d3.id, player_id: p1.id})
Repo.insert!(%Copi.Cornucopia.Vote{dealt_card_id: d4.id, player_id: p2.id})
game = Cornucopia.get_game!(game.id) |> Repo.preload(players: [dealt_cards: [:card, :votes]])
assert Cornucopia.highest_scoring_card_in_round(game, 1).id == d1.id
# Fails on master: returns `nil` because Round 2's "Cryptography" cards are filtered out by Round 1's "Authentication" lead suit
assert Cornucopia.highest_scoring_card_in_round(game, 2).id == d3.id
end
Expected Behavior
special_lead_cards/1 should be applied per round after grouping by played_in_round:
def highest_scoring_cards_in_game(game) do
Enum.reduce(game.players, [], fn player, cards -> (player.dealt_cards |> played_cards) ++ cards end)
|> lead_suit_cards
|> scoring_cards(Enum.count(game.players))
|> Enum.group_by(fn card -> card.played_in_round end)
|> Enum.flat_map(fn {_, cards} -> cards |> special_lead_cards() |> highest_card() end)
end
Hi @sydseter, could you please assign this issue to me? I'd be happy to open a PR with the fix and multi-round regression tests.
- 主要言語
- Python
- スター
- 158
- フォーク
- 110
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 115
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
OWASP/cornucopia のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
OWASP/cornucopia#3778 ·
メンテナーはふだん 1 日以内に返信
-
Upgrade @vitest/mocker from 4.1.10 to 5.0再び着手できるかも @Mahaboobunnisa123 が 43 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンhelp wanted javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
OWASP/cornucopia#3538 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
OWASP/cornucopia#3784 ·
メンテナーはふだん 1 日以内に返信
-
Add the Hindi translation for the Companion Edition対応中かも @V-2007-P が 2 日前に担当しました。 オープン
OWASP/cornucopia#3770 · コメント 6 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug(copi): next_round and toggle_continue_vote can be triggered on unstarted or finished games対応中かも @Abhrant-Singh が 3 日前に担当しました。 オープン
OWASP/cornucopia#3762 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
OWASP/cornucopia の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
AI bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
AUTO-MAS-Project/AUTO-MAS#1960 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
btclib-org/btclib-wallet#872 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Scheduled returns scan all accepted minion keys causing extreme load対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
saltstack/salt#70789 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 87/100
btclib-org/btclib#3093 ·
メンテナーはふだん 1 日以内に返信