How yahel150/nimgame works
NimGame is a browser-based Nim game for human-vs-computer or same-device play. The user chooses an opponent, a preset or custom variant, and a piece style; the browser then renders the board and sends selections and confirmed moves to the WebAssembly game engine. The engine manages sessions, validates rules, applies moves, and chooses computer moves; the browser displays the resulting state and outcome. The README documents misère, poisoned-pile, take-away, and custom games. The excerpts show the browser/Wasm boundary and core engine logic, but not the Wasm bindings, so that connection is shown only at the boundary.
Main entry points: game_service.cpp Session service · app.js Game interface · rules.cpp Move rules · strategies.cpp Computer strategy
Components 10
Browser experience
- Game interface
src/web/app.js - Piece imagery
assets/images
Game engine
- Session service
src/engine/game_service.cpp - Game configuration
src/engine/game_config.cpp - Game state
src/engine/game_state.cpp - Undo history
src/engine/history.cpp - JSON serialization
src/engine/serialization.cpp
Rules and strategy
- Move rules
src/engine/rules.cpp - Computer strategy
src/engine/strategies.cpp
Other components
- Player
Connections 10
- Player → Game interface: chooses and plays
- Game interface → Session service: requests via Wasm
- Game interface → Piece imagery: loads piece art
- Session service → Game configuration: builds preset config
- Session service → Game state: creates and updates
- Session service → Undo history: records and restores
- Session service → Move rules: validates and applies
- Session service → Computer strategy: requests computer move
- Move rules → Computer strategy: checks winning position
- Session service → JSON serialization