feat(decks): rank owned-card upgrades by deck fit, not just legality (#294) - #348
Merged
Conversation
…294) The heuristic suggester returned cards that were owned, in colour identity and Commander-legal, ranked by curve then price. That guarantees a *legal* pick, not a *good* one: a generic in-colour rock could outrank a card that actually does what the deck is trying to do. Candidates are now scored against the deck's plan first, with curve and price kept as tie-breakers — so a deck with no detectable theme ranks exactly as it did before, and only decks that *have* a plan see any change. Two signals, both offline and deterministic: * **Themes** — recurring keywords plus rules-text patterns (+1/+1 counters, tokens, sacrifice, lifegain, spellslinger, mill, graveyard recursion). * **Tribes** — creature types the deck cares about, derived **from the deck** rather than a hardcoded list of creature types: types the commander's text names, or that enough of the deck's creatures already share. Magic has hundreds of types and gains more every set, so a literal list would be wrong within a year; this stays correct for types invented after it was written. A tribal hit is weighted above a text match because it's the deck's whole plan rather than one mode of a card. Whatever matched is surfaced on the pick ("matches your tokens, elf"). An unexplained recommendation is one the reader has no way to disagree with, which is the actual complaint behind this issue. Theme detection moves out of `llm.py` into a new `src/deck_synergy.py`. It had to be shared: the offline suggester can't import the LLM module to reuse it, and a second copy would drift — this repo has already paid for exactly that, with two card-name resolvers that disagreed until DFCs matched from a decklist but not from a CSV (#338). #295 reuses the same scoring as its pre-filter. Two things found while building it: * **The plural of Elf is Elves.** A naive `s?` match silently found nothing for Elf, Wolf, Dwarf and Ally — precisely the tribes people build around. Only the irregulars real creature types use are handled; an unknown one degrades to a missed signal rather than a wrong one. * Subtypes are read from **creature** type lines only, so an Aura-heavy deck isn't "Aura tribal". Deliberately not included: a `game_changer` quality boost, which #294 lists as optional. Those cards raise a deck's bracket (`src/brackets.py`), so silently floating them to the top of an "upgrades" list would change something about the deck the suggester never mentions. Worth doing as an explicit, labelled signal rather than a hidden ranking nudge. 16 new tests; suite 1274 passing at 100% coverage. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxrePqFWyzQTcWaroSk4sH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #294. One of the two remaining items in the Decks & EDH tooling milestone; #295 is the sibling and reuses this scoring.
The problem
The heuristic suggester returned cards that were owned, in colour identity and Commander-legal, ranked by curve then price. Those rules make a pick allowed, not good — a generic in-colour mana rock could outrank a card that actually does what the deck is trying to do.
What changes
Candidates are now scored against the deck's plan first, with curve and price kept as tie-breakers. A deck with no detectable theme ranks exactly as it did before — only decks that have a plan see any difference.
Two signals, both offline and deterministic (no LLM, no network, no new data source):
Whatever matched is shown on the pick — "matches your tokens, elf". An unexplained recommendation is one the reader has no way to disagree with, which is really the complaint behind this issue.
Shared plumbing, not a second copy
Theme detection moved out of
llm.pyinto a newsrc/deck_synergy.py. It had to be shared: the deliberately-offline suggester can't import the LLM module to reuse it, and a second copy would drift. This repo has already paid for that once — two card-name resolvers disagreed until DFCs matched from a decklist but not from a CSV (#338). #295 asks for the same plumbing as its pre-filter, so it's there waiting.Two things found while building it
elfs?, which silently found nothing for Elf, Wolf, Dwarf and Ally — precisely the tribes people build decks around. Now only the irregulars real creature types actually use are handled, and an unknown one degrades to a missed signal rather than a wrong one.Deliberately not included
#294 lists a
game_changer"staple-ness" boost as optional. I left it out on purpose: those cards raise a deck's bracket (src/brackets.py), so silently floating them to the top of an upgrades list would change something about the deck that the suggester never mentions. That's worth doing as an explicit, labelled signal — "strong, but raises your bracket" — rather than a hidden ranking nudge, and it's a decision worth making on its own rather than smuggling in here.Verification
ruffandmkdocs --strictclean. No migration.🤖 Generated with Claude Code
https://claude.ai/code/session_01LxrePqFWyzQTcWaroSk4sH