Skip to content

Add FreeCell variant - #26

Merged
austin-smith merged 14 commits into
mainfrom
freecell
Jul 4, 2026
Merged

austin-smith merged 14 commits into
mainfrom
freecell

Conversation

@austin-smith

@austin-smith austin-smith commented Jul 4, 2026 •

Copy link
Copy Markdown
Owner

Add FreeCell as a new game variant, refactor hint/advisor and auto-move logic, add new pixelated deck variant, and update app icon.

Summary

  • Add FreeCell gameplay with cascades, free cells, supermove rules, solver-backed hints, auto-finish support, and dedicated board UI.
  • Split shared, Klondike-specific, and FreeCell-specific game logic across rules, sessions, persistence, planners, and move advisors.
  • Overhaul hints and tap auto-move behavior with shared legal move generation, variant-specific policies, and a new Klondike planner.
  • Add per-variant and aggregate statistics, including reset behavior scoped to Klondike, FreeCell, or all games.
  • Update Settings with game variant selection, compact table color swatches, and a Classic/Pixel card style selector.
  • Add a pixel card variant.
  • Update app icon.
  • Update rules/scoring UI and docs for multiple game variants.
  • Expand tests across FreeCell rules/solver/auto-finish, shared tap move policy, persistence sanitization, statistics, and Klondike planner behavior.

Split the monolithic game core into variant-aware and shared components and add FreeCell support. Key changes:

- Introduce shared models and rules (Shared/Card.swift, Shared/GameRules.swift) and move Card into a shared location.
- Split variant-specific logic into Klondike and FreeCell modules (rules, persistence, session, state, auto-move advisors).
- Refactor AutoMoveAdvisor to a shared coordinator that delegates variant-specific behavior and to handle free cells as sources/destinations.
- Update game persistence (SavedGamePayload) to sanitize and validate state per-variant and include free cell layout checks.
- Adjust hint/auto-finish logic to be variant-aware (Klondike-specific hint planner and AutoFinishPlanner guarding for Klondike).
- Add new FreeCell/Klondike views, tests, and documentation (docs/solitaire-rules-freecell.md).
- Remove outdated GameModels/GameRules files and apply many file renames/moves to a Shared/ and variant-based structure.

These changes prepare the codebase for multiple solitaire variants by centralizing common logic and isolating variant differences.
Introduce per-variant GameStatistics storage and an aggregated "All" view. Key changes:

- GameStatistics: add aggregated(...) to combine multiple variant stats with overflow-safe counters and helpers.
- GameStatisticsStore: switch to variant-scoped UserDefaults keys (defaultsKey(for:)), and update APIs (load/save/update/reset/markTrackingStarted) to accept a GameVariant parameter.
- SolitaireViewModel: record and finalize stats using the current variant; mark tracking started when switching/decoding into the correct variant bucket.
- StatisticsView & ContentView: add a scope picker (Klondike/FreeCell/All), show aggregated metrics for All, and remove direct new-variant buttons and menu items.
- GameMenuCommands: remove obsolete newKlondike/newFreeCell actions.
- Tests: update usages to load/reset per-variant, add tests for variant isolation, aggregation correctness, overflow safety, and variant-switch finalization; adjust test helper to preserve multiple variant keys.

These changes allow tracking and resetting statistics per game variant and presenting combined statistics across variants when requested.
Simplify flipKlondikeTopCardIfNeeded by removing the unnecessary didFlip variable and its guard check. The top tableau card is flipped and the scoring, sound, and haptic effects are applied immediately. This reduces dead code and clarifies the flip logic without changing behavior.
Wrap TableauPileView content in a safety check so it only renders when viewModel.state.tableau contains the pileIndex, returning an inert clear placeholder otherwise to avoid out-of-bounds access during state changes. Rework the pile ZStack and geometry code: reorder/inline views, preserve drop highlight offsets, and update CardView usage (adds cardSize and related params) and drag handling. Minor UI tweak: remove a redundant caption from SettingsView. Documentation: update README to list supported variants (Klondike and FreeCell) and add a rules table with links to variant rule docs.
Replace the segmented Picker for selecting GameVariant with a custom card-style selector. Added a subtitle computed property to GameVariant and a new variantCard(_:) helper in SettingsView that renders stylized, accessible buttons (material background, shadow, selection stroke, opacity/scale) with haptic feedback and smooth animation on change. This improves clarity and visual presentation of the game type selection.
Show the currently selected table background label in the header and replace the old rectangular swatch+label rows with compact circular color swatches. Renamed backgroundColorRow to colorSwatch and updated visuals: swatches now display a checkmark and accent stroke when selected, expand to fill available space with a fixed aspect ratio, and include accessibility labels/selected traits. Selection still updates tableBackgroundColorRawValue and triggers haptic feedback.
Refactor FreeCellTopRowView to control spacing more precisely by grouping the four free cells and four foundations into fixed-width HStacks. Introduces computed innerGap, middleGap and groupWidth so the two groups are separated by a clear spacer (preserving alignment and visual gap) while keeping consistent inner spacing between cards. Also adds a simple placeholder marker in FoundationView when a foundation is empty (system "a" glyph, styled and non-interactive) so empty foundations have a subtle visual cue.
@austin-smith austin-smith changed the title Add FreeCell, variant-aware gameplay, and pixel card styling Add FreeCell variant Jul 4, 2026
@austin-smith
austin-smith marked this pull request as ready for review July 4, 2026 19:55
@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5da88a3f40

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ComputerSolitaire.xcodeproj/project.pbxproj
Comment thread ComputerSolitaire/Game/Shared/GamePersistence.swift
@austin-smith austin-smith linked an issue Jul 4, 2026 that may be closed by this pull request
@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@austin-smith
austin-smith merged commit 4beddae into main Jul 4, 2026
2 checks passed
@austin-smith
austin-smith deleted the freecell branch July 4, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FreeCell game variant

1 participant