cli: find jokers in booster packs
Rust CI balatro-seed-search passed CI.
MadGobblins/balatro-seed-search/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-10-08 15:55:59 +02:00
parent 566b5e1293
commit 29b7a328a9
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 139 additions and 16 deletions

View File

@ -38,6 +38,7 @@ Expected standard output:
`--before-ante` is inclusive. Repeat `--joker` to require multiple jokers, or
add `--mode any` to accept any requested joker. Run
`balatro-seed-search find-jokers --help` for every available search control.
Use `--pack-joker NAME` to search Buffoon-pack contents instead of shop slots.
Shop results use the post-1.0.1c joker pools and report positions in an ante's
shop queue. `--max-rerolls` assumes one two-card shop visit; purchases, unlocks,

View File

@ -606,3 +606,12 @@ regression evidence rather than copying the table blindly.
- Commit: `release: prepare v0.1.1`.
- Publish the matching tag and configured Linux/Windows artifacts with the
repository's `rust_realease` workflow after preparation passes.
- [x] **49. Search Buffoon packs for jokers.**
- Add repeatable `--pack-joker NAME[:MIN-MAX]` targets to `find-jokers` and
`create-filter`, with the existing all/any and explanation behavior.
- Keep shop-only modifiers scoped to `--joker`, and document the modeled
per-ante pack limits and source distinction.
- Checks: CLI/filter-shape and end-to-end tests; full tests; strict Clippy;
release build; `git diff --check`.
- Commit: `cli: find jokers in booster packs`.

View File

@ -5,10 +5,11 @@ iteration, shops, packs, tags, vouchers, bosses, Soul, Wraith, editions,
stickers, and standard cards. Tests cover deterministic behavior, pool
validity, serial/parallel result ordering, filters, and the CLI.
The friendly `find-jokers` command searches modeled shop draws, while
`--legendary` searches Soul resolutions. Jokers from a Buffoon pack or Wraith
still require the relevant [advanced JSON clause](filter-format.md). The
default any-slot shop search covers the first 16 modeled queue draws.
The friendly `find-jokers` command searches modeled shop draws,
`--pack-joker` searches Buffoon-pack contents, and `--legendary` searches Soul
resolutions. Jokers produced by Wraith still require the relevant
[advanced JSON clause](filter-format.md). The default any-slot shop search
covers the first 16 modeled queue draws.
## Shop reference contract

View File

@ -7,6 +7,7 @@ by `find-jokers`:
```bash
balatro-seed-search create-filter \
--legendary Canio --legendary Perkeo --before-ante 2 \
--pack-joker Blueprint \
--joker 'Blueprint:2-' --joker 'Brainstorm:2-' \
--joker 'Credit Card' \
--output my-search.json
@ -20,8 +21,8 @@ balatro-seed-search create-filter \
balatro-seed-search search --filter - --max-seeds 5000000
```
Repeat `--joker` and `--legendary` and select `--mode all|any` to refine the
generated filter. Per-target ante ranges, edition, sticker, `--max-rerolls`,
Repeat `--joker`, `--pack-joker`, and `--legendary` and select `--mode all|any`
to refine the generated filter. Per-target ante ranges, edition, sticker, `--max-rerolls`,
and exact `--slot` options work exactly as they do in `find-jokers`. An
existing `--output` file is protected unless `--force` is supplied.

View File

@ -30,6 +30,22 @@ balatro-seed-search find-jokers \
--mode any --before-ante 3 --output seeds
```
Search Buffoon packs with `--pack-joker`. The command checks the first four
modeled packs in ante 1 and the first six in each later ante, ignoring packs
that cannot contain jokers:
```bash
balatro-seed-search find-jokers \
--pack-joker Blueprint --before-ante 3 \
--max-matches 5
```
`--pack-joker` is repeatable and can be mixed with shop `--joker` and Soul
`--legendary` targets. The selected `--mode all|any`, global ante limit, and
per-target `NAME:MIN-MAX` ranges apply across all three sources. Edition,
sticker, reroll, and exact-draw restrictions apply only to shop `--joker`
targets.
Search for any of the five legendary jokers through The Soul with
`--legendary`. This avoids writing an advanced JSON filter:
@ -39,11 +55,9 @@ balatro-seed-search find-jokers \
--random-start --max-matches 5
```
The option is repeatable and may be mixed with `--joker`; the existing
The option is repeatable and may be mixed with either joker option; the existing
`--mode all|any` applies across every requested target. Legendary searches
check all four modeled ante-1 packs and all six packs in each later ante.
Edition, sticker, reroll, and exact-draw restrictions apply only to shop
`--joker` targets.
Add an inclusive ante range to an individual target with `NAME:MIN-MAX`:

