AI Heuristics & Decision Tree Design
Inside the logic of Pinpoint's single-player bot engine and decision heuristics
Introduction to Board Game AI
Developing a computer opponent for Pinpoint presents a unique challenge in game design: it is a game of perfect information but stochastic input. While players can see the entire state of the board, the hand replenishment mechanism introduces randomized elements.
Unlike chess where search trees can be calculated deterministically, a Pinpoint AI must calculate decisions based on expected value models while adapting its strategy based on the current difficulty level.
Minimax Search and Decision Trees
At the core of the Hard and Expert Pinpoint bots is a modified Minimax algorithm. The algorithm treats the board state as a node tree. The bot simulates its own moves (maximizing node values) and predicts human responses (minimizing node values).
Because the game has a high branching factor—especially in the early game where over 80 cells are empty—we implement Alpha-Beta Pruning to discard sub-trees that are guaranteed to yield suboptimal results, maintaining performance on both mobile and web platforms.
function minimax(node, depth, alpha, beta, maximizingPlayer) {
if (depth === 0 || isBoardFull(node)) {
return evaluateBoardState(node);
}
if (maximizingPlayer) {
let maxEval = -Infinity;
for (let move of getLegalMoves(node)) {
let child = applyMove(node, move);
let evaluation = minimax(child, depth - 1, alpha, beta, false);
maxEval = Math.max(maxEval, evaluation);
alpha = Math.max(alpha, evaluation);
if (beta <= alpha) break; // Prune branch
}
return maxEval;
} else {
let minEval = Infinity;
for (let move of getLegalMoves(node)) {
let child = applyMove(node, move);
let evaluation = minimax(child, depth - 1, alpha, beta, true);
minEval = Math.min(minEval, evaluation);
beta = Math.min(beta, evaluation);
if (beta <= alpha) break; // Prune branch
}
return minEval;
}
}
The Heuristic Evaluation Function
The heart of the AI bot is its evaluation function: evaluateBoardState(). This converts a static board configuration into a single numerical score representing the bot's advantage. The heuristic score is calculated as the sum of several weighted components:
1. Pattern Vector Analysis
The AI scans the board for alignment vectors in all four directions (horizontal, vertical, and both diagonals). It awards points based on the completeness of patterns:
- 2-in-a-row: 2 points (low priority)
- 3-in-a-row: 8 points (potential setup)
- 4-in-a-row: 25 points (high threat, triggers immediate block if held by opponent)
- 5-in-a-row: 75 points (critical state, ready to transition to reversal)
- 6-in-a-row (Reversal): 150 points (massive advantage, triggers board state reset)
2. Center Quadrant Modifiers
Because cells centered on section boundaries and quadrant intersections double the value of squares and crosses, the AI increases the positional score of pins placed in these coordinate zones. Placing a pin adjacent to a quadrant center receives a positional bonus of +15, encouraging the bot to fight for central dominance early in the match.
3. Joker Conservation Policy
Joker pins are the most valuable resource in Pinpoint. The AI uses a conservation threshold: it will not play a Joker unless the evaluation function determines that the placement will complete a pattern yielding at least 8 points, or block an opponent's 4-in-a-row that is guaranteed to score on their next turn.
Multiplayer Heuristics: In 3-player and 4-player games, the AI adjusts its weight parameters dynamically. If one opponent is leading by more than 15 points, the AI shifts its w_d (defensive weight) focus to block that specific player, mimicking human political behavior in multiplayer strategy games.
Balancing the Difficulty Levels
To provide a satisfying experience for players of all skill levels, we deliberately modify the AI's heuristic limits:
- Easy Mode: The search depth is set to 0. The bot simply selects a random legal move from its hand, simulating a player learning the interface. It utilizes Jokers randomly when they appear in hand.
- Medium Mode: Search depth is set to 1. The bot evaluates the board purely based on immediate points gained (greedy strategy) and performs basic single-turn blocking when an opponent has 3-in-a-row.
- Hard Mode: Search depth is set to 2. The bot uses minimax search, coordinates quadrant center attacks, actively blocks 4-in-a-row patterns, and conserves Jokers for high-value scoring turns.
- Expert Mode: Search depth is set to 3. The bot calculates expected value matrices of future player hands, sets up double-threat traps (where two scoring patterns share a completing coordinate), and optimizes 6-line reversals to flip board control.