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.
- 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
- 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
- Basic hand evaluation
- Hand ranking comparisons
- Board texture analysis
- Helper functions (getPairs, getThreeOfAKinds, etc.)
- 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.)
- Mulberry32 seeded random number generator
- Hourly seed generation for consistent games
- Array shuffling utilities
- Random element selection
- LocalStorage wrapper with error handling
- High score management
- Game settings persistence
- Progress tracking
- Achievement system support
- Configurable modal dialogs
- Alert and confirm helpers
- Backdrop and ESC key support
- Custom button configuration
- Proper styling and animations
- 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)
- Score tracking display
- Streak counter
- Accuracy percentage
- Fixed initialization bug where content wasn't rendered
- Abstract base class for all games
- Handles game lifecycle
- Score and streak management
- Timer integration
- High score saving
- Seeded random support
- Identify poker hands from 5 cards
- 30 rounds with even distribution
- Uses shared components
- 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
- 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
- Sample migration of The Nuts game
- 3-level difficulty system
- Uses default card dimensions from library
test-new-architecture.html- Comprehensive test page- Tests all libraries and components
- Includes game demos
- Pokersolver loaded from CDN
- Local development server (
serve.js) - Resolves CORS issues for ES modules
- npm scripts for build and serve
- GitHub Actions workflow ready
- CORS Issues: Created local dev server to serve ES modules
- Import Paths: Added .js extensions for ES module compatibility
- Timer Display: Fixed to show smooth decimal countdown
- Modal Styling: Fixed positioning to appear as proper overlay
- Score Display: Fixed initialization to show content
- Hand Comparison: Integrated pokersolver for accurate evaluation
- Card Sizes: Standardized at 85x120 pixels across all games
- Best Hand Selection: Fixed to use pokersolver's accurate evaluation
/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
- TypeScript 5.7.2
- pokersolver 2.1.4 (loaded from CDN)
- No other runtime dependencies
Run locally with:
npm install
npm run build
npm run serveThen open: http://localhost:8000/test-new-architecture.html
✅ The Nuts game migration: Full pokersolver integration completed
- Updated to use
findTheNutsWithSolverfor accurate nuts finding - Improved
generateDecoyHandwith strategic hand selection based on target strength - Added
estimateHandStrengthfor 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.htmlandthe-nuts-new.htmlwith 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
✅ Production build process: Enhanced and tested
- Added
build:productionnpm 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.ymlto 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
✅ Minimal SPA Router: Created lightweight routing solution
- Implemented
src/lib/router.tswith 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 gameunmount()- Clean up resourcesserialize()- Save current game statedeserialize(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
- Refresh Support: Game state persists across page refreshes
- Back Button Works: Natural browser navigation between games
- Clean URLs:
#/foundation,#/the-nutsfor bookmarking - No Server Config: Hash routing works on GitHub Pages
- AI-Friendly: Simple vanilla TypeScript, no framework
Visit http://localhost:8000/index-spa.html to test:
- Navigate between games
- Refresh mid-game (state preserved)
- Use back/forward buttons
- Bookmark specific games
- ✅ Test all refactored games thoroughly - COMPLETED
- ✅ Prepare GitHub Pages deployment - COMPLETED
- ✅ Implement SPA with router - COMPLETED
- Test SPA thoroughly and fix any issues
- Migrate to SPA as primary interface
- Push to GitHub and verify deployment
- Migrate remaining games (beginner and intermediate levels)
- Remove old architecture files once stable
- 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