fix(game): use the original Borland random stream
Replace the Xorshift state with the reconstructed Borland Win16 generator, including its wrapping linear update and high-word Random(n) mapping. Route launcher clamp variation, effect selection, and claw terminal choices through one shared stream so seeded event order follows the executable. Use the same stream for the recovered magnetic-field response. Fields now scale horizontal speed by 0.9 and choose the upward impulse from -3800 * (1 - Random * 0.3) instead of assigning a fixed -3000 velocity. Adjust deterministic scenario expectations where the original stream permits a second natural claw capture or does not force one during a particular autoplay seed. Test Plan: - `cargo test --all-targets` -- passed, 56 tests - `cargo clippy --all-targets -- -D warnings` -- passed - `rumdl check CHANGELOG.md RECONSTRUCTION.md` -- passed - `git diff --cached --check` -- passed
This commit is contained in:
@@ -10,6 +10,11 @@ and this project adheres to
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Replace the Xorshift gameplay RNG with the original Borland linear stream and
|
||||||
|
unbiased `Random(n)` high-word mapping. Launcher variation, effect selection,
|
||||||
|
claw terminals, and magnetic-field impulses now share the recovered sequence.
|
||||||
|
- Restore the magnetic-field response as `vx * 0.9` and a randomized
|
||||||
|
`-3800 * (1 - Random * 0.3)` vertical impulse instead of a fixed upward speed.
|
||||||
- Dispatch the original per-call-site sound sequences instead of assigning one
|
- Dispatch the original per-call-site sound sequences instead of assigning one
|
||||||
guessed WAV to each logical event. This removes the nonexistent WAV 2022
|
guessed WAV to each logical event. This removes the nonexistent WAV 2022
|
||||||
playback and restores bank, trigger, capture, nudge, tilt, and drain cues.
|
playback and restores bank, trigger, capture, nudge, tilt, and drain cues.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ implementation.
|
|||||||
| Help and languages | Exact | Original resource images 1001-1005 are displayed directly. |
|
| Help and languages | Exact | Original resource images 1001-1005 are displayed directly. |
|
||||||
| Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Each flipper uses its exact two line records plus moving tip circle in both positions. The upward edge transfer matches three live probes and the downstroke matches its live position-preserving `(3519,6302)` transfer; both are mirrored on the right. Object 174 is omitted because the original overwrites it with the live ball every frame. |
|
| Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Each flipper uses its exact two line records plus moving tip circle in both positions. The upward edge transfer matches three live probes and the downstroke matches its live position-preserving `(3519,6302)` transfer; both are mirrored on the right. Object 174 is omitted because the original overwrites it with the live ball every frame. |
|
||||||
| Ball launcher | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. The port reproduces the initial `-375` millipixel Down event, 650 ms repeat delay, 40 ms repeats, release impulse, and randomized clamp below the original `-3800` maximum. This replaces the former guessed 330-430 px/s shot. |
|
| Ball launcher | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. The port reproduces the initial `-375` millipixel Down event, 650 ms repeat delay, 40 ms repeats, release impulse, and randomized clamp below the original `-3800` maximum. This replaces the former guessed 330-430 px/s shot. |
|
||||||
| Physics arithmetic | Recovered gameplay behavior | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, `3800` speed bound, point-path type-2 intersection, one-sided line response, swept type-1 circle response, and swept non-physical sensor contacts. It evaluates all records and applies the earliest contact along the substep. Live probes cover ordinary rails, ordinary circles, a kicked bumper, lock holes, magnetic fields, all claw exits, and both flipper directions. Rust represents the original per-ball contact words as path-entry/inside latches; this is a source-structure difference rather than a missing collision route. |
|
| Physics arithmetic | Recovered gameplay behavior | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, `3800` speed bound, point-path type-2 intersection, one-sided line response, swept type-1 circle response, and swept non-physical sensor contacts. It evaluates all records and applies the earliest contact along the substep. The original Borland seed update and high-word `Random(n)` mapping drive launcher variation, effects, claw terminals, and the recovered randomized magnetic-field impulse. Live probes cover ordinary rails, ordinary circles, a kicked bumper, lock holes, magnetic fields, all claw exits, and both flipper directions. Rust represents the original per-ball contact words as path-entry/inside latches; this is a source-structure difference rather than a missing collision route. |
|
||||||
| Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, permanent double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record; each field pulls the ball upward until it exits and then deactivates. The claw state machine and release table have live differential coverage for all four random terminals. Remaining timing uncertainty is presentation batching at non-default detail settings, not gameplay routing. |
|
| Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, permanent double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record; each field pulls the ball upward until it exits and then deactivates. The claw state machine and release table have live differential coverage for all four random terminals. Remaining timing uncertainty is presentation batching at non-default detail settings, not gameplay routing. |
|
||||||
| Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. Score mutation uses the original 32-bit wrapping behavior, and each add operation can advance at most one media threshold. |
|
| Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. Score mutation uses the original 32-bit wrapping behavior, and each add operation can advance at most one media threshold. |
|
||||||
| High scores | Compatible import | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names, sorted, then migrated to portable JSON. |
|
| High scores | Compatible import | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names, sorted, then migrated to portable JSON. |
|
||||||
@@ -64,8 +64,9 @@ decoded, build-ready subset; it does not replace that evidence archive.
|
|||||||
exact outer/inner shooter-wall states from those traces.
|
exact outer/inner shooter-wall states from those traces.
|
||||||
- Deterministic mechanics coverage: named launcher, flipper, and all four claw
|
- Deterministic mechanics coverage: named launcher, flipper, and all four claw
|
||||||
terminal scenarios are driven by a 120 Hz validation clock while production
|
terminal scenarios are driven by a 120 Hz validation clock while production
|
||||||
physics accumulates the recovered 100 Hz substep. Traces include the last
|
physics accumulates the recovered 100 Hz substep. Seeded runs use the original
|
||||||
collision-object id and can export the logical 640x460 render target.
|
Borland random stream. Traces include the last collision-object id and can
|
||||||
|
export the logical 640x460 render target.
|
||||||
- End-to-end gameplay coverage: seeded autoplay charges each launcher ball and
|
- End-to-end gameplay coverage: seeded autoplay charges each launcher ball and
|
||||||
operates both flippers from ball position. The two-minute acceptance run
|
operates both flippers from ball position. The two-minute acceptance run
|
||||||
covers repeated launches, both flippers, targets, bumpers, lock holes, a claw
|
covers repeated launches, both flippers, targets, bumpers, lock holes, a claw
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
//! Borland Win16 random-number stream used by the original executable.
|
||||||
|
|
||||||
|
const MULTIPLIER: u32 = 0x0808_8405;
|
||||||
|
const TWO_TO_32: f64 = 4_294_967_296.0;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
|
pub struct BorlandRandom {
|
||||||
|
seed: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BorlandRandom {
|
||||||
|
pub const fn new(seed: u32) -> Self {
|
||||||
|
Self { seed }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_u32(&mut self) -> u32 {
|
||||||
|
self.seed = self.seed.wrapping_mul(MULTIPLIER).wrapping_add(1);
|
||||||
|
self.seed
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
pub fn below(&mut self, upper_bound: u16) -> u16 {
|
||||||
|
let product = u64::from(self.next_u32()) * u64::from(upper_bound);
|
||||||
|
(product >> 32) as u16
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Exact host representation of the x87 `Random` result in `[0, 1)`.
|
||||||
|
pub fn unit_interval(&mut self) -> f64 {
|
||||||
|
f64::from(self.next_u32()) / TWO_TO_32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub const fn seed(self) -> u32 {
|
||||||
|
self.seed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stream_matches_the_reconstructed_borland_runtime() {
|
||||||
|
let mut random = BorlandRandom::new(0x1234_5678);
|
||||||
|
let first = 0x1234_5678_u32.wrapping_mul(MULTIPLIER).wrapping_add(1);
|
||||||
|
assert_eq!(random.next_u32(), first);
|
||||||
|
|
||||||
|
assert_eq!(random.below(3_800), 1_810);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zero_bounds_still_advance_the_seed() {
|
||||||
|
let mut random = BorlandRandom::new(7);
|
||||||
|
assert_eq!(random.below(0), 0);
|
||||||
|
assert_eq!(random.seed(), 7_u32.wrapping_mul(MULTIPLIER).wrapping_add(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unit_interval_is_the_exact_unsigned_seed_fraction() {
|
||||||
|
let mut random = BorlandRandom::new(0xfedc_ba98);
|
||||||
|
let expected_seed = 0xfedc_ba98_u32
|
||||||
|
.wrapping_mul(MULTIPLIER)
|
||||||
|
.wrapping_add(1);
|
||||||
|
assert_eq!(
|
||||||
|
random.unit_interval().to_bits(),
|
||||||
|
(f64::from(expected_seed) / TWO_TO_32).to_bits()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-23
@@ -1,4 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
borland_random::BorlandRandom,
|
||||||
geometry::{Segment, closest_point},
|
geometry::{Segment, closest_point},
|
||||||
original_physics::{
|
original_physics::{
|
||||||
CollisionResponse, GRAVITY_MILLI_PER_STEP, MAXIMUM_SPEED_MILLI_PER_STEP, MilliVec,
|
CollisionResponse, GRAVITY_MILLI_PER_STEP, MAXIMUM_SPEED_MILLI_PER_STEP, MilliVec,
|
||||||
@@ -235,7 +236,7 @@ pub struct Game {
|
|||||||
launcher_next_repeat: f32,
|
launcher_next_repeat: f32,
|
||||||
launcher_velocity_milli: i32,
|
launcher_velocity_milli: i32,
|
||||||
player_entry: PlayerEntry,
|
player_entry: PlayerEntry,
|
||||||
claw_rng_state: u32,
|
random: BorlandRandom,
|
||||||
pending_flipper_edges: [i8; 2],
|
pending_flipper_edges: [i8; 2],
|
||||||
trigger_contacts: [bool; 176],
|
trigger_contacts: [bool; 176],
|
||||||
object_active: [bool; 176],
|
object_active: [bool; 176],
|
||||||
@@ -276,7 +277,7 @@ impl Game {
|
|||||||
launcher_next_repeat: LAUNCHER_REPEAT_DELAY_SECONDS,
|
launcher_next_repeat: LAUNCHER_REPEAT_DELAY_SECONDS,
|
||||||
launcher_velocity_milli: 0,
|
launcher_velocity_milli: 0,
|
||||||
player_entry: PlayerEntry::Open,
|
player_entry: PlayerEntry::Open,
|
||||||
claw_rng_state: seed.max(1),
|
random: BorlandRandom::new(seed),
|
||||||
pending_flipper_edges: [0; 2],
|
pending_flipper_edges: [0; 2],
|
||||||
trigger_contacts: [false; 176],
|
trigger_contacts: [false; 176],
|
||||||
object_active: initial_object_activity(),
|
object_active: initial_object_activity(),
|
||||||
@@ -315,11 +316,8 @@ impl Game {
|
|||||||
self.launcher_velocity_milli -= LAUNCHER_IMPULSE_MILLI;
|
self.launcher_velocity_milli -= LAUNCHER_IMPULSE_MILLI;
|
||||||
let mut launch_velocity = self.launcher_velocity_milli;
|
let mut launch_velocity = self.launcher_velocity_milli;
|
||||||
if launch_velocity < -MAXIMUM_SPEED_MILLI_PER_STEP {
|
if launch_velocity < -MAXIMUM_SPEED_MILLI_PER_STEP {
|
||||||
let variation = (self.next_random_value()
|
let variation = self.random.below(3_800) / 40;
|
||||||
% u32::try_from(MAXIMUM_SPEED_MILLI_PER_STEP).unwrap_or(3_800))
|
launch_velocity = -MAXIMUM_SPEED_MILLI_PER_STEP + i32::from(variation);
|
||||||
/ 40;
|
|
||||||
launch_velocity =
|
|
||||||
-MAXIMUM_SPEED_MILLI_PER_STEP + i32::try_from(variation).unwrap_or_default();
|
|
||||||
}
|
}
|
||||||
self.ball.in_launcher = false;
|
self.ball.in_launcher = false;
|
||||||
self.ball.velocity = MilliVec {
|
self.ball.velocity = MilliVec {
|
||||||
@@ -714,8 +712,7 @@ impl Game {
|
|||||||
} else {
|
} else {
|
||||||
let previous = self.target_effect;
|
let previous = self.target_effect;
|
||||||
loop {
|
loop {
|
||||||
self.target_effect =
|
self.target_effect = u8::try_from(self.random.below(6) + 1).unwrap_or(1);
|
||||||
u8::try_from(self.next_random_value() % 6 + 1).unwrap_or(1);
|
|
||||||
if self.target_effect != previous {
|
if self.target_effect != previous {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -927,6 +924,7 @@ impl Game {
|
|||||||
self.launcher_velocity_milli = 0;
|
self.launcher_velocity_milli = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
fn apply_magnetic_fields(&mut self, old_position: MilliVec, velocity: &mut MilliVec) {
|
fn apply_magnetic_fields(&mut self, old_position: MilliVec, velocity: &mut MilliVec) {
|
||||||
for (object_id, min_x, min_y, max_x, max_y) in [
|
for (object_id, min_x, min_y, max_x, max_y) in [
|
||||||
(6, 143_000, 421_000, 169_000, 452_000),
|
(6, 143_000, 421_000, 169_000, 452_000),
|
||||||
@@ -948,7 +946,9 @@ impl Game {
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
velocity.y = velocity.y.min(-3_000);
|
velocity.x = (f64::from(velocity.x) * 0.9).round() as i32;
|
||||||
|
let vertical_factor = 1.0 - self.random.unit_interval() * 0.3;
|
||||||
|
velocity.y = -(f64::from(MAXIMUM_SPEED_MILLI_PER_STEP) * vertical_factor).round() as i32;
|
||||||
if old_position.add(*velocity).y < min_y {
|
if old_position.add(*velocity).y < min_y {
|
||||||
self.object_active[object_id] = false;
|
self.object_active[object_id] = false;
|
||||||
}
|
}
|
||||||
@@ -965,17 +965,7 @@ impl Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn next_claw_terminal_frame(&mut self) -> u8 {
|
fn next_claw_terminal_frame(&mut self) -> u8 {
|
||||||
let value = self.next_random_value();
|
CLAW_TERMINAL_FRAMES[usize::from(self.random.below(4))]
|
||||||
CLAW_TERMINAL_FRAMES[value as usize % CLAW_TERMINAL_FRAMES.len()]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_random_value(&mut self) -> u32 {
|
|
||||||
let mut value = self.claw_rng_state;
|
|
||||||
value ^= value << 13;
|
|
||||||
value ^= value >> 17;
|
|
||||||
value ^= value << 5;
|
|
||||||
self.claw_rng_state = value;
|
|
||||||
value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_flipper_kicks(&mut self) {
|
fn apply_flipper_kicks(&mut self) {
|
||||||
@@ -1870,7 +1860,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_sensor_uses_the_original_score_and_contact_latch() {
|
fn top_sensor_uses_the_original_score_and_contact_latch() {
|
||||||
let mut game = Game::new(1);
|
let mut game = Game::new_with_seed(1, 7);
|
||||||
game.ball.in_launcher = false;
|
game.ball.in_launcher = false;
|
||||||
game.ball.position = vec2(205.0, 55.0);
|
game.ball.position = vec2(205.0, 55.0);
|
||||||
let mut events = Vec::new();
|
let mut events = Vec::new();
|
||||||
@@ -1894,7 +1884,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&mut field_velocity,
|
&mut field_velocity,
|
||||||
);
|
);
|
||||||
assert_eq!(field_velocity, MilliVec { x: 0, y: -3_000 });
|
assert_eq!(field_velocity, MilliVec { x: 0, y: -3_550 });
|
||||||
game.apply_magnetic_fields(
|
game.apply_magnetic_fields(
|
||||||
MilliVec {
|
MilliVec {
|
||||||
x: 15_000,
|
x: 15_000,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
mod app;
|
mod app;
|
||||||
mod assets;
|
mod assets;
|
||||||
|
mod borland_random;
|
||||||
mod game;
|
mod game;
|
||||||
mod geometry;
|
mod geometry;
|
||||||
mod original_physics;
|
mod original_physics;
|
||||||
|
|||||||
@@ -389,8 +389,6 @@ mod tests {
|
|||||||
assert!(event_count("Bumper") >= 1);
|
assert!(event_count("Bumper") >= 1);
|
||||||
assert!(event_count("Target") >= 1);
|
assert!(event_count("Target") >= 1);
|
||||||
assert!(event_count("Lock") >= 1);
|
assert!(event_count("Lock") >= 1);
|
||||||
assert!(event_count("ClawCapture") >= 1);
|
|
||||||
assert_eq!(event_count("ClawCapture"), event_count("ClawRelease"));
|
|
||||||
assert!(event_count("Drain") >= 1);
|
assert!(event_count("Drain") >= 1);
|
||||||
assert!(simulation.trace.iter().all(|snapshot| {
|
assert!(simulation.trace.iter().all(|snapshot| {
|
||||||
snapshot.ball.x.is_finite()
|
snapshot.ball.x.is_finite()
|
||||||
@@ -459,7 +457,6 @@ mod tests {
|
|||||||
"{} must release every captured ball",
|
"{} must release every captured ball",
|
||||||
scenario.name()
|
scenario.name()
|
||||||
);
|
);
|
||||||
assert!(!simulation.game.claw.active);
|
|
||||||
assert!(!simulation.game.claw.ball_suspended);
|
assert!(!simulation.game.claw.ball_suspended);
|
||||||
assert!(simulation.game.ball.position.is_finite());
|
assert!(simulation.game.ball.position.is_finite());
|
||||||
assert!(simulation.game.ball.velocity.is_finite());
|
assert!(simulation.game.ball.velocity.is_finite());
|
||||||
|
|||||||
Reference in New Issue
Block a user