refactor: replace local DrawMode with upstream klondike::DrawStockConfig (#82)
DrawMode was a 1:1 mirror of klondike::DrawStockConfig (DrawOne/DrawThree). Delete it and use the upstream type everywhere; re-export DrawStockConfig from solitaire_core. config_for assigns draw_stock directly and draw_mode() returns session.config().inner.draw_stock. Serde is unchanged — DrawStockConfig serialises to the same "DrawOne"/"DrawThree" named variants, so persisted game_state.json / replay JSON stay byte-compatible (no migration). Field/method/variable names containing draw_mode are unchanged. 35 files, mechanical type swap across all crates. Implemented via a multi-agent workflow (core → per-crate consumers → verify). cargo test --workspace and clippy --workspace --all-targets -- -D warnings green. Closes #82 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@ use bevy::prelude::*;
|
||||
use bevy::tasks::{AsyncComputeTaskPool, Task, futures_lite::future};
|
||||
use bevy::window::AppLifecycle;
|
||||
use solitaire_core::KlondikePile;
|
||||
use solitaire_core::{DrawMode, game_state::{GameMode, GameState}};
|
||||
use solitaire_core::{DrawStockConfig, game_state::{GameMode, GameState}};
|
||||
use solitaire_core::{DEFAULT_SOLVE_MOVES_BUDGET, DEFAULT_SOLVE_STATES_BUDGET};
|
||||
#[allow(deprecated)]
|
||||
use solitaire_data::latest_replay_path;
|
||||
@@ -157,12 +157,12 @@ impl Plugin for GamePlugin {
|
||||
.is_some_and(|g| g.move_count() > 0 && !g.is_won());
|
||||
let (initial_state, pending_restore) = if prompt_worthy {
|
||||
(
|
||||
GameState::new(seed_from_system_time(), DrawMode::DrawOne),
|
||||
GameState::new(seed_from_system_time(), DrawStockConfig::DrawOne),
|
||||
saved,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
saved.unwrap_or_else(|| GameState::new(seed_from_system_time(), DrawMode::DrawOne)),
|
||||
saved.unwrap_or_else(|| GameState::new(seed_from_system_time(), DrawStockConfig::DrawOne)),
|
||||
None,
|
||||
)
|
||||
};
|
||||
@@ -388,7 +388,7 @@ fn poll_pending_new_game_seed(
|
||||
|
||||
/// Pure helper extracted for testability — `new_game_with_solver_*`
|
||||
/// engine tests in the same file exercise this path.
|
||||
pub(crate) fn choose_winnable_seed(initial_seed: u64, draw_mode: DrawMode) -> u64 {
|
||||
pub(crate) fn choose_winnable_seed(initial_seed: u64, draw_mode: DrawStockConfig) -> u64 {
|
||||
let mut seed = initial_seed;
|
||||
for _ in 0..SOLVER_DEAL_RETRY_CAP {
|
||||
match GameState::solve_fresh_deal(
|
||||
@@ -830,8 +830,8 @@ fn handle_draw(
|
||||
Vec::new()
|
||||
} else {
|
||||
let draw_count = match game.0.draw_mode() {
|
||||
DrawMode::DrawOne => 1_usize,
|
||||
DrawMode::DrawThree => 3_usize,
|
||||
DrawStockConfig::DrawOne => 1_usize,
|
||||
DrawStockConfig::DrawThree => 3_usize,
|
||||
};
|
||||
let n = stock.len();
|
||||
let take = n.min(draw_count);
|
||||
@@ -1324,7 +1324,7 @@ mod tests {
|
||||
app.insert_resource(PendingRestoredGame(None));
|
||||
// Override the system-time seed with a known value.
|
||||
app.world_mut().resource_mut::<GameStateResource>().0 =
|
||||
GameState::new(seed, DrawMode::DrawOne);
|
||||
GameState::new(seed, DrawStockConfig::DrawOne);
|
||||
app
|
||||
}
|
||||
|
||||
@@ -1540,7 +1540,7 @@ mod tests {
|
||||
app.insert_resource(GameStatePath(Some(path.clone())));
|
||||
// Override the seed so we can verify it was written.
|
||||
app.world_mut().resource_mut::<GameStateResource>().0 =
|
||||
GameState::new(7654, DrawMode::DrawOne);
|
||||
GameState::new(7654, DrawStockConfig::DrawOne);
|
||||
|
||||
app.world_mut().write_message(AppExit::Success);
|
||||
app.update();
|
||||
@@ -1559,7 +1559,7 @@ mod tests {
|
||||
|
||||
let path = tmp_gs_path("new_game_delete");
|
||||
// Pre-create a saved file.
|
||||
save_game_state_to(&path, &GameState::new(1, DrawMode::DrawOne)).unwrap();
|
||||
save_game_state_to(&path, &GameState::new(1, DrawStockConfig::DrawOne)).unwrap();
|
||||
assert!(path.exists());
|
||||
|
||||
let mut app = test_app(1);
|
||||
@@ -1693,7 +1693,7 @@ mod tests {
|
||||
fn has_legal_moves_returns_true_for_fresh_game() {
|
||||
// A fresh deal always has a non-empty stock (24 cards), so drawing
|
||||
// is always a legal move regardless of the initial face-up tableau cards.
|
||||
let game = GameState::new(42, DrawMode::DrawOne);
|
||||
let game = GameState::new(42, DrawStockConfig::DrawOne);
|
||||
assert!(
|
||||
has_legal_moves(&game),
|
||||
"fresh deal must contain at least one legal move"
|
||||
@@ -1707,7 +1707,7 @@ mod tests {
|
||||
// immediately placed. The game is only stuck when both stock AND waste
|
||||
// are exhausted and no visible card can be moved.
|
||||
use solitaire_core::card::{Card, Deck, Rank, Suit};
|
||||
let mut game = GameState::new(1, DrawMode::DrawOne);
|
||||
let mut game = GameState::new(1, DrawStockConfig::DrawOne);
|
||||
for foundation in [
|
||||
Foundation::Foundation1,
|
||||
Foundation::Foundation2,
|
||||
@@ -1743,7 +1743,7 @@ mod tests {
|
||||
#[test]
|
||||
fn has_legal_moves_returns_true_when_ace_can_go_to_foundation() {
|
||||
use solitaire_core::card::{Card, Deck, Rank, Suit};
|
||||
let mut game = GameState::new(1, DrawMode::DrawOne);
|
||||
let mut game = GameState::new(1, DrawStockConfig::DrawOne);
|
||||
|
||||
// Empty stock and waste so draw is NOT available.
|
||||
game.set_test_stock_cards(Vec::new());
|
||||
@@ -1787,7 +1787,7 @@ mod tests {
|
||||
// card of its column the previous code would return false (softlock)
|
||||
// even though the player can still move that run.
|
||||
use solitaire_core::card::{Card, Deck, Rank, Suit};
|
||||
let mut game = GameState::new(1, DrawMode::DrawOne);
|
||||
let mut game = GameState::new(1, DrawStockConfig::DrawOne);
|
||||
|
||||
game.set_test_stock_cards(Vec::new());
|
||||
game.set_test_waste_cards(Vec::new());
|
||||
@@ -2185,7 +2185,7 @@ mod tests {
|
||||
assert_eq!(loaded.seed, 7654, "seed must match the live game state");
|
||||
assert_eq!(
|
||||
loaded.draw_mode,
|
||||
DrawMode::DrawOne,
|
||||
DrawStockConfig::DrawOne,
|
||||
"draw_mode must be captured"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -2326,7 +2326,7 @@ mod tests {
|
||||
"with solver toggle off, the requested seed must be honoured exactly"
|
||||
);
|
||||
// Cross-check: the dealt tableau must match GameState::new(999) byte-for-byte.
|
||||
let expected = GameState::new(999, DrawMode::DrawOne);
|
||||
let expected = GameState::new(999, DrawStockConfig::DrawOne);
|
||||
for tableau in [
|
||||
Tableau::Tableau1,
|
||||
Tableau::Tableau2,
|
||||
@@ -2403,7 +2403,7 @@ mod tests {
|
||||
//
|
||||
// Seed 394 was previously Unwinnable under the old DFS; now it resolves
|
||||
// as Inconclusive, so the helper must accept it immediately.
|
||||
let chosen = choose_winnable_seed(394, DrawMode::DrawOne);
|
||||
let chosen = choose_winnable_seed(394, DrawStockConfig::DrawOne);
|
||||
assert_eq!(
|
||||
chosen, 394,
|
||||
"seed 394 resolves as Inconclusive; choose_winnable_seed must accept it as-is"
|
||||
|
||||
Reference in New Issue
Block a user