Skip to content

feat(1-3): Core Improvements - Phases 1-3 Complete#3

Open
nikhilachale wants to merge 2 commits into
mainfrom
feat/issue-1
Open

feat(1-3): Core Improvements - Phases 1-3 Complete#3
nikhilachale wants to merge 2 commits into
mainfrom
feat/issue-1

Conversation

@nikhilachale

Copy link
Copy Markdown
Owner

Summary

Comprehensive implementation of Phases 1-3 from issue #1 covering core correctness, multiplayer stability, and AI quality improvements.

Changes Made

Phase 1: Core Correctness

  • Castling Rules: Fixed castling to prevent moving out of, through, or into check
  • Insufficient Material: Added bishop color logic to detect same-color bishops as draws
  • Move Validation: Added authoritative move-legality validation in socket server
  • Promotion Support: Added full promotion piece choice (Q/R/B/N) across engine, socket, and UI

Phase 2: Multiplayer Stability

  • Player Identity: Validate player IDs (white/black only) and prevent spoofing
  • Room Cleanup: Implemented timeout-based cleanup (5 minutes) for inactive rooms
  • Reconnect Logic: Added exponential backoff retry (2s → 30s, max 10 attempts) with auto-rejoin
  • ChessStore: Updated with reconnection state management
  • Non-blocking Alerts: Replaced blocking alerts with error message banner

Phase 3: AI Quality

  • Opening Depth: Fixed to honor requested search depth instead of artificially limiting
  • Performance: Reduced cloning overhead in MoveEvaluator by eliminating per-piece game clones
  • Tests: Added comprehensive AI sanity checks for deterministic behavior

Tests Added

  • Game.test.ts: Castling edge cases, insufficient material, promotion
  • MoveEvaluator.test.ts: Consistency, checkmate avoidance, legal moves, deterministic scoring
  • index.test.ts: Socket message handling with mocked WebSocket

Success Criteria Met

  • ✅ All illegal moves rejected
  • ✅ Castling follows full rules
  • ✅ Promotion choices work across all layers
  • ✅ Room cleanup prevents memory leaks
  • ✅ Reconnect flow is reliable
  • ✅ AI uses requested search depth
  • ✅ Comprehensive test coverage for critical paths

Closes #1

nikhilachale and others added 2 commits April 8, 2026 14:44
- Fix castling rules: prevent castling out of, through, or into check
- Add bishop color logic to insufficient material detection
- Add move-legality validation in socket server
- Add promotion piece choice support (Q/R/B/N) in Game.ts
- Add promotion piece parameter to socket make_move handler
- Add promotion UI in game page with modal selector

All Phase 1 tasks completed. Castling now properly checks for king safety,
insufficient material draw detection handles same-color bishops, and players
can select promotion pieces when pawns reach the final rank.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Phase 2 - Multiplayer Stability:
- Validate player identity in socket handlers (white/black only, prevent spoofing)
- Add room cleanup lifecycle with 5-minute timeout for inactive rooms
- Add reconnect retry logic with exponential backoff (2s to 30s, 10 max attempts)
- Update chessStore with rejoining state and actions
- Replace blocking alerts with non-blocking error message banner

Phase 3 - AI Quality:
- Fix opening-depth behavior to honor requested search depth
- Reduce cloning overhead in MoveEvaluator (removed per-piece game clones)
- Add AI sanity checks in tests (deterministic behavior, legal moves only)

Tests:
- Game.test.ts: Castling edge cases, insufficient material, promotion
- MoveEvaluator.test.ts: Consistency, checkmate avoidance, legal moves, deterministic scoring
- index.test.ts: Socket message handling with mocked WebSocket

All Phase 2 and Phase 3 tasks completed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Core Improvements Roadmap: Move Validation, Stability, AI & UX

1 participant