Skip to content

Feature/connect four#31

Merged
boraaros merged 5 commits into
mainfrom
feature/connect-four
Mar 29, 2026
Merged

Feature/connect four#31
boraaros merged 5 commits into
mainfrom
feature/connect-four

Conversation

@boraaros

Copy link
Copy Markdown
Owner

No description provided.

New project: Alligator.ConnectFour — implements IPosition<Drop> and IRules<Position, Drop>

Features:

  - 7x6 board with discs dropped from top

  - Zobrist hashing for fast incremental position identification

  - Vertical/horizontal/diagonal win detection via last-move optimization

  - Heuristic evaluation: center preference + window-of-4 scoring

  - Move ordering: center columns yielded first

  - Cached Drop instances (only 7 objects, reused via Drop.At())

  - 8 unit tests: win detection (vertical/horizontal/diagonal), TakeBack, solver integration
… depth and improved evaluation

- Add Program.cs with human vs AI game loop (column input, colored board display)

- Add Configuration.cs with MaxDepth=13 (searches at depths 2,4,6,8,10,12)

- Make solver MaxDepth configurable via IConfiguration (default 7, backward compatible)

- Improve static evaluation: positional weight table (winning lines per cell),

  distance-based threat scoring, and double threat detection (+80 bonus)
The pure geometric weights (counting 4-in-a-row windows) gave higher scores to middle rows (2-3). This created a stacking penalty: playing center column let the opponent place on top for a higher-weighted cell (row 1 weight 10 > row 0 weight 7), making the AI avoid the center opening.

New formula: columnWeight[c] + (Rows - 1 - row), where columnWeight is the horizontal window count {3,4,5,7,5,4,3}. Center column remains dominant, but lower rows now always outweigh upper rows in the same column.
…spective

The solver's HeuristicValue + IsOpponentsTurn mechanism expects absolute values
(always from the same player's perspective), matching TreePosition and TicTacToe.
Connect Four's Evaluate() incorrectly returned values from the current player's
perspective, which caused NullWindowTest to produce negated minimax values and
BestNodeSearch to select the worst moves instead of the best.
@boraaros boraaros merged commit 3dbf3f3 into main Mar 29, 2026
1 check passed
@boraaros boraaros deleted the feature/connect-four branch March 29, 2026 20:40
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.

1 participant