Skip to content

Latest commit

 

History

History
266 lines (216 loc) · 8.61 KB

File metadata and controls

266 lines (216 loc) · 8.61 KB

Poker Training Games - Refactoring Progress

Date: 2025-09-09

Overview

Successfully refactored the poker training games from monolithic HTML/JavaScript files (~3700 lines each) into a modular TypeScript architecture with shared libraries and reusable components.

Completed Tasks

1. TypeScript Architecture Setup ✅

  • Created TypeScript configuration (tsconfig.json)
  • Set up build system with npm scripts
  • Configured ES modules for browser compatibility
  • Added proper type definitions for cards, games, and UI components

2. Shared Libraries Created ✅

Cards Library (src/lib/cards.ts)

  • Card parsing and validation
  • Deck generation and shuffling
  • Card rendering with configurable dimensions
  • Standard card dimensions: 85x120 pixels (updated from 70x100)
  • Seeded random shuffling support
  • Card formatting utilities

Poker Library (src/lib/poker.ts)

  • Basic hand evaluation
  • Hand ranking comparisons
  • Board texture analysis
  • Helper functions (getPairs, getThreeOfAKinds, etc.)

Pokersolver Integration (src/lib/pokersolver-wrapper.ts)

  • Wrapper for professional-grade poker evaluation
  • Uses pokersolver library from CDN
  • Accurate hand comparison with kickers
  • Best hand selection from 7 cards
  • Handles all edge cases (wheel straights, etc.)

Random Library (src/lib/random.ts)

  • Mulberry32 seeded random number generator
  • Hourly seed generation for consistent games
  • Array shuffling utilities
  • Random element selection

Storage Library (src/lib/storage.ts)

  • LocalStorage wrapper with error handling
  • High score management
  • Game settings persistence
  • Progress tracking
  • Achievement system support

3. Reusable UI Components ✅

Modal Component (src/components/Modal.ts)

  • Configurable modal dialogs
  • Alert and confirm helpers
  • Backdrop and ESC key support
  • Custom button configuration
  • Proper styling and animations

Timer Component (src/components/Timer.ts)

  • Countdown timer with pause/resume
  • Visual warning states
  • Smooth decimal display (fixed from whole seconds)
  • Click to pause functionality
  • Multiple display formats (seconds, mm:ss)

ScoreDisplay Component (src/components/ScoreDisplay.ts)

  • Score tracking display
  • Streak counter
  • Accuracy percentage
  • Fixed initialization bug where content wasn't rendered

4. Base Game Class (src/games/BaseGame.ts)

  • Abstract base class for all games
  • Handles game lifecycle
  • Score and streak management
  • Timer integration
  • High score saving
  • Seeded random support

5. Foundation Games Migrated ✅

Name That Hand (src/games/foundation/NameThatHand.ts)

  • Identify poker hands from 5 cards
  • 30 rounds with even distribution
  • Uses shared components

Hand vs Hand (src/games/foundation/HandVsHand.ts)

  • Compare two poker hands
  • Uses pokersolver for accurate comparison
  • Fixed: Visual feedback showing correct/incorrect answers
  • Fixed: Card size increased to 90x130 pixels
  • Fixed: No more false ties - proper kicker evaluation

Best Five from Seven (src/games/foundation/BestFiveFromSeven.ts)

  • Select best 5-card hand from 7 cards
  • Uses pokersolver for accurate evaluation
  • Fixed: Now finds actual best hand correctly
  • Fixed: Card size increased to 85x120 pixels
  • Card selection with visual feedback

6. Advanced Game Sample (src/games/advanced/TheNuts.ts)

  • Sample migration of The Nuts game
  • 3-level difficulty system
  • Uses default card dimensions from library

7. Test Infrastructure ✅

  • test-new-architecture.html - Comprehensive test page
  • Tests all libraries and components
  • Includes game demos
  • Pokersolver loaded from CDN

8. Development Setup ✅

  • Local development server (serve.js)
  • Resolves CORS issues for ES modules
  • npm scripts for build and serve
  • GitHub Actions workflow ready

Key Fixes Applied

  1. CORS Issues: Created local dev server to serve ES modules
  2. Import Paths: Added .js extensions for ES module compatibility
  3. Timer Display: Fixed to show smooth decimal countdown
  4. Modal Styling: Fixed positioning to appear as proper overlay
  5. Score Display: Fixed initialization to show content
  6. Hand Comparison: Integrated pokersolver for accurate evaluation
  7. Card Sizes: Standardized at 85x120 pixels across all games
  8. Best Hand Selection: Fixed to use pokersolver's accurate evaluation