View File

@ -41,7 +41,7 @@ struct Cli {
#[derive(Debug, Subcommand)]
enum Command {
/// Find shop jokers or Soul legendaries on or before an ante.
/// Find shop, Buffoon-pack, or Soul jokers on or before an ante.
FindJokers(FindJokersArgs),
/// Search with the complete engine filter DSL from a JSON file or stdin.
Search(FilterSearchArgs),
@ -166,16 +166,25 @@ struct JokerFilterArgs {
/// Shop joker, optionally NAME:MIN-MAX. Repeat for multiple targets.
#[arg(
long = "joker",
required_unless_present = "legendaries",
required_unless_present_any = ["legendaries", "pack_jokers"],
action = clap::ArgAction::Append,
value_parser = parse_joker_target
)]
jokers: Vec<TargetSpec>,
/// Buffoon-pack joker, optionally NAME:MIN-MAX. Repeat for multiple targets.
#[arg(
long = "pack-joker",
required_unless_present_any = ["jokers", "legendaries"],
action = clap::ArgAction::Append,
value_parser = parse_joker_target
)]
pack_jokers: Vec<TargetSpec>,
/// Soul legendary, optionally NAME:MIN-MAX. Repeat for multiple targets.
#[arg(
long = "legendary",
required_unless_present = "jokers",
required_unless_present_any = ["jokers", "pack_jokers"],
action = clap::ArgAction::Append,
value_parser = parse_legendary_target
)]
@ -589,6 +598,22 @@ fn build_joker_condition_groups(args: &JokerFilterArgs) -> Vec<Clause> {
.collect(),
},
}));
groups.extend(args.pack_jokers.iter().map(|target| {
let antes = target.range.map_or_else(
|| (1..=args.before_ante).collect::<Vec<_>>(),
|range| range.antes().collect::<Vec<_>>(),
);
Clause::AnyOf {
clauses: antes
.into_iter()
.map(|ante| Clause::AnteAnyPackContains {
ante,
max_packs: if ante == 1 { 4 } else { 6 },
card: target.name.clone(),
})
.collect(),
}
}));
groups
}
@ -1186,6 +1211,17 @@ fn run_find_jokers(args: FindJokersArgs) -> Result<()> {
.join(",")
));
}
if !args.query.pack_jokers.is_empty() {
context_parts.push(format!(
"pack_jokers={}",
args.query
.pack_jokers
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
));
}
context_parts.push(format!("mode={mode}"));
context_parts.push(format!("before_ante={}", args.query.before_ante));
if let Some(max_rerolls) = args.query.max_rerolls {
@ -1493,10 +1529,10 @@ fn completion_script(shell: CompletionShell) -> &'static str {
return
fi
case "${COMP_WORDS[1]}" in
find-jokers) COMPREPLY=( $(compgen -W "--joker --legendary --before-ante --mode --edition --sticker --slot --max-rerolls --print-filter --deck --stake --seed-length --seed-size --seed-prefix --named --start-rank --random-start --max-seeds --max-matches --threads --progress --explain --output --help" -- "$cur") ) ;;
find-jokers) COMPREPLY=( $(compgen -W "--joker --pack-joker --legendary --before-ante --mode --edition --sticker --slot --max-rerolls --print-filter --deck --stake --seed-length --seed-size --seed-prefix --named --start-rank --random-start --max-seeds --max-matches --threads --progress --explain --output --help" -- "$cur") ) ;;
search) COMPREPLY=( $(compgen -W "--filter --deck --stake --seed-length --seed-size --seed-prefix --named --start-rank --random-start --max-seeds --max-matches --threads --progress --explain --output --help" -- "$cur") ) ;;
inspect) COMPREPLY=( $(compgen -W "--filter --antes --deck --stake --output --help" -- "$cur") ) ;;
create-filter) COMPREPLY=( $(compgen -W "--joker --legendary --before-ante --mode --edition --sticker --slot --max-rerolls --output --force --help" -- "$cur") ) ;;
create-filter) COMPREPLY=( $(compgen -W "--joker --pack-joker --legendary --before-ante --mode --edition --sticker --slot --max-rerolls --output --force --help" -- "$cur") ) ;;
list) COMPREPLY=( $(compgen -W "jokers editions stickers tags bosses vouchers cards decks stakes all" -- "$cur") ) ;;
completions) COMPREPLY=( $(compgen -W "bash zsh fish" -- "$cur") ) ;;
esac
@ -1508,16 +1544,17 @@ complete -F _balatro_seed_search balatro-seed-search
r#"#compdef balatro-seed-search
_arguments '1:command:(find-jokers search inspect create-filter list completions help)' '*::argument:->args'
case $words[2] in
find-jokers) _arguments '--joker[shop joker, optionally NAME:MIN-MAX]:joker:' '--legendary[Soul legendary, optionally NAME:MIN-MAX]:joker:' '--before-ante[default inclusive last ante]:ante:' '--mode[all or any]:(all any)' '--edition[edition]:' '--sticker[sticker]:' '--slot[exact zero-based ante queue position]:draw:' '--max-rerolls[first two-card visit plus rerolls]:count:' '--print-filter' '--deck[deck]:' '--stake[stake]:' '--seed-length[length]:' '--seed-size[scan every seed of this length]:length:' '--seed-prefix[required seed prefix]:' '--named[seed fragment allowed anywhere]:' '--start-rank[candidate rank]:' '--random-start[random starting rank]' '--max-seeds[count]:' '--max-matches[count]:' '--threads[count]:' '--progress[duration]:' '--explain[show where each condition is first met]' '--output[format]:(human pretty jsonl seeds)' ;;
find-jokers) _arguments '--joker[shop joker, optionally NAME:MIN-MAX]:joker:' '--pack-joker[Buffoon-pack joker, optionally NAME:MIN-MAX]:joker:' '--legendary[Soul legendary, optionally NAME:MIN-MAX]:joker:' '--before-ante[default inclusive last ante]:ante:' '--mode[all or any]:(all any)' '--edition[edition]:' '--sticker[sticker]:' '--slot[exact zero-based ante queue position]:draw:' '--max-rerolls[first two-card visit plus rerolls]:count:' '--print-filter' '--deck[deck]:' '--stake[stake]:' '--seed-length[length]:' '--seed-size[scan every seed of this length]:length:' '--seed-prefix[required seed prefix]:' '--named[seed fragment allowed anywhere]:' '--start-rank[candidate rank]:' '--random-start[random starting rank]' '--max-seeds[count]:' '--max-matches[count]:' '--threads[count]:' '--progress[duration]:' '--explain[show where each condition is first met]' '--output[format]:(human pretty jsonl seeds)' ;;
search) _arguments '--filter[saved JSON query]:file:_files' '--deck[deck]:' '--stake[stake]:' '--seed-length[length]:' '--seed-size[scan every seed of this length]:length:' '--seed-prefix[required seed prefix]:' '--named[seed fragment allowed anywhere]:' '--start-rank[candidate rank]:' '--random-start[random starting rank]' '--max-seeds[count]:' '--max-matches[count]:' '--threads[count]:' '--progress[duration]:' '--explain[show where each condition is first met]' '--output[format]:(human pretty jsonl seeds)' ;;
inspect) _arguments '1:seed:' '--filter[saved JSON query]:file:_files' '--antes[count]:' '--deck[deck]:' '--stake[stake]:' '--output[format]:(human pretty jsonl seeds)' ;;
create-filter) _arguments '--joker[shop joker, optionally NAME:MIN-MAX]:joker:' '--legendary[Soul legendary, optionally NAME:MIN-MAX]:joker:' '--before-ante[default inclusive last ante]:ante:' '--mode[all or any]:(all any)' '--edition[edition]:' '--sticker[sticker]:' '--slot[exact zero-based ante queue position]:draw:' '--max-rerolls[first two-card visit plus rerolls]:count:' '--output[JSON destination]:file:_files' '--force[replace output file]' ;;
create-filter) _arguments '--joker[shop joker, optionally NAME:MIN-MAX]:joker:' '--pack-joker[Buffoon-pack joker, optionally NAME:MIN-MAX]:joker:' '--legendary[Soul legendary, optionally NAME:MIN-MAX]:joker:' '--before-ante[default inclusive last ante]:ante:' '--mode[all or any]:(all any)' '--edition[edition]:' '--sticker[sticker]:' '--slot[exact zero-based ante queue position]:draw:' '--max-rerolls[first two-card visit plus rerolls]:count:' '--output[JSON destination]:file:_files' '--force[replace output file]' ;;
esac
"#
}
CompletionShell::Fish => {
r#"complete -c balatro-seed-search -f -n '__fish_use_subcommand' -a 'find-jokers search inspect create-filter list completions help'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from find-jokers' -l joker -d 'Shop joker, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from find-jokers' -l pack-joker -d 'Buffoon-pack joker, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from find-jokers' -l legendary -d 'Soul legendary, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from find-jokers' -l before-ante -d 'Default inclusive last ante'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from find-jokers' -l mode -a 'all any'
@ -1533,6 +1570,7 @@ complete -c balatro-seed-search -n '__fish_seen_subcommand_from search inspect'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l output -r
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l force
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l joker -d 'Shop joker, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l pack-joker -d 'Buffoon-pack joker, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l legendary -d 'Soul legendary, optionally NAME:MIN-MAX'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l before-ante -d 'Default inclusive last ante'
complete -c balatro-seed-search -n '__fish_seen_subcommand_from create-filter' -l mode -a 'all any'
@ -1807,6 +1845,40 @@ mod tests {
assert!(Cli::try_parse_from(["balatro-seed-search", "find-jokers"]).is_err());
}
#[test]
fn parses_pack_joker_targets_and_builds_pack_clauses() {
let cli = Cli::try_parse_from([
"balatro-seed-search",
"find-jokers",
"--pack-joker",
"blueprint:2-3",
"--pack-joker",
"Joker",
"--before-ante",
"1",
])
.unwrap();
let Command::FindJokers(args) = cli.command else {
panic!("wrong command")
};
assert_eq!(args.query.pack_jokers[0].name, "Blueprint");
assert_eq!(args.query.pack_jokers[0].range.unwrap().to_string(), "2-3");
let filter = build_joker_filter(&args.query);
assert!(matches!(
filter.clauses.as_slice(),
[Clause::AnyOf { clauses: ranged }, Clause::AnyOf { clauses: defaulted }]
if matches!(ranged.as_slice(), [
Clause::AnteAnyPackContains { ante: 2, max_packs: 6, card },
Clause::AnteAnyPackContains { ante: 3, max_packs: 6, .. },
] if card == "Blueprint")
&& matches!(defaulted.as_slice(), [
Clause::AnteAnyPackContains { ante: 1, max_packs: 4, card }
] if card == "Joker")
));
assert!(filter.compile_checked().is_ok());
}
#[test]
fn rejects_bad_names_with_suggestions() {
let error = Cli::try_parse_from([
@ -1908,6 +1980,7 @@ mod tests {
range: None,
})
.collect(),
pack_jokers: Vec::new(),
legendaries: Vec::new(),
before_ante,
mode,
@ -2089,6 +2162,30 @@ mod tests {
assert_eq!(matches, ["ALEEB"]);
}
#[test]
fn pack_joker_shortcut_matches_known_buffoon_pack() {
let mut args = joker_args(&[], MatchMode::All, 1);
args.query.pack_jokers = vec![parse_joker_target("Blueprint").unwrap()];
args.search.run.seed_length = 5;
let filter = build_joker_filter(&args.query);
let compiled = filter.compile_checked().unwrap();
let config = RunConfig {
deck: parse_deck("Red Deck").unwrap(),
stake: parse_stake("White Stake").unwrap(),
seed: [0; 8],
seed_len: 5,
};
let searcher = test_searcher(&config, &compiled);
let rank = Seed::parse("111AR").unwrap().rank();
let mut matches = Vec::new();
searcher.scan(rank, 1, |record| matches.push(record.seed));
assert_eq!(matches, ["111AR"]);
let report = inspect_filter(&filter, "111AR", &config);
assert_eq!(report.matched, 1);
assert!(report.clauses[0].detail.contains("Buffoon Pack"));
}
#[test]
fn wraps_joker_groups_for_any_mode() {
let args = joker_args(&["Blueprint", "Brainstorm"], MatchMode::Any, 2);