fix: Prevent broken win configurations that guarantee Player 1 wins#12
Open
dhanjit wants to merge 1 commit into
Open
fix: Prevent broken win configurations that guarantee Player 1 wins#12dhanjit wants to merge 1 commit into
dhanjit wants to merge 1 commit into
Conversation
After running AI simulations, discovered that allowing K < N-1 creates broken game configurations where Player 1 has guaranteed wins. Simulation Results: - 5×5 with 3-in-a-row: Player 1 wins 100% in ~10 moves - 5×5 with 5-in-a-row: All games timeout (too defensive) - Player 1 can win during placement phase with small K values Changes: - Restrict win line length to K >= N-1 (minimum: max(3, N-1)) - Update UI dropdown to only show valid options - Update game.js validation with better error messages - Add "(Easier)" label to N-1 option in UI Affected Configurations: - 3×3 grid: Only 3-in-a-row allowed (no change) - 4×4 grid: Only 3-in-a-row or 4-in-a-row allowed - 5×5 grid: Only 4-in-a-row or 5-in-a-row allowed (removed 3-in-a-row) - 6×6 grid: Only 5-in-a-row or 6-in-a-row allowed - 7×7 grid: Only 6-in-a-row or 7-in-a-row allowed Tools Added: - tests/simulate-advantage.js: Measure first-player advantage via AI simulations - tests/quick-sim.js: Quick simulation with easy AI - tests/test-winnable.js: Test game winnability across configurations All 130 tests still passing with new validation.
1ef6b6c to
218c6ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Discovered via AI Simulations
Ran AI vs AI simulations to measure first-player advantage and discovered critical game-breaking configurations:
🚨 Broken Configuration Found:
5×5 grid with 3-in-a-row:
Root Cause:
When K < N-1, Player 1 can form K-in-a-row during the placement phase before Player 2 has a chance to defend.
Solution
Restrict win line length to K >= N-1 (minimum: max(3, N-1))
New Configuration Limits:
3-in-a-row, 4 or 5-in-a-row3-in-a-row,4-in-a-row, 5 or 6-in-a-row3/4/5-in-a-row, 6 or 7-in-a-rowChanges Made
UI (
web/index.html):Backend Validation (
web/js/game.js):Simulation Tools Added:
tests/simulate-advantage.js: Comprehensive AI simulation frameworktests/quick-sim.js: Quick simulation runnertests/test-winnable.js: Test game winnability across configurationsSimulation Data
Testing
✅ All 130 existing tests pass with new validation
✅ Invalid configurations now properly rejected
✅ UI prevents selection of broken configurations
Impact
Positive:
Neutral:
Related
This was discovered while investigating first-player advantage mitigation strategies (Pie Rule evaluation).