File Structure

/src
  /lib
    - cards.ts (Card utilities)
    - poker.ts (Basic poker logic)
    - pokersolver-wrapper.ts (Professional evaluation)
    - random.ts (Seeded random)
    - storage.ts (LocalStorage wrapper)
  /components
    - Modal.ts
    - Timer.ts
    - ScoreDisplay.ts
  /games
    - BaseGame.ts
    /foundation
      - NameThatHand.ts
      - HandVsHand.ts
      - BestFiveFromSeven.ts
    /advanced
      - TheNuts.ts
  /types
    - cards.d.ts
    - games.d.ts
    - ui.d.ts

Dependencies

  • TypeScript 5.7.2
  • pokersolver 2.1.4 (loaded from CDN)
  • No other runtime dependencies

Testing

Run locally with:

npm install
npm run build
npm run serve

Then open: http://localhost:8000/test-new-architecture.html

Completed (2025-09-09)

The Nuts game migration: Full pokersolver integration completed

  • Updated to use findTheNutsWithSolver for accurate nuts finding
  • Improved generateDecoyHand with strategic hand selection based on target strength
  • Added estimateHandStrength for better decoy generation
  • Removed unused imports and cleaned up code

Production build script: Created build-production.js

  • Generates static HTML files for deployment
  • Copies compiled JavaScript from dist/
  • Creates foundation-new.html and the-nuts-new.html with new architecture
  • Preserves existing files for comparison

Updated main index: Created index-new.html

  • Modern, responsive design with game cards
  • Shows all 4 difficulty levels (2 active, 2 coming soon)
  • Links to refactored games using new architecture
  • Maintains Poker Power branding colors

Deployment Setup (2025-09-09 - Continued)

Production build process: Enhanced and tested

  • Added build:production npm script for one-command building
  • Tested production builds work correctly without dev server
  • Both foundation games and The Nuts game function properly in production

GitHub Actions workflow: Updated for automatic deployment

  • Modified .github/workflows/deploy.yml to use production build
  • Builds TypeScript then generates production HTML files
  • Deploys the production/ directory to GitHub Pages
  • Ready for automatic deployment on push to main branch

Single Page Application Implementation (2025-09-09 - Latest)

Minimal SPA Router: Created lightweight routing solution

  • Implemented src/lib/router.ts with History API support
  • Hash-based routing fallback for GitHub Pages (#/route)
  • Automatic state persistence with sessionStorage
  • Clean URLs and proper back button behavior
  • Only ~150 lines of code - truly minimal

Game Lifecycle Interface: Added to BaseGame

  • mount(container, state?) - Initialize and render game
  • unmount() - Clean up resources
  • serialize() - Save current game state
  • deserialize(state) - Restore saved state
  • All games now support refresh and navigation

Single Page Shell: Created index-spa.html

  • Home page with game selection grid
  • Foundation games menu with sub-navigation
  • Automatic game state restoration on refresh
  • Clean, modern UI matching existing design
  • Works with existing TypeScript game modules

Key Benefits of SPA Approach

  1. Refresh Support: Game state persists across page refreshes
  2. Back Button Works: Natural browser navigation between games
  3. Clean URLs: #/foundation, #/the-nuts for bookmarking
  4. No Server Config: Hash routing works on GitHub Pages
  5. AI-Friendly: Simple vanilla TypeScript, no framework

Testing the SPA

Visit http://localhost:8000/index-spa.html to test:

  • Navigate between games
  • Refresh mid-game (state preserved)
  • Use back/forward buttons
  • Bookmark specific games

Next Steps

  1. ✅ Test all refactored games thoroughly - COMPLETED
  2. ✅ Prepare GitHub Pages deployment - COMPLETED
  3. ✅ Implement SPA with router - COMPLETED
  4. Test SPA thoroughly and fix any issues
  5. Migrate to SPA as primary interface
  6. Push to GitHub and verify deployment
  7. Migrate remaining games (beginner and intermediate levels)
  8. Remove old architecture files once stable

Notes

  • All games now use professional-grade poker evaluation via pokersolver
  • Consistent card rendering across all games
  • Modular architecture makes adding new games easy
  • TypeScript provides type safety and better IDE support
  • Shared libraries eliminate code duplication
  • Component-based UI enables reuse across games