fix(scores): restore per-player high-score flow

The rewrite waited for the whole game to finish, selected only the maximum
player score, and sorted entries as ordinary unsigned integers. The original
checks each player immediately when their own last ball is lost and compares
scores by signed high word then unsigned low word.

Emit a candidate at each player elimination, prompt qualifying players with the
original `TDK Pinball Player` value, show the table, and then either resume the
next player or return to attract mode. Preserve source table order on import and
insert only strictly qualifying scores with the original word-wise comparator;
keep JSON as the host persistence representation.

Test Plan:
- `cargo test --all-targets` -- passed, 60 tests
- `cargo clippy --all-targets -- -D warnings` -- passed
- `rumdl check tdkpin-rs/CHANGELOG.md tdkpin-rs/RECONSTRUCTION.md` -- passed
- `git diff --cached --check` -- passed
This commit is contained in:
2026-08-23 17:00:12 +02:00
parent 64d41eb605
commit 3fa3e29ad3
5 changed files with 102 additions and 34 deletions
+28 -1
View File
@@ -67,6 +67,7 @@ pub enum Event {
Nudge,
Tilt,
Drain,
HighScoreCandidate(u32),
Sound(u16),
}
@@ -87,7 +88,8 @@ impl Event {
| Self::ExtraBall
| Self::Nudge
| Self::Tilt
| Self::Drain => None,
| Self::Drain
| Self::HighScoreCandidate(_) => None,
}
}
}
@@ -1190,9 +1192,14 @@ impl Game {
} else {
player.balls = player.balls.saturating_sub(1);
}
let high_score_candidate =
(player.balls == 0 && player.extra_balls == 0).then_some(player.score);
self.save_current_rule_state();
events.push(Event::Drain);
events.push(Event::Sound(2008));
if let Some(score) = high_score_candidate {
events.push(Event::HighScoreCandidate(score));
}
self.tilted = false;
self.tilt_counter = 0;
self.tilt_counter_accumulator = 0.0;
@@ -1634,6 +1641,26 @@ mod tests {
assert_eq!(game.multiball_state, MultiballState::Ready);
}
#[test]
fn each_player_reports_a_high_score_candidate_on_their_last_ball() {
let mut game = Game::new(2);
game.players[0].balls = 1;
game.players[0].score = 123_456;
let mut events = Vec::new();
game.drain(&mut events);
assert!(events.contains(&Event::HighScoreCandidate(123_456)));
assert_eq!(game.current_player, 1);
assert!(!game.finished);
events.clear();
game.players[1].balls = 1;
game.players[1].score = 654_321;
game.drain(&mut events);
assert!(events.contains(&Event::HighScoreCandidate(654_321)));
assert!(game.finished);
}
#[test]
fn fast_ball_cannot_tunnel_through_the_top_rail() {
let mut game = Game::new(1);