P-Lens is a bookkeeping app for a player's own pachinko and pachislot results. For a pachislot play, it works out from the data counter's figures how likely each setting is, by Bayesian inference: what was thought likely before looking (the prior), times how likely the counter's figures are under each setting (the likelihood), gives how likely each setting is after looking (the posterior).
The likelihood
For a machine of bonuses, each game is taken to come up BIG, REG, a small win the player counted, or nothing counted, with each setting's published chances. The games nobody counted share what is left of the probability. From crates/pachislot-engine/src/posterior.rs:
/// The regular games' part of a stretch's log-likelihood: every count but
/// a watch's cues.
fn regular_log_likelihood(table: &SettingLevelTable, segment: &Segment) -> f64 {
let chance = |id: &EntityId| -> f64 {
table
.events
.iter()
.filter(|event| event.answers_to(id))
.map(|event| event.chance.value())
.sum()
};
let (counted, covered, log) = segment
.counts
.iter()
.filter(|(id, _)| !is_cue(table, id))
.fold((0_u64, 0.0, 0.0), |(counted, covered, log), (id, count)| {
let probability = chance(id);
(
counted + u64::from(*count),
covered + probability,
log + times(u64::from(*count), probability.ln()),
)
});
let rest = u64::from(segment.games).saturating_sub(counted);
log + times(rest, (-covered).ln_1p())
}
The product is taken in logarithms: the probability of 8,000 particular games is far too small a number for a float to hold. Each setting's log-likelihood is added to its log-prior, and the results are scaled back to shares summing to one. Figures impossible under every setting the prior allows are an error, ContradictoryEvidence, rather than the least impossible setting (the same file):
/// Each setting's prior weighed by what was seen under its table, as a
/// share of all of them.
fn weighed(
spec: &NormalizedSpec,
prior: Option<&Distribution>,
seen: impl Fn(&SettingLevelTable) -> f64,
) -> Result<Posterior, InferenceError> {
let logs: Vec<f64> = log_prior(spec, prior)?
.into_iter()
.zip(&spec.tables)
.map(|(log_prior, table)| log_prior + seen(table))
.map(|log| if log.is_nan() { f64::NEG_INFINITY } else { log })
.collect();
let total = log_sum_exp(&logs);
if !total.is_finite() {
return Err(InferenceError::ContradictoryEvidence);
}
Ok(Posterior {
setting_levels: spec
.setting_levels()
.zip(logs)
.map(|(setting_level, log)| (setting_level, (log - total).exp()))
.collect(),
})
}
An AT machine's history is read the same way, its ATs and the games before each walked through the machine's ceilings and modes, setting by setting.
Spec sheets also list screens a machine shows only under some settings: a trophy at the end of an AT that appears only at setting 4 or higher, say. Players call these 確定演出 (kakutei enshutsu, confirming effects). A formula may name each one with the settings it can be seen under. On the live screen the player marks it seen rather than counting it, since once is all it tells, and every setting it never appears under is given no likelihood at all: a trophy that says setting 4 or higher leaves settings 1 to 3 at 0%. Hints that are only likelier under high settings are counted instead, as the share of some event they appeared on, such as a dress on the round screen within an AT, and weighed against each setting's chance of it.
The prior
Nobody but the parlor knows how many cabinets it set high that day. P-Lens offers ten spreads of settings to start from, from a day the parlor collects to cabinets said to be part of an all-high row, and a player can choose a spread from the shared catalog instead. From core/pachislot/prior.ts:
/**
* Each stock spread's shares of setting levels 1 to 6, in basis points,
* harshest first. They are made here, not taken from anywhere: what people
* who ran parlors and people who played for a living have said in public
* agrees on the shape — an ordinary day is mostly 1 with some 2, seldom
* above 4, its levels averaging 1.2 to 1.6; a day a parlor gives back
* averages near 2 and brings 5 and 6 in; a day it collects is nearly all
* 1 — and each spread here is one point within that shape. No level is
* given nothing: a spread that rules a level out could never be argued out
* of it by what the cabinet then does. `featured` is not a parlor's day
* but a cabinet's standing on one: one of those the day's high levels were
* said to be put in.
*/
const STOCK_SHARES: Readonly<Record<StockSpreadKey, readonly number[]>> = {
collecting: [8200, 1300, 350, 100, 30, 20],
"ordinary-harsh": [7000, 2000, 600, 300, 60, 40],
ordinary: [6000, 2500, 900, 500, 60, 40],
"ordinary-kind": [4500, 3000, 1300, 900, 200, 100],
"event-weak": [5500, 2200, 800, 800, 350, 350],
event: [4800, 2000, 700, 1100, 650, 750],
"event-strong": [4000, 2000, 900, 1300, 800, 1000],
"new-machine": [3500, 2400, 1700, 1200, 700, 500],
"grand-opening": [4000, 2500, 1200, 1200, 500, 600],
featured: [1000, 1000, 1000, 2500, 2000, 2500],
}
Where nobody chooses one, a play starts from ordinary, shown in the app as 通常営業(標準) (prior.ts). The prior matters as much as the counter does, and the app says under the odds which spread they were worked out under: 設定配分「…」のもとでの見込みです, "the odds under the spread …" (SettingLevelOdds.tsx).
A worked example
The test machine above has only two settings, 1 and 6, with BIG at 1 in 250 and 1 in 200 and REG at 1 in 400 and 1 in 250. Say its data counter shows 4,000 games, 20 BIGs and 14 REGs. The engine, called directly at v0.10.63, under two priors:
| Prior (1 : 6) | Setting 1 | Setting 6 | Payout |
|---|
| Even | 25.9% | 74.1% | 109.49% |
| 90 : 10 | 75.9% | 24.1% | 101.76% |
The same 4,000 games read as probably setting 6 when the two were alike beforehand, and as probably setting 1 when one cabinet in ten was thought to be set high. The payout rate in the last column is each setting's weighed by the posterior. The figures were chosen for the example; the fixture has two settings rather than six, so the app's stock spreads, which share among six, are not used here.
On screen, the posterior is read in three figures players use. From core/pachislot/setting-level-reading.ts:
/**
* What a posterior over settings says, in the words players use: how likely a
* high setting is, the setting the odds average to, and the single most
* likely one. The engine gives the distribution; these only read it.
*/
export interface SettingLevelReading {
/** 高設定期待度: the chance the setting is at least `threshold`. */
readonly highShare: number
readonly threshold: number
/** 期待設定: the settings averaged by their chance, `3.22` and the like. */
readonly averageSettingLevel: number
/** 最有力: the most likely setting; where several are as likely as each other, the middle one of them, the lower where two are in the middle. */
readonly mostLikely: number | undefined
}