fix: align shop generation with reference RNG and pools
This commit is contained in:
parent
f634a2ab76
commit
3f8acebce9
|
|
@ -32,13 +32,17 @@ Find the first seed in a small range containing Blueprint on or before ante 2:
|
|||
Expected standard output:
|
||||
|
||||
```text
|
||||
1111111Q
|
||||
11111122
|
||||
```
|
||||
|
||||
`--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.
|
||||
|
||||
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,
|
||||
and later visits are not simulated. See [correctness limits](docs/correctness.md).
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Search guide](docs/searching.md): joker searches, named seeds, inspection,
|
||||
|
|
|
|||
10
TASK.md
10
TASK.md
|
|
@ -588,3 +588,13 @@ regression evidence rather than copying the table blindly.
|
|||
- Checks: CLI conflicts and filter-shape tests; search/inspection equivalence;
|
||||
full tests; strict Clippy; release build; `git diff --check`.
|
||||
- Commit: `cli: add shop reroll cutoff`.
|
||||
|
||||
- [x] **47. Repair audited shop generation.**
|
||||
- Correct rarity key ordering, post-1.0.1c joker pools, and shared hash and
|
||||
decimal rounding semantics; initialize starting deck vouchers consistently.
|
||||
- Describe shop positions as queue draws with conditional reroll locations.
|
||||
Preserve isolated-query semantics and document unmodeled purchase state.
|
||||
- Add external shop fixtures and false-Blueprint regressions; retain Soul and
|
||||
pack regressions. Checks: full tests, strict Clippy, release build, reference
|
||||
comparison, CLI smoke tests, and `git diff --check`.
|
||||
- Commit: `fix: align shop generation with reference RNG and pools`.
|
||||
|
|
|
|||
|
|
@ -8,8 +8,42 @@ 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 draws, including the
|
||||
initial shop and reroll window.
|
||||
default any-slot shop search covers the first 16 modeled queue draws.
|
||||
|
||||
## Shop reference contract
|
||||
|
||||
The shop targets the post-1.0.1c pools (1.0.1f reference), with Vampire in
|
||||
Uncommon and Stuntman in Rare. Rarity keys are `rarity{ante}{source}`, while
|
||||
identity and edition keys put the source before the ante. Hash arithmetic
|
||||
preserves the original operation order; stream state is rounded to 13 decimal
|
||||
places with ties to even, matching decimal formatting of the binary float.
|
||||
|
||||
`tests/fixtures/shop_reference.json` contains 1,024 externally generated card
|
||||
identities, from eight seeds over eight antes and sixteen draws each. The
|
||||
reference is [TheSoul commit 780c1c2](https://github.com/SpectralPack/TheSoul/tree/780c1c21d9c5c283f2229548ee715b5fc2578342),
|
||||
configured as version 10106, Red Deck, White Stake, with unrestricted pools.
|
||||
`tests/reference/shop_oracle.cpp` documents how to reproduce the TSV output
|
||||
against that checkout without executing the Rust implementation. Only display
|
||||
spellings for Driver's License and Mail-In Rebate are normalized in the fixture.
|
||||
The regression covers positive Blueprint results and rejects the old false hit
|
||||
at seed `11111125`, ante 2, queue card 4 (Castle).
|
||||
|
||||
Search and inspection apply Magic, Nebula, and Zodiac starting vouchers.
|
||||
However, each clause is an independent query: there is no chronological
|
||||
purchase, ownership, deck-enhancement, or unlock-state simulation. Conditional
|
||||
jokers remain in the unrestricted pools, and matching several clauses does
|
||||
not prove they are all obtainable along one gameplay route. This policy matches
|
||||
the fixture's explicit settings, not every online analyzer configuration.
|
||||
|
||||
Queue positions do not uniquely identify shop visits. Later visits and rerolls
|
||||
both consume the same ante queue. `--max-rerolls` is a first-visit cutoff with
|
||||
two cards per shop, not a budget for all visits; it rejects Zodiac Deck.
|
||||
Overstock purchases, tags, and other gameplay changes require a route-aware
|
||||
simulator. Edition voucher effects after purchases are not modeled either.
|
||||
|
||||
Shared RNG and pools also affect Buffoon/Wraith contents. Existing Soul and
|
||||
spectral-pack regression fixtures are checked alongside the shop fixtures;
|
||||
passing them is not a claim that every pack on every seed is externally proven.
|
||||
|
||||
The regression suite establishes deterministic self-consistency and
|
||||
published-pool sanity. It is not a complete external, bit-for-bit oracle for
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ allowed reroll. For example, `--max-rerolls 1` generates alternatives for
|
|||
slots 0, 1, 2, and 3. This keeps saved JSON explicit and gives search and
|
||||
inspection identical cutoff semantics.
|
||||
|
||||
This expansion assumes a single two-card shop visit per queried ante, without
|
||||
Overstock or other shop-size changes. Saved JSON stores queue positions, not
|
||||
a reroll budget; using it with another deck or route does not remap the slots.
|
||||
|
||||
The friendly joker command can also generate a starting filter directly:
|
||||
|
||||
```bash
|
||||
|
|
@ -100,8 +104,9 @@ Example:
|
|||
```
|
||||
|
||||
Names use the same case-insensitive validation as command-line arguments. In
|
||||
raw JSON, shop slots 0–1 mean the two opening cards, 2–3 mean the first reroll,
|
||||
and each later pair advances the reroll count. The internal slot value `255`
|
||||
raw JSON, shop slots are zero-based positions in the ante's card queue. Each
|
||||
visit and each reroll consumes cards from that queue. Only for a single
|
||||
two-card visit do slots 2–3 mean the first reroll. The internal slot value `255`
|
||||
means any of the first 16 modeled draws. Invalid names, numeric ranges, and
|
||||
partial-score combinations fail before scanning.
|
||||
|
||||
|
|
|
|||
|
|
@ -71,19 +71,26 @@ balatro-seed-search find-jokers \
|
|||
```
|
||||
|
||||
By default, the command checks the first 16 modeled shop-card draws in every
|
||||
ante: two cards in the opening shop followed by seven two-card rerolls. Use
|
||||
`--max-rerolls X` for the practical cutoff “opening shop plus at most X
|
||||
rerolls.” For example, `--max-rerolls 0` checks only the two opening cards and
|
||||
`--max-rerolls 3` checks the opening shop plus the first three rerolls:
|
||||
ante's queue. `--max-rerolls X` means the first two-card shop visit in that
|
||||
ante, followed by at most X rerolls in that same visit. For example,
|
||||
`--max-rerolls 0` checks its two opening cards and `--max-rerolls 3` checks
|
||||
the first eight queue cards:
|
||||
|
||||
```bash
|
||||
balatro-seed-search find-jokers \
|
||||
--joker Blueprint --before-ante 3 --max-rerolls 3
|
||||
```
|
||||
|
||||
The lower-level `--slot 0..15` option selects one exact zero-based draw. Slots
|
||||
0–1 are the opening shop, 2–3 are reroll 1, 4–5 are reroll 2, and so on through
|
||||
slots 14–15 for reroll 7. `--slot` and `--max-rerolls` are mutually exclusive.
|
||||
The lower-level `--slot 0..15` option selects one exact zero-based queue draw.
|
||||
With one two-card visit, slots 0–1 are the opening cards, 2–3 are reroll 1,
|
||||
and so on. Visiting another shop also consumes this queue; the same positions
|
||||
could instead be opening cards of later visits without any rerolls. Explanations
|
||||
therefore report queue positions, not guaranteed visit/reroll numbers.
|
||||
|
||||
`--max-rerolls` is not a per-visit or whole-run budget and assumes no shop-size
|
||||
changes. It is rejected with Zodiac Deck, whose starting Overstock grants an
|
||||
extra shop card; use explicit queue positions for that deck. `--slot` and
|
||||
`--max-rerolls` are mutually exclusive.
|
||||
Edition and sticker requirements may be combined with either scope:
|
||||
|
||||
```bash
|
||||
|
|
@ -135,8 +142,8 @@ accepted joker, modifier, tag, boss, voucher, card, deck, and stake.
|
|||
remains intentionally machine-clean.
|
||||
- `--deck` and `--stake` select run rules.
|
||||
- `--seed-length 1..8` chooses the generated seed space.
|
||||
- `--max-rerolls 0..7` limits joker targets to the opening shop plus that many
|
||||
two-card rerolls. Without it, joker targets use all 16 modeled draws.
|
||||
- `--max-rerolls 0..7` limits joker targets to the first two-card shop visit
|
||||
plus that many rerolls in the same visit. Without it, use all 16 queue draws.
|
||||
|
||||
`--random-start` and `--start-rank` are mutually exclusive. A random search
|
||||
visits at most the requested number of unique seeds; it never searches the
|
||||
|
|
@ -217,9 +224,9 @@ Without a filter, `inspect` prints an ante overview. With a filter, it explains
|
|||
which clauses matched and where:
|
||||
|
||||
```bash
|
||||
balatro-seed-search inspect 1111111Q --antes 3
|
||||
balatro-seed-search inspect 1111111Q --filter blueprint.json
|
||||
balatro-seed-search inspect 1111111Q --filter blueprint.json --output jsonl
|
||||
balatro-seed-search inspect 11111122 --antes 3
|
||||
balatro-seed-search inspect 11111122 --filter blueprint.json
|
||||
balatro-seed-search inspect 11111122 --filter blueprint.json --output jsonl
|
||||
```
|
||||
|
||||
## Creating advanced filters
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use balatro_seed_search::inspect::{
|
|||
inspect_filter, inspect_overview, InspectionReport, SeedOverview,
|
||||
};
|
||||
use balatro_seed_search::search::{Match, Searcher};
|
||||
use balatro_seed_search::state::RunConfig;
|
||||
use balatro_seed_search::state::{Deck, RunConfig};
|
||||
use balatro_seed_search::tables::{
|
||||
BOSSES, CARDS, ENHANCEMENTS, PLANETS, SEALS, SPECTRALS, STD_EDITIONS, TAGS, TAROTS, VOUCHERS,
|
||||
};
|
||||
|
|
@ -197,7 +197,7 @@ struct JokerFilterArgs {
|
|||
#[arg(long, value_parser = parse_sticker_name, requires = "jokers")]
|
||||
sticker: Option<String>,
|
||||
|
||||
/// Exact zero-based shop draw: 0-1 opening, 2-3 reroll 1, ..., 14-15 reroll 7.
|
||||
/// Exact zero-based card position in the ante's shop queue (0-15).
|
||||
#[arg(
|
||||
long,
|
||||
value_parser = clap::value_parser!(u8).range(0..=15),
|
||||
|
|
@ -206,7 +206,7 @@ struct JokerFilterArgs {
|
|||
)]
|
||||
slot: Option<u8>,
|
||||
|
||||
/// Search the opening shop and no more than this many rerolls (0-7).
|
||||
/// First two-card shop plus this many rerolls (0-7); excludes later visits.
|
||||
#[arg(
|
||||
long,
|
||||
value_parser = clap::value_parser!(u8).range(0..=7),
|
||||
|
|
@ -1127,6 +1127,11 @@ where
|
|||
|
||||
fn run_find_jokers(args: FindJokersArgs) -> Result<()> {
|
||||
validate_search_args(&args.search)?;
|
||||
if args.query.max_rerolls.is_some()
|
||||
&& matches!(parse_deck(&args.search.run.deck)?, Deck::Zodiac)
|
||||
{
|
||||
bail!("--max-rerolls assumes a two-card shop; Zodiac starts with Overstock. Use --slot or a saved filter with explicit queue positions.");
|
||||
}
|
||||
let filter = build_joker_filter(&args.query);
|
||||
if args.print_filter {
|
||||
println!("{}", serde_json::to_string_pretty(&filter)?);
|
||||
|
|
@ -1503,10 +1508,10 @@ 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 draw: 0-1 opening, then two per reroll]:draw:' '--max-rerolls[opening shop plus at most this many 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:' '--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 draw: 0-1 opening, then two per reroll]:draw:' '--max-rerolls[opening shop plus at most this many rerolls]:count:' '--output[JSON destination]:file:_files' '--force[replace output file]' ;;
|
||||
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]' ;;
|
||||
esac
|
||||
"#
|
||||
}
|
||||
|
|
@ -2006,6 +2011,16 @@ mod tests {
|
|||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reroll_cutoff_rejects_zodiac_shop_size() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"balatro-seed-search", "find-jokers", "--joker", "Blueprint",
|
||||
"--deck", "Zodiac", "--max-rerolls", "1", "--print-filter",
|
||||
]).unwrap();
|
||||
let Command::FindJokers(args) = cli.command else { panic!("wrong command") };
|
||||
assert!(run_find_jokers(args).unwrap_err().to_string().contains("Overstock"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_inclusive_soul_groups_for_legendaries() {
|
||||
let mut args = joker_args(&[], MatchMode::All, 3);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub enum Edition { None, Foil, Holographic, Polychrome, Negative }
|
|||
pub fn next_joker_rarity(inst: &mut Instance, source: RandomSource, ante: i32) -> Rarity {
|
||||
match source {
|
||||
RandomSource::Soul => return Rarity::Legendary,
|
||||
// Wraith spectral always yields a Rare joker
|
||||
RandomSource::Wraith => return Rarity::Rare,
|
||||
RandomSource::Null => {} // fall through to roll
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ pub fn next_joker_rarity(inst: &mut Instance, source: RandomSource, ante: i32) -
|
|||
if matches!(source, RandomSource::Soul) { return Rarity::Legendary; }
|
||||
if matches!(source, RandomSource::RareTag) { return Rarity::Rare; }
|
||||
if matches!(source, RandomSource::UncommonTag) { return Rarity::Uncommon; }
|
||||
if matches!(source, RandomSource::RiffRaff) { return Rarity::Common; }
|
||||
if matches!(source, RandomSource::RiffRaff | RandomSource::TopUp) { return Rarity::Common; }
|
||||
|
||||
let key = NodeKey {
|
||||
kind: RandomType::JokerRarity,
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ impl<'de> Deserialize<'de> for AnteRange {
|
|||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum Clause {
|
||||
/// "Ante N shop slot S contains joker X, optional edition E, optional sticker"
|
||||
/// `slot=255` (sentinel) → ANY of the first 16 slots (covers default 4-slot shop
|
||||
/// + up to 12 rerolls without overshooting).
|
||||
/// `slot=255` means any of the first 16 queue draws. Visit/reroll locations
|
||||
/// depend on shop size and the player's route; a slot is not a visit number.
|
||||
AnteShopHasJoker {
|
||||
ante: u8,
|
||||
slot: u8,
|
||||
|
|
|
|||
|
|
@ -162,10 +162,7 @@ pub fn inspect_overview(seed: &str, config: &RunConfig, max_ante: u8) -> SeedOve
|
|||
}
|
||||
|
||||
fn fresh_instance(seed: &str, config: &RunConfig) -> Instance {
|
||||
let mut instance = Instance::new(seed);
|
||||
instance.deck = config.deck;
|
||||
instance.stake = config.stake;
|
||||
instance
|
||||
Instance::from_config(seed, config)
|
||||
}
|
||||
|
||||
fn edition_name(edition: Edition) -> &'static str {
|
||||
|
|
@ -179,11 +176,7 @@ fn edition_name(edition: Edition) -> &'static str {
|
|||
}
|
||||
|
||||
fn shop_draw_location(index: usize) -> String {
|
||||
if index < 2 {
|
||||
format!("opening shop card #{}", index + 1)
|
||||
} else {
|
||||
format!("reroll #{} card #{}", index / 2, index % 2 + 1)
|
||||
}
|
||||
format!("queue card #{}", index + 1)
|
||||
}
|
||||
|
||||
fn inspect_clause(clause: &Clause, seed: &str, config: &RunConfig) -> (bool, String) {
|
||||
|
|
@ -544,7 +537,7 @@ mod tests {
|
|||
partial: false,
|
||||
min_score: None,
|
||||
};
|
||||
let report = inspect_filter(&filter, "1111111Q", &config());
|
||||
let report = inspect_filter(&filter, "ALEEB", &config());
|
||||
assert_eq!(report.matched, 1);
|
||||
assert_eq!(report.total, 2);
|
||||
assert!(report.clauses[0].matched);
|
||||
|
|
@ -560,7 +553,7 @@ mod tests {
|
|||
clauses: vec![Clause::AnteShopHasJoker {
|
||||
ante: 2,
|
||||
slot: 3,
|
||||
joker: "Blueprint".into(),
|
||||
joker: "Castle".into(),
|
||||
edition: None,
|
||||
sticker: None,
|
||||
}],
|
||||
|
|
@ -569,13 +562,14 @@ mod tests {
|
|||
};
|
||||
let report = inspect_filter(&matching, "11111125", &config());
|
||||
assert_eq!(report.matched, 1);
|
||||
assert!(report.clauses[0].detail.contains("reroll #1 card #2"));
|
||||
assert!(report.clauses[0].detail.contains("queue card #4"));
|
||||
|
||||
let mut earlier = matching;
|
||||
let Clause::AnteShopHasJoker { slot, .. } = &mut earlier.clauses[0] else {
|
||||
unreachable!()
|
||||
};
|
||||
*slot = 2;
|
||||
// A later exact draw must not accept Castle from draw #4.
|
||||
*slot = 4;
|
||||
assert_eq!(inspect_filter(&earlier, "11111125", &config()).matched, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,13 +134,20 @@ impl NodeKey {
|
|||
}
|
||||
}
|
||||
|
||||
/// Build the hashed-string form: type_str + source_str + ante_str + resample_str.
|
||||
/// Most streams use type + source + ante. Rarity uniquely uses type +
|
||||
/// ante + source (`rarity2sho`, not `raritysho2`). These are different RNG
|
||||
/// streams, not interchangeable spellings of the same key.
|
||||
fn render(&self) -> String {
|
||||
let mut out = String::with_capacity(40);
|
||||
out.push_str(self.kind.key());
|
||||
if let Some(kind) = self.secondary_kind { out.push_str(kind.key()); }
|
||||
if let Some(s) = self.source { out.push_str(s.key()); }
|
||||
if let Some(a) = self.ante { out.push_str(&a.to_string()); }
|
||||
if matches!(self.kind, RandomType::JokerRarity) {
|
||||
if let Some(a) = self.ante { out.push_str(&a.to_string()); }
|
||||
if let Some(s) = self.source { out.push_str(s.key()); }
|
||||
} else {
|
||||
if let Some(s) = self.source { out.push_str(s.key()); }
|
||||
if let Some(a) = self.ante { out.push_str(&a.to_string()); }
|
||||
}
|
||||
if let Some(r) = self.resample {
|
||||
if r > 0 {
|
||||
out.push_str("_resample");
|
||||
|
|
@ -197,6 +204,26 @@ pub struct Instance {
|
|||
}
|
||||
|
||||
impl Instance {
|
||||
/// Initialize the deck's starting vouchers as well as its identity.
|
||||
/// Queries start with no purchased items; later purchases need an explicit
|
||||
/// simulation and must not be inferred from independently matched clauses.
|
||||
pub fn from_config(seed: &str, config: &crate::state::RunConfig) -> Self {
|
||||
let mut instance = Self::new(seed);
|
||||
instance.deck = config.deck;
|
||||
instance.stake = config.stake;
|
||||
match config.deck {
|
||||
crate::state::Deck::Magic => instance.activate_voucher("Crystal Ball"),
|
||||
crate::state::Deck::Nebula => instance.activate_voucher("Telescope"),
|
||||
crate::state::Deck::Zodiac => {
|
||||
instance.activate_voucher("Tarot Merchant");
|
||||
instance.activate_voucher("Planet Merchant");
|
||||
instance.activate_voucher("Overstock");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
instance
|
||||
}
|
||||
|
||||
pub fn new(seed: &str) -> Self {
|
||||
let mut buf = heapless8::Buf::new();
|
||||
buf.write(seed);
|
||||
|
|
@ -312,7 +339,7 @@ impl Instance {
|
|||
pub fn get_node(&mut self, key: NodeKey) -> f64 {
|
||||
let idx = self.find_or_init(key);
|
||||
let n = self.nodes[idx].as_mut().expect("node initialised");
|
||||
n.state = round_digits(fract(n.state * 1.72431234 + 2.134453429141), 13);
|
||||
n.state = round_decimal13(fract(n.state * 1.72431234 + 2.134453429141));
|
||||
(n.state + self.hashed_seed) * 0.5
|
||||
}
|
||||
|
||||
|
|
@ -420,9 +447,26 @@ impl Instance {
|
|||
#[inline]
|
||||
fn fract(x: f64) -> f64 { x - x.floor() }
|
||||
#[inline]
|
||||
fn round_digits(f: f64, d: u32) -> f64 {
|
||||
let p = 10f64.powi(d as i32);
|
||||
(f * p).round() / p
|
||||
fn round_decimal13(f: f64) -> f64 {
|
||||
// Balatro uses tonumber(string.format("%.13f", value)). Multiplication
|
||||
// by 10^13 can round across a decimal halfway boundary before round()
|
||||
// even sees the value. Scale its exact binary significand by 5^13, then
|
||||
// round the remaining power of two with ties to even. The largest product
|
||||
// is 84 bits, so u128 avoids floating rounding and hot-loop allocations.
|
||||
if !f.is_finite() || f == 0.0 { return f; }
|
||||
debug_assert!((0.0..1.0).contains(&f));
|
||||
let bits = f.to_bits();
|
||||
let exponent = ((bits >> 52) & 0x7ff) as u32;
|
||||
if exponent == 0 { return 0.0; } // subnormals round to zero at 13 places
|
||||
let significand = (bits & ((1_u64 << 52) - 1)) | (1_u64 << 52);
|
||||
let product = significand as u128 * 1_220_703_125; // 5^13
|
||||
let shift = 1062 - exponent; // 1023 bias + 52 fraction bits - 13
|
||||
if shift >= 128 { return 0.0; }
|
||||
let integer = product >> shift;
|
||||
let remainder = product & ((1_u128 << shift) - 1);
|
||||
let halfway = 1_u128 << (shift - 1);
|
||||
let increment = remainder > halfway || (remainder == halfway && integer & 1 != 0);
|
||||
(integer + u128::from(increment)) as f64 / 10_000_000_000_000.0
|
||||
}
|
||||
|
||||
/// Stack-allocated 8-char seed buffer.
|
||||
|
|
@ -448,10 +492,26 @@ mod heapless8 {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn decimal_rounding_matches_game_format_without_double_rounding() {
|
||||
let mut state = 1_u64;
|
||||
for _ in 0..20_000 {
|
||||
state = state.wrapping_mul(6364136223846793005).wrapping_add(1);
|
||||
let value = f64::from_bits((state >> 12) | (1023_u64 << 52)) - 1.0;
|
||||
let expected: f64 = format!("{value:.13}").parse().unwrap();
|
||||
assert_eq!(round_decimal13(value), expected, "{value:.17}");
|
||||
}
|
||||
for value in [0.0, f64::MIN_POSITIVE, f64::from_bits(1), 0.00006103515625, 0.00018310546875] {
|
||||
let expected: f64 = format!("{value:.13}").parse().unwrap();
|
||||
assert_eq!(round_decimal13(value), expected);
|
||||
}
|
||||
assert!(round_decimal13(f64::NAN).is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cache_key_rendering() {
|
||||
let k = NodeKey::with_ante(RandomType::JokerRarity, RandomSource::Shop, 1);
|
||||
assert_eq!(k.render(), "raritysho1");
|
||||
assert_eq!(k.render(), "rarity1sho");
|
||||
let soul = NodeKey::with_secondary_kind(RandomType::Soul, RandomType::Tarot, 1);
|
||||
assert_eq!(soul.render(), "soul_Tarot1");
|
||||
}
|
||||
|
|
|
|||
20
src/rng.rs
20
src/rng.rs
|
|
@ -16,15 +16,14 @@
|
|||
/// computes `pseudohash(key + seed)` where `key` is something like
|
||||
/// `"Joker1"`, `"Tarot1Arcana1"`, `"Voucher1"`, etc.
|
||||
///
|
||||
/// The math is float-fragile — we mirror Immolate's split-int-and-fract
|
||||
/// trick so we match the reference bit-for-bit on every common architecture.
|
||||
/// Preserve the game's operation order. Splitting the integer and fractional
|
||||
/// terms changes some hashes (for example `Joker2sho8FMQNT`). Do not fuse these
|
||||
/// operations or replace them with the historical OpenCL approximation.
|
||||
#[inline]
|
||||
pub fn pseudohash(s: &str) -> f64 {
|
||||
let bytes = s.as_bytes();
|
||||
let len = bytes.len();
|
||||
let mut num: f64 = 1.0;
|
||||
let k: u32 = 32;
|
||||
let shift: f64 = (1u64 << k) as f64; // 2^32
|
||||
|
||||
let mut i = len as isize - 1;
|
||||
while i >= 0 {
|
||||
|
|
@ -34,11 +33,7 @@ pub fn pseudohash(s: &str) -> f64 {
|
|||
// b = pi * (i+1)
|
||||
let b = std::f64::consts::PI * (i as f64 + 1.0);
|
||||
|
||||
let scaled = (a + b) * shift;
|
||||
let int_part = scaled.floor() as i64;
|
||||
|
||||
let fract_part = fract(fract(a * shift) + fract(b * shift));
|
||||
num = fract((int_part as f64 + fract_part) / shift);
|
||||
num = fract(a + b);
|
||||
i -= 1;
|
||||
}
|
||||
num
|
||||
|
|
@ -148,6 +143,13 @@ pub fn pseudoseed_random(seed_string: &str, key: &str) -> LuaRandom {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn hash_matches_lua_reference_for_previously_divergent_keys() {
|
||||
// Direct reverse-byte arithmetic in LuaJIT and pinned TheSoul agree.
|
||||
assert_eq!(pseudohash("Joker2sho8FMQNT"), 0.12115985000809815);
|
||||
assert_eq!(pseudohash("Planetsho67LB2WVPK"), 0.41935267137603205);
|
||||
}
|
||||
|
||||
/// Reference value from running Immolate on seed "PHRAYJUS" with key "Joker1":
|
||||
/// pseudohash("Joker1PHRAYJUS") = 0.4859... (recomputed during port).
|
||||
/// We assert determinism and stable round-trip; exact reference cross-check
|
||||
|
|
|
|||
|
|
@ -144,9 +144,7 @@ impl<'a> Searcher<'a> {
|
|||
/// that needs an isolated sub-run.
|
||||
#[inline]
|
||||
fn evaluate(&self, seed_str: &str) -> u8 {
|
||||
let mut template = Instance::new(seed_str);
|
||||
template.deck = self.config.deck;
|
||||
template.stake = self.config.stake;
|
||||
let template = Instance::from_config(seed_str, self.config);
|
||||
let mut score: u8 = 0;
|
||||
|
||||
for op in &self.filter.ops {
|
||||
|
|
@ -167,8 +165,8 @@ fn eval_op(inst: &Instance, op: &Op) -> bool {
|
|||
match op {
|
||||
Op::HasJoker { ante, slot, joker_id, edition, sticker } => {
|
||||
// Multi-slot shop scan. `slot=255` is the sentinel for
|
||||
// "any of the first 16 draws" — two opening-shop cards plus
|
||||
// seven two-card rerolls under the baseline shop model.
|
||||
// "any of the first 16 queue draws". These equal an opening shop
|
||||
// plus seven rerolls only with two cards and a single shop visit.
|
||||
let scan_end = if *slot == 255 { 16 } else { (*slot as usize) + 1 };
|
||||
let scan_target_only = *slot != 255;
|
||||
let mut sub = inst.clone();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
//! Canonical Balatro item tables, ported from Immolate (lib/items.cl).
|
||||
|
||||
// OpenCL source lines 9–71 (J_C_BEGIN..J_C_END), 60 entries
|
||||
// Post-1.0.1c draw pools, not the item enum's historical rarity grouping.
|
||||
// Reference: SpectralPack/TheSoul include/items.hpp, current-version arrays.
|
||||
// Common: 61 entries.
|
||||
pub const COMMON_JOKERS: &[&str] = &[
|
||||
"Joker",
|
||||
"Greedy Joker",
|
||||
|
|
@ -65,7 +67,7 @@ pub const COMMON_JOKERS: &[&str] = &[
|
|||
"Shoot the Moon",
|
||||
];
|
||||
|
||||
// OpenCL source lines 73–138 (J_U_BEGIN..J_U_END), 64 entries
|
||||
// Uncommon: 64 entries (Vampire is uncommon in the supported version).
|
||||
pub const UNCOMMON_JOKERS: &[&str] = &[
|
||||
"Joker Stencil",
|
||||
"Four Fingers",
|
||||
|
|
@ -87,6 +89,7 @@ pub const UNCOMMON_JOKERS: &[&str] = &[
|
|||
"Card Sharp",
|
||||
"Madness",
|
||||
"Seance",
|
||||
"Vampire",
|
||||
"Shortcut",
|
||||
"Hologram",
|
||||
"Cloud 9",
|
||||
|
|
@ -126,17 +129,15 @@ pub const UNCOMMON_JOKERS: &[&str] = &[
|
|||
"The Idol",
|
||||
"Seeing Double",
|
||||
"Matador",
|
||||
"Stuntman",
|
||||
"Satellite",
|
||||
"Cartomancer",
|
||||
"Astronomer",
|
||||
"Bootstraps",
|
||||
];
|
||||
|
||||
// OpenCL source lines 140–161 (J_R_BEGIN..J_R_END), 20 entries
|
||||
// Rare: 20 entries (Stuntman is rare in the supported version).
|
||||
pub const RARE_JOKERS: &[&str] = &[
|
||||
"DNA",
|
||||
"Vampire",
|
||||
"Vagabond",
|
||||
"Baron",
|
||||
"Obelisk",
|
||||
|
|
@ -151,6 +152,7 @@ pub const RARE_JOKERS: &[&str] = &[
|
|||
"The Family",
|
||||
"The Order",
|
||||
"The Tribe",
|
||||
"Stuntman",
|
||||
"Invisible Joker",
|
||||
"Brainstorm",
|
||||
"Driver's License",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
"source": "https://github.com/SpectralPack/TheSoul/tree/780c1c21d9c5c283f2229548ee715b5fc2578342",
|
||||
"version": "1.0.1f",
|
||||
"configuration": "Red Deck, White Stake, fresh instance per ante, unrestricted item pools, 16 consecutive nextShopItem draws; spelling normalized only",
|
||||
"cases": [
|
||||
{"seed":"11111125","ante":1,"items":["Dusk","Splash","Smeared Joker","Photograph","The Lovers","Trading Card","Spare Trousers","Sixth Sense","Sock and Buskin","Justice","Blue Joker","The Magician","The Hanged Man","The Fool","Zany Joker","Half Joker"]},
|
||||
{"seed":"11111125","ante":2,"items":["Abstract Joker","Card Sharp","To Do List","Castle","Egg","Abstract Joker","Jupiter","Green Joker","Midas Mask","Hanging Chad","Mercury","Square Joker","Ice Cream","Pareidolia","Even Steven","Wee Joker"]},
|
||||
{"seed":"11111125","ante":3,"items":["Pareidolia","Saturn","Mars","Glass Joker","Even Steven","The Lovers","Ceres","Raised Fist","Mars","Egg","Sly Joker","Banner","Lusty Joker","Crazy Joker","Droll Joker","Gift Card"]},
|
||||
{"seed":"11111125","ante":4,"items":["Merry Andy","Matador","The Devil","Golden Ticket","Ramen","Mars","Green Joker","Mars","The Star","Uranus","Square Joker","Runner","Mars","8 Ball","Eris","Abstract Joker"]},
|
||||
{"seed":"11111125","ante":5,"items":["Planet X","Ceres","Chaos the Clown","Wrathful Joker","Uranus","Justice","Faceless Joker","Zany Joker","Satellite","Supernova","Death","Droll Joker","Scary Face","Throwback","Strength","Droll Joker"]},
|
||||
{"seed":"11111125","ante":6,"items":["Flower Pot","Ceremonial Dagger","Hanging Chad","Rocket","Four Fingers","Banner","Planet X","Neptune","Death","Mystic Summit","The Hanged Man","Photograph","The Hanged Man","Red Card","Walkie Talkie","Wrathful Joker"]},
|
||||
{"seed":"11111125","ante":7,"items":["The Chariot","Bootstraps","The High Priestess","Raised Fist","Uranus","The Emperor","Faceless Joker","Mail-In Rebate","Greedy Joker","Lusty Joker","Saturn","Greedy Joker","Delayed Gratification","Neptune","Crazy Joker","Obelisk"]},
|
||||
{"seed":"11111125","ante":8,"items":["Hack","Justice","Golden Ticket","Mystic Summit","Hack","Jolly Joker","Crazy Joker","Greedy Joker","The Sun","The High Priestess","Ceres","The Moon","Hiker","Rough Gem","Chaos the Clown","Zany Joker"]},
|
||||
{"seed":"FMQNT","ante":1,"items":["Stuntman","Earth","Supernova","Drunkard","The Tribe","Cloud 9","The Emperor","Abstract Joker","Earth","Uranus","Eris","Runner","Business Card","The Emperor","Fortune Teller","Business Card"]},
|
||||
{"seed":"FMQNT","ante":2,"items":["Mystic Summit","Banner","Hallucination","Lucky Cat","Strength","The Star","Jolly Joker","The Sun","Crazy Joker","Egg","Banner","Fortune Teller","Zany Joker","Golden Ticket","The Moon","Luchador"]},
|
||||
{"seed":"FMQNT","ante":3,"items":["Abstract Joker","The High Priestess","The Hierophant","Half Joker","Clever Joker","Sly Joker","Droll Joker","Juggler","Seltzer","Gluttonous Joker","Justice","Wily Joker","Odd Todd","Blue Joker","Saturn","Rough Gem"]},
|
||||
{"seed":"FMQNT","ante":4,"items":["Juggler","Square Joker","Wily Joker","Wrathful Joker","Mercury","Trading Card","Chaos the Clown","Brainstorm","Hanging Chad","Cavendish","Delayed Gratification","To the Moon","Pluto","Smeared Joker","Gluttonous Joker","Mars"]},
|
||||
{"seed":"FMQNT","ante":5,"items":["Credit Card","Devious Joker","Mercury","Campfire","Pluto","Delayed Gratification","Mercury","Chaos the Clown","Glass Joker","Sly Joker","Clever Joker","Joker","Eris","Odd Todd","Baron","Golden Ticket"]},
|
||||
{"seed":"FMQNT","ante":6,"items":["Showman","Popcorn","Ride the Bus","Green Joker","Mercury","Venus","Photograph","Saturn","Pluto","Sly Joker","The Devil","The Emperor","Seeing Double","The Chariot","Photograph","Ceres"]},
|
||||
{"seed":"FMQNT","ante":7,"items":["Ice Cream","Saturn","Hallucination","The High Priestess","Planet X","Business Card","Death","Seance","Fortune Teller","Cavendish","Devious Joker","Egg","Justice","Justice","Swashbuckler","Smiley Face"]},
|
||||
{"seed":"FMQNT","ante":8,"items":["Loyalty Card","Pluto","Swashbuckler","Scary Face","Mystic Summit","Loyalty Card","Venus","Mars","The Sun","Photograph","The Magician","Saturn","Red Card","Bloodstone","Swashbuckler","Ramen"]},
|
||||
{"seed":"ALEEB","ante":1,"items":["Trading Card","Rocket","The Empress","Ceremonial Dagger","Joker Stencil","Raised Fist","Seltzer","Drunkard","Scary Face","Smiley Face","Wee Joker","Raised Fist","Popcorn","Square Joker","Joker","Bull"]},
|
||||
{"seed":"ALEEB","ante":2,"items":["Saturn","Zany Joker","Cavendish","Scholar","Even Steven","Mad Joker","8 Ball","Blueprint","Raised Fist","Smiley Face","Delayed Gratification","The World","Swashbuckler","Mars","Photograph","To Do List"]},
|
||||
{"seed":"ALEEB","ante":3,"items":["Smiley Face","Mr. Bones","The Duo","The Trio","The Hermit","Lusty Joker","Venus","Egg","Jolly Joker","Saturn","Delayed Gratification","Crafty Joker","Steel Joker","The Tribe","Sock and Buskin","Shoot the Moon"]},
|
||||
{"seed":"ALEEB","ante":4,"items":["Droll Joker","Mars","8 Ball","Juggler","Egg","Diet Cola","Matador","Scary Face","Faceless Joker","Mercury","Venus","Juggler","Ice Cream","Riff-raff","Mime","Devious Joker"]},
|
||||
{"seed":"ALEEB","ante":5,"items":["The Hierophant","Venus","Mercury","The Hermit","Scholar","Raised Fist","Rough Gem","Clever Joker","Fortune Teller","Splash","Baron","Arrowhead","Delayed Gratification","Devious Joker","Jupiter","The Empress"]},
|
||||
{"seed":"ALEEB","ante":6,"items":["The Hermit","Gluttonous Joker","The Lovers","Business Card","The Hierophant","Mystic Summit","Mercury","Neptune","The Sun","Neptune","Golden Ticket","8 Ball","Mail-In Rebate","Photograph","Mime","Oops! All 6s"]},
|
||||
{"seed":"ALEEB","ante":7,"items":["Joker","Crazy Joker","Ceres","The Devil","8 Ball","Blue Joker","Gluttonous Joker","Sixth Sense","Baseball Card","Hit the Road","Glass Joker","The Magician","Uranus","Burnt Joker","Blue Joker","Mars"]},
|
||||
{"seed":"ALEEB","ante":8,"items":["Dusk","Trading Card","Reserved Parking","Eris","Mail-In Rebate","Sixth Sense","The Sun","Faceless Joker","Planet X","Reserved Parking","Blue Joker","Odd Todd","Venus","Credit Card","Jupiter","Sly Joker"]},
|
||||
{"seed":"ABCD1234","ante":1,"items":["Judgement","Earth","Certificate","Ride the Bus","Popcorn","Venus","Ceremonial Dagger","Ceres","Bull","Blackboard","Delayed Gratification","Stuntman","Bootstraps","Even Steven","Droll Joker","Neptune"]},
|
||||
{"seed":"ABCD1234","ante":2,"items":["Smiley Face","Splash","Odd Todd","Splash","Swashbuckler","Strength","Sly Joker","Ice Cream","Splash","Sly Joker","The Lovers","Crafty Joker","Justice","Judgement","Banner","Mad Joker"]},
|
||||
{"seed":"ABCD1234","ante":3,"items":["Crafty Joker","Shoot the Moon","8 Ball","Certificate","Cloud 9","Planet X","The Empress","To Do List","The High Priestess","Odd Todd","Faceless Joker","Scholar","Shortcut","Hallucination","The Hermit","Sly Joker"]},
|
||||
{"seed":"ABCD1234","ante":4,"items":["Judgement","Drunkard","The Tribe","Red Card","Eris","Dusk","Droll Joker","Wily Joker","Onyx Agate","Earth","Gluttonous Joker","Green Joker","Wrathful Joker","Runner","Abstract Joker","Card Sharp"]},
|
||||
{"seed":"ABCD1234","ante":5,"items":["The Chariot","Red Card","Merry Andy","Runner","Swashbuckler","Justice","Four Fingers","Uranus","The Sun","Business Card","Wrathful Joker","Red Card","Mars","Business Card","Riff-raff","Reserved Parking"]},
|
||||
{"seed":"ABCD1234","ante":6,"items":["Ice Cream","Death","Death","Blueprint","The Hermit","Fibonacci","Jolly Joker","Campfire","Ice Cream","The Hanged Man","Fortune Teller","Fortune Teller","Card Sharp","Hit the Road","To Do List","Uranus"]},
|
||||
{"seed":"ABCD1234","ante":7,"items":["Golden Joker","Constellation","Jolly Joker","Lucky Cat","Planet X","Earth","The Hanged Man","Smiley Face","Ramen","Banner","Greedy Joker","The Fool","Jupiter","Planet X","Throwback","Wrathful Joker"]},
|
||||
{"seed":"ABCD1234","ante":8,"items":["Temperance","Crafty Joker","Ceremonial Dagger","Walkie Talkie","Campfire","Egg","Business Card","Devious Joker","To the Moon","Mercury","Cartomancer","Burnt Joker","Supernova","The Chariot","Wrathful Joker","Zany Joker"]},
|
||||
{"seed":"CHAD","ante":1,"items":["Riff-raff","Clever Joker","Mr. Bones","The Hermit","Faceless Joker","Mime","The Idol","Strength","To Do List","Zany Joker","Judgement","Ride the Bus","Earth","Photograph","Joker","Superposition"]},
|
||||
{"seed":"CHAD","ante":2,"items":["Red Card","The Empress","The Wheel of Fortune","Even Steven","Venus","Throwback","Trading Card","The Wheel of Fortune","Eris","Hanging Chad","Clever Joker","Faceless Joker","Jupiter","Egg","Raised Fist","Superposition"]},
|
||||
{"seed":"CHAD","ante":3,"items":["Smiley Face","To the Moon","8 Ball","Hanging Chad","Riff-raff","Judgement","Neptune","Red Card","Seance","Splash","Jolly Joker","Rough Gem","Bloodstone","Justice","Devious Joker","Merry Andy"]},
|
||||
{"seed":"CHAD","ante":4,"items":["Marble Joker","8 Ball","The Devil","Stone Joker","Gros Michel","Joker","Shortcut","Riff-raff","Hanging Chad","Spare Trousers","Bull","Droll Joker","Riff-raff","The World","Swashbuckler","Ceres"]},
|
||||
{"seed":"CHAD","ante":5,"items":["8 Ball","Clever Joker","The Devil","Reserved Parking","Judgement","Mr. Bones","The Devil","Rocket","Astronomer","Mail-In Rebate","Earth","Cloud 9","Madness","Blackboard","Ice Cream","The Hierophant"]},
|
||||
{"seed":"CHAD","ante":6,"items":["Hiker","The Hermit","The Emperor","The Wheel of Fortune","Ride the Bus","Mail-In Rebate","Flower Pot","Gros Michel","Bloodstone","Crazy Joker","Crafty Joker","Shortcut","Devious Joker","The Devil","Erosion","Merry Andy"]},
|
||||
{"seed":"CHAD","ante":7,"items":["Troubadour","The Trio","Saturn","Odd Todd","The Hanged Man","The Moon","Joker","Scary Face","The Hanged Man","Glass Joker","Throwback","Wily Joker","Neptune","The Trio","The Emperor","Hiker"]},
|
||||
{"seed":"CHAD","ante":8,"items":["Delayed Gratification","Joker","Drunkard","Earth","Golden Ticket","Ice Cream","Steel Joker","Clever Joker","The Lovers","Lusty Joker","Steel Joker","Raised Fist","Mail-In Rebate","Popcorn","Scary Face","Rough Gem"]},
|
||||
{"seed":"7LB2WVPK","ante":1,"items":["Venus","Walkie Talkie","Splash","Mars","The Hierophant","Blue Joker","Gros Michel","Crazy Joker","The Devil","Mail-In Rebate","To Do List","Lucky Cat","Blue Joker","Hanging Chad","Bloodstone","The Family"]},
|
||||
{"seed":"7LB2WVPK","ante":2,"items":["The Fool","8 Ball","Onyx Agate","The Devil","The Chariot","Hanging Chad","Blue Joker","Chaos the Clown","Golden Ticket","Droll Joker","Runner","Hallucination","The Sun","Sly Joker","Devious Joker","Even Steven"]},
|
||||
{"seed":"7LB2WVPK","ante":3,"items":["Egg","The Tower","Venus","Onyx Agate","Uranus","Ride the Bus","Uranus","The Tribe","To the Moon","The Duo","Blue Joker","Splash","Mad Joker","Shortcut","Devious Joker","Mercury"]},
|
||||
{"seed":"7LB2WVPK","ante":4,"items":["Venus","Swashbuckler","Golden Ticket","The World","Even Steven","Golden Ticket","Jupiter","Blackboard","Mail-In Rebate","Earth","Scholar","Mime","Delayed Gratification","Business Card","Credit Card","Ride the Bus"]},
|
||||
{"seed":"7LB2WVPK","ante":5,"items":["Superposition","The High Priestess","Justice","Ceres","Uranus","Temperance","Jolly Joker","Misprint","Seance","Riff-raff","Clever Joker","Brainstorm","Jupiter","Clever Joker","Hiker","Mad Joker"]},
|
||||
{"seed":"7LB2WVPK","ante":6,"items":["Neptune","Runner","Crafty Joker","Greedy Joker","Red Card","Delayed Gratification","Rough Gem","Planet X","Cavendish","Superposition","Ancient Joker","Fortune Teller","Half Joker","Banner","Neptune","The Sun"]},
|
||||
{"seed":"7LB2WVPK","ante":7,"items":["The High Priestess","Planet X","Supernova","Bloodstone","Arrowhead","The World","Scholar","Venus","Greedy Joker","Saturn","Diet Cola","Stone Joker","The Emperor","Venus","The Chariot","Drunkard"]},
|
||||
{"seed":"7LB2WVPK","ante":8,"items":["Popcorn","The Hanged Man","Hack","The Hermit","Reserved Parking","Lucky Cat","Delayed Gratification","Blue Joker","Mercury","Pareidolia","Obelisk","The Hierophant","Eris","8 Ball","Crafty Joker","Eris"]},
|
||||
{"seed":"U8RJYV6M","ante":1,"items":["The Emperor","Walkie Talkie","Juggler","Planet X","Neptune","Strength","Hologram","The Magician","Ramen","Runner","The Devil","Sock and Buskin","The World","Uranus","Gros Michel","Jupiter"]},
|
||||
{"seed":"U8RJYV6M","ante":2,"items":["Shortcut","Satellite","Chaos the Clown","Ceres","The World","Hanging Chad","Earth","Ice Cream","Greedy Joker","Banner","Reserved Parking","Zany Joker","Marble Joker","Stuntman","Four Fingers","Golden Joker"]},
|
||||
{"seed":"U8RJYV6M","ante":3,"items":["Justice","Mime","Chaos the Clown","Droll Joker","Mystic Summit","Eris","Joker","Popcorn","Riff-raff","Photograph","Reserved Parking","Reserved Parking","Shoot the Moon","Golden Ticket","Even Steven","Green Joker"]},
|
||||
{"seed":"U8RJYV6M","ante":4,"items":["The Sun","Hit the Road","Business Card","Death","Lusty Joker","Mystic Summit","Strength","Venus","Space Joker","Hack","The Lovers","The Sun","The Hierophant","Gros Michel","The Emperor","The Empress"]},
|
||||
{"seed":"U8RJYV6M","ante":5,"items":["Bull","Red Card","Dusk","Bull","Temperance","Planet X","Mars","Crazy Joker","Justice","Superposition","8 Ball","Venus","The Sun","Sly Joker","Misprint","Card Sharp"]},
|
||||
{"seed":"U8RJYV6M","ante":6,"items":["Green Joker","Drunkard","Neptune","Brainstorm","Hallucination","Cavendish","Droll Joker","Runner","The Chariot","Golden Joker","Chaos the Clown","Smeared Joker","Judgement","Supernova","Ice Cream","Wrathful Joker"]},
|
||||
{"seed":"U8RJYV6M","ante":7,"items":["Joker Stencil","The Hierophant","Supernova","To Do List","Mail-In Rebate","Neptune","Drunkard","Scholar","The Devil","Blue Joker","Jolly Joker","Matador","Constellation","Vampire","Turtle Bean","Eris"]},
|
||||
{"seed":"U8RJYV6M","ante":8,"items":["Lusty Joker","The Magician","Hallucination","Death","Blue Joker","Cavendish","The Hierophant","Troubadour","The Idol","Eris","Egg","Rough Gem","Jolly Joker","Business Card","The Empress","The Lovers"]},
|
||||
{"seed":"V3PUR5L4","ante":1,"items":["The Hanged Man","Trading Card","Blue Joker","Strength","Gros Michel","Pluto","Supernova","Neptune","Business Card","Clever Joker","Droll Joker","Pluto","Wily Joker","Planet X","Eris","Sixth Sense"]},
|
||||
{"seed":"V3PUR5L4","ante":2,"items":["Red Card","Reserved Parking","Droll Joker","Shoot the Moon","Smiley Face","Chaos the Clown","Onyx Agate","Superposition","Smiley Face","The Wheel of Fortune","The Hermit","The Devil","Showman","The Magician","Golden Joker","Trading Card"]},
|
||||
{"seed":"V3PUR5L4","ante":3,"items":["Earth","Showman","Uranus","Saturn","Raised Fist","Planet X","Uranus","Splash","Scholar","Gros Michel","Splash","Pluto","Reserved Parking","Swashbuckler","Mystic Summit","The Hierophant"]},
|
||||
{"seed":"V3PUR5L4","ante":4,"items":["Temperance","Venus","The Emperor","Golden Joker","Reserved Parking","Ice Cream","The Fool","Ride the Bus","Mercury","Faceless Joker","The Devil","Venus","Faceless Joker","The Sun","Crazy Joker","Ice Cream"]},
|
||||
{"seed":"V3PUR5L4","ante":5,"items":["Egg","The Empress","Banner","Constellation","Swashbuckler","Credit Card","Certificate","Golden Ticket","Blue Joker","Scholar","To Do List","Crafty Joker","Invisible Joker","Burglar","Ancient Joker","Photograph"]},
|
||||
{"seed":"V3PUR5L4","ante":6,"items":["Certificate","Smiley Face","Hallucination","Popcorn","Arrowhead","Hanging Chad","Hack","Cloud 9","Swashbuckler","Campfire","Egg","Banner","Baseball Card","Green Joker","Reserved Parking","Popcorn"]},
|
||||
{"seed":"V3PUR5L4","ante":7,"items":["Shoot the Moon","Venus","Popcorn","Judgement","Ride the Bus","The Moon","Gluttonous Joker","Gros Michel","Sock and Buskin","Shortcut","Ceres","Photograph","Rocket","Mail-In Rebate","Devious Joker","Strength"]},
|
||||
{"seed":"V3PUR5L4","ante":8,"items":["Blue Joker","Juggler","Joker Stencil","Golden Joker","The World","Ride the Bus","Fibonacci","Sly Joker","The Devil","8 Ball","The Empress","Banner","The Sun","The Lovers","Hanging Chad","The Hanged Man"]}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Compile against TheSoul 780c1c21d9c5c283f2229548ee715b5fc2578342:
|
||||
// g++ -std=c++17 -O2 -ffp-contract=off -I /path/to/TheSoul/include \
|
||||
// tests/reference/shop_oracle.cpp -o /tmp/shop-oracle
|
||||
// Run: /tmp/shop-oracle ALEEB
|
||||
// Output: ante, one-based draw, kind, canonical upstream item name (TSV).
|
||||
#include <cmath>
|
||||
using std::isnan;
|
||||
#include "util.hpp"
|
||||
#include "items.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) return 1;
|
||||
for (int ante = 1; ante <= 8; ++ante) {
|
||||
Instance instance(argv[1]);
|
||||
instance.params.version = 10106;
|
||||
for (int draw = 1; draw <= 16; ++draw) {
|
||||
auto card = instance.nextShopItem(ante);
|
||||
std::cout << ante << '\t' << draw << '\t' << card.type << '\t' << card.item << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
use balatro_seed_search::derive::{get_shop_instance, next_joker_rarity, next_shop_item, Rarity};
|
||||
use balatro_seed_search::filter::{Clause, Filter};
|
||||
use balatro_seed_search::inspect::inspect_filter;
|
||||
use balatro_seed_search::state::{Deck, RunConfig, Stake};
|
||||
use balatro_seed_search::{Instance, RandomSource, Searcher, Seed};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Reference {
|
||||
source: String,
|
||||
version: String,
|
||||
configuration: String,
|
||||
cases: Vec<Case>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Case {
|
||||
seed: String,
|
||||
ante: u8,
|
||||
items: Vec<String>,
|
||||
}
|
||||
|
||||
fn config(deck: Deck) -> RunConfig {
|
||||
RunConfig {
|
||||
deck,
|
||||
stake: Stake::White,
|
||||
seed: [0; 8],
|
||||
seed_len: 8,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shop_queues_match_external_versioned_reference() {
|
||||
let reference: Reference =
|
||||
serde_json::from_str(include_str!("fixtures/shop_reference.json")).unwrap();
|
||||
assert!(reference
|
||||
.source
|
||||
.contains("780c1c21d9c5c283f2229548ee715b5fc2578342"));
|
||||
assert_eq!(reference.version, "1.0.1f");
|
||||
assert!(reference.configuration.contains("unrestricted"));
|
||||
assert_eq!(reference.cases.len(), 64);
|
||||
for case in reference.cases {
|
||||
let mut instance = Instance::from_config(&case.seed, &config(Deck::Red));
|
||||
assert_eq!(case.items.len(), 16);
|
||||
for (slot, expected) in case.items.iter().enumerate() {
|
||||
let actual = next_shop_item(&mut instance, case.ante as i32);
|
||||
assert_eq!(
|
||||
actual.item,
|
||||
expected,
|
||||
"{} ante {} draw {}",
|
||||
case.seed,
|
||||
case.ante,
|
||||
slot + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn search_and_inspection_agree_with_positive_and_negative_blueprint_references() {
|
||||
// The old engine incorrectly called 11111125's Castle a Blueprint.
|
||||
// ALEEB is an independently generated positive: ante 2, queue card 8.
|
||||
for (seed, slot, expected) in [
|
||||
("11111125", 3, false),
|
||||
("ALEEB", 7, true),
|
||||
("ALEEB", 8, false),
|
||||
] {
|
||||
let filter = Filter {
|
||||
clauses: vec![Clause::AnteShopHasJoker {
|
||||
ante: 2,
|
||||
slot,
|
||||
joker: "Blueprint".into(),
|
||||
edition: None,
|
||||
sticker: None,
|
||||
}],
|
||||
partial: false,
|
||||
min_score: None,
|
||||
};
|
||||
let compiled = filter.compile_checked().unwrap();
|
||||
let mut config = config(Deck::Red);
|
||||
config.seed_len = seed.len() as u8;
|
||||
let searcher = Searcher {
|
||||
config: &config,
|
||||
filter: &compiled,
|
||||
partial: false,
|
||||
min_score: 0,
|
||||
};
|
||||
let mut hits = 0;
|
||||
searcher.scan_ranks(&[Seed::parse(seed).unwrap().rank()], |_| hits += 1);
|
||||
assert_eq!(hits, usize::from(expected), "search {seed} slot {slot}");
|
||||
let report = inspect_filter(&filter, seed, &config);
|
||||
assert_eq!(
|
||||
report.matched > 0,
|
||||
expected,
|
||||
"inspection {seed} slot {slot}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starting_deck_vouchers_change_shop_rates() {
|
||||
let zodiac = Instance::from_config("ALEEB", &config(Deck::Zodiac));
|
||||
assert!(zodiac.is_voucher_active("Overstock"));
|
||||
assert_eq!(get_shop_instance(&zodiac).tarot, 9.6);
|
||||
assert_eq!(get_shop_instance(&zodiac).planet, 9.6);
|
||||
let ghost = Instance::from_config("ALEEB", &config(Deck::Ghost));
|
||||
assert_eq!(get_shop_instance(&ghost).spectral, 2.0);
|
||||
assert!(Instance::from_config("ALEEB", &config(Deck::Magic)).is_voucher_active("Crystal Ball"));
|
||||
assert!(Instance::from_config("ALEEB", &config(Deck::Nebula)).is_voucher_active("Telescope"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forced_joker_sources_do_not_roll_shop_rarity() {
|
||||
for seed in ["FMQNT", "ALEEB", "11111125"] {
|
||||
let mut instance = Instance::new(seed);
|
||||
for ante in 1..=8 {
|
||||
assert_eq!(
|
||||
next_joker_rarity(&mut instance, RandomSource::Wraith, ante),
|
||||
Rarity::Rare
|
||||
);
|
||||
assert_eq!(
|
||||
next_joker_rarity(&mut instance, RandomSource::TopUp, ante),
|
||||
Rarity::Common
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue