refactor(core): card_game redundancy cleanup + derive scoring from upstream stats #88

Merged
funman300 merged 16 commits from refactor/strip-card_game-redundancies into master 2026-06-22 18:44:38 +00:00
4 changed files with 23 additions and 14 deletions
Showing only changes of commit 8995a8ae9c - Show all commits
+6 -13
View File
@@ -3,7 +3,9 @@
//! [`KlondikeAdapter`] is a pure helper namespace for:
//! - building [`KlondikeConfig`] from Ferrous settings
//! - translating between local and upstream types
//! - applying Ferrous-specific scoring policy on top of upstream defaults
//!
//! Ferrous-specific scoring policy (the win-time bonus) lives in
//! [`crate::scoring`], not here.
//!
//! All `From` / `TryFrom` conversions between `solitaire_core` product types and
//! upstream `card_game` / `klondike` types live here so that the product modules
@@ -14,11 +16,11 @@ use klondike::{
SkipCards, Tableau,
};
/// Bridges `solitaire_core` game config and scoring to the upstream `klondike` crate.
/// Bridges `solitaire_core` game config to the upstream `klondike` crate.
///
/// This type is intentionally zero-sized: it does not carry mutable runtime
/// state, and exists only as a namespace for configuration, conversion, and
/// scoring helpers.
/// state, and exists only as a namespace for configuration and conversion
/// helpers.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct KlondikeAdapter;
@@ -81,12 +83,3 @@ pub fn skip_cards_from_count(skip: usize) -> Option<SkipCards> {
_ => None,
}
}
/// Time bonus added to the score on a win: `700_000 / elapsed_seconds`.
/// Returns 0 when `elapsed_seconds` is 0 to avoid division by zero.
pub fn compute_time_bonus(elapsed_seconds: u64) -> i32 {
if elapsed_seconds == 0 {
return 0;
}
(700_000u64 / elapsed_seconds).min(i32::MAX as u64) as i32
}
+1
View File
@@ -2,6 +2,7 @@ pub mod achievement;
pub mod error;
pub mod game_state;
pub mod klondike_adapter;
pub mod scoring;
// Re-export the upstream types that cross the solitaire_core API boundary so
// downstream crates (engine, wasm) can import from one place without a direct
+15
View File
@@ -0,0 +1,15 @@
//! Ferrous-specific scoring policy layered on top of upstream `klondike`.
//!
//! Upstream [`klondike::KlondikeStats::score`] owns the per-move point values
//! (move-to-foundation, flip-up bonus, recycle penalty, etc.). The functions
//! here are the Ferrous Solitaire house rules that upstream has no opinion on —
//! currently just the win-time bonus shown in the win modal.
/// Time bonus added to the score on a win: `700_000 / elapsed_seconds`.
/// Returns 0 when `elapsed_seconds` is 0 to avoid division by zero.
pub fn compute_time_bonus(elapsed_seconds: u64) -> i32 {
if elapsed_seconds == 0 {
return 0;
}
(700_000u64 / elapsed_seconds).min(i32::MAX as u64) as i32
}
+1 -1
View File
@@ -12,7 +12,7 @@
use bevy::prelude::*;
use solitaire_core::game_state::GameMode;
use solitaire_core::klondike_adapter::compute_time_bonus;
use solitaire_core::scoring::compute_time_bonus;
use solitaire_data::AnimSpeed;
use crate::achievement_plugin::display_name_for;