# Gomoku AI Player

## Beginner Level

### Limitations

- Heavy dependence on randomness causes inconsistent behavior.
- Threat detection is shallow. It only checks for basic three-stone segments.
- Does not recognize double threats or more complex tactical formations.
- Can still accidentally play a strong move because of `getSmartMoves`.



### Improvements

- Add a dedicated lightweight heuristic that avoids obviously losing moves.
- Restrict move pool further to increase predictability.
- Detect simple two-way threats so the AI can intentionally miss them to stay weak.
- Add cap on evaluating any potential strong attack patterns.

------

## Easy Level

### Limitations

- Checks for immediate wins and some patterns but has no long-term planning.
- Pattern recognition is inconsistent due to randomness.
- Does not assign priority levels to threats beyond basic fours or threes.
- Can be manipulated by forcing the AI into predictable 50 percent branches.

### Improvements

- Add basic detection for double-three or double-four threats.
- Make blocking more consistent by removing some randomness.
- Add simple pattern scoring instead of discrete condition checks only.
- Give preference to moves that discourage opponent expansion.

------

## Medium Level

### Limitations

- Uses minimax depth 3, which is still shallow for a 15x15 Gomoku board.
- Move count is high because `getSmartMoves` radius 2 often creates 30 to 60 moves.
- No advanced move ordering beyond evaluating position once.
- Transposition table entries can be overwritten with weak keys because the key combines `boardHash + depth + isMaximizing` as a string.
- Evaluation is expensive because all lines and diagonals are recalculated for every node.
- No iterative deepening, so no early-cut results if time is short.

### Improvements

- Introduce better move ordering using history heuristic or frequency updates.
- Reduce move pool:
  - Filter out moves that score below a threshold after initial evaluation.
  - Reduce radius from 2 to adaptive growth based on move density.
- Cache diagonal and line evaluations incrementally to avoid recomputation.
- Strengthen transposition table hashing using Zobrist hashing.
- Add time-based cutoff even for medium level so it never stalls.

------

## Hard Level

### Limitations

- Depth 4 is costly when game progression increases piece density.
- Suboptimal mode selects second or third best but still runs full minimax for scoring.
- Repeated evaluation of moves in move ordering increases time significantly.
- No parallelization, so deeper searches slow sharply.
- Transposition table does not differentiate between exact, upper-bound, lower-bound scores.

### Improvements

- Use fail-soft alpha beta to return better cutoffs.
- Implement Zobrist hashing to reduce hash collisions.
- Add PV-based move ordering that stores best-first move for each depth.
- Generate killer moves more effectively by tracking two killers per depth.
- Reduce branch factor by removing obviously losing defensive moves.
- Add aspiration windows around expected scores to reduce search space.

------

## Expert Level

### Limitations

- VCF detection is expensive and includes deep recursion with large move sets.
- Iterative deepening raises depth from 4 to 8 but without proper time-slicing.
- No dedicated threat space search. Expert engines use threat-space-only search for efficiency.
- Positional evaluation is not tuned for professional Gomoku patterns (43, 44, 33, etc.).
- Transposition table is global but does not age out old states, so it bloats and slows down GC.

### Improvements

- Replace VCF brute force with threat-space search (TSS) and threat-sequence graphs.
- Use full iterative deepening with aspiration windows and time-splitting.
- Add more refined patterns such as double-four, overline penalties, and multiple-open-three structures.
- Add TT entry types: exact, fail-high, fail-low.
- Add aging or LRU eviction to transposition table.
- Integrate move probability models based on pattern priority (immediate wins, fours, open threes first).
- Optimize evaluatePosition by caching previously scanned lines and updating incrementally after each move.