-
Notifications
You must be signed in to change notification settings - Fork 0
Fix AI vertical threat detection blind spot on center columns #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e001d5b
7479728
55cb8c3
fadb94d
bbbb83e
36dfc35
95fb9b6
7daf046
7b8c324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,8 @@ | ||||||
| // constants | ||||||
| const TOTAL_COLUMNS = 7; | ||||||
| const TOTAL_ROWS = 7; | ||||||
| const HUMAN_WIN_SCORE = -4; | ||||||
| const COMPUTER_WIN_SCORE = 4; | ||||||
| const HUMAN_WIN_SCORE = -1000000; | ||||||
| const COMPUTER_WIN_SCORE = 1000000; | ||||||
| const NO_WIN_SCORE = 0; | ||||||
|
|
||||||
| // Transposition Table constants | ||||||
|
|
@@ -55,6 +55,17 @@ const OPENING_BOOK = { | |||||
| // Block 3-stacks on edges | ||||||
| '010111': 0, // Block left edge 3-stack | ||||||
| '616161': 6, // Block right edge 3-stack | ||||||
|
|
||||||
| // Vertical stacking defense (any column) | ||||||
| '4142': 4, // Block column 4 stack | ||||||
| '414241': 4, // Continue blocking column 4 | ||||||
| '2122': 2, // Block column 2 stack | ||||||
| '5152': 5, // Block column 5 stack | ||||||
|
|
||||||
| // Human stacks center - AI contests by stacking same column | ||||||
| '3132': 3, // Contest center column | ||||||
|
||||||
| '3132': 3, // Contest center column |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening book has duplicate key '313231' on lines 42 and 67. Both entries map to column 3 but are listed under different comment sections. This duplication is unnecessary and makes the opening book harder to maintain. Consider removing one of these duplicate entries.
| '313231': 3, // Continue center control |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening book entry '31323132': 3 on line 68 represents a sequence where human and AI alternate playing column 3 four times. However, this is an 8-character key representing 4 moves, which means it would only be consulted after move 4. But looking at the pattern: after '3132' (line 30/66), AI plays 3. Then if human plays 3 again, the board key is '313231', and the book says AI plays 3 (line 42/67). Then if human plays 3 again, the key would be '31323132', which is this entry. However, at this point, the column would likely be getting full (4 pieces in a 7-row board), and this represents a very specific scenario. Consider whether this entry adds value or if the search would handle this adequately.
| '31323132': 3, // Keep stacking center |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable opponent.
| const opponent = player === 1 ? 2 : 1; |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "prefer slower human wins (delay loss)" but the actual effect is achieved by adding recursionsRemaining to HUMAN_WIN_SCORE, which makes shallower human wins more negative (worse from AI's perspective). The comment is correct in intent but could be clearer. Consider rephrasing to: "Make immediate human wins worse (more negative) so AI prefers positions where losses are delayed".
| score = score + recursionsRemaining; // Prefer slower human wins (delay loss) | |
| score = score + recursionsRemaining; // Make immediate human wins worse (more negative) so AI prefers positions where losses are delayed |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tie-breaking logic compares childNodes[col].score with bestScore, but these scores are from different perspectives. The childNodes[col].score contains the score from the child node's perspective (set by recursive think() calls), while bestScore contains the negated score from the parent's perspective (computed as -childNode.score at line 1163). This comparison will not correctly identify tied moves. Consider storing the computed scores in a separate array during the search loop, or tracking which moves achieved the best score using a different mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening book entry '414241': 4 represents a game sequence where AI plays column 4 in response to human's first move on column 4. However, the opening book already defines that when human plays column 4 first ('41'), AI should respond with column 3 (line 27). This means the sequence '414241' would never occur if the AI follows its own opening book, making this entry unreachable dead code. Similar logic applies to entries '2122' and '5152' on lines 62-63.