mcts
mcts copied to clipboard
Modernize to TypeScript with zero-copy optimization
Major improvements:
- Converted from Flow to modern TypeScript 5.3 with super strict linting
- Removed inefficient deep cloning (_.cloneDeep) in favor of mutable game state with apply/undo moves
- Added comprehensive benchmark suite measuring moves per second
- Achieved ~450K moves/second average performance
Technical changes:
- Replaced lodash with native JavaScript methods where possible
- Implemented mutable state pattern: moves are applied when traversing down the tree and undone when backtracking
- Fixed critical bug where cached children weren't re-applying moves in subsequent simulations
- Added strict TypeScript compiler options (noUncheckedIndexedAccess, exactOptionalPropertyTypes, etc.)
- Configured ESLint with @typescript-eslint strict type checking
Performance:
- SingleCellGame: 943K moves/sec
- TwoCellGame: 505K moves/sec
- TicTacToe: 67K moves/sec (1K rounds), 69K moves/sec (10K rounds)
- SummingDice: 497K moves/sec
All tests passing with 100% win rate detection for optimal moves.