Loading repository data…
Loading repository data…
hyperstellar8848 / repository
This project implements a three-player Ludo game in Python where one human player competes against two AI-controlled players. The artificial intelligence of the bots is developed using the Minimax algorithm and Alpha-Beta Pruning. Developed as an AI Course Project at NIT.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This version of Ludo contains structured positional rules to guarantee deterministic movement calculation for AI search depths:
0 to 49. All players circulate on this track.Tile 0 $\rightarrow$ Exits at Tile 49Tile 16 $\rightarrow$ Exits at Tile 15Tile 32 $\rightarrow$ Exits at Tile 3150 and 51 are individual, safe pipelines extending past the common track layout. Opponents cannot enter these zones.Tile 52 represents the end of the game path. Once a piece lands exactly on Tile 52, its status transitions to "GOAL". It locks permanently and cannot be moved or targeted again.1, 2, 3.YARD. A player must roll a precise value of 6 to move a piece out of the yard and deploy it to their designated starting tile.0-49) currently occupied by an opposing token, a Capture triggers. The opposing token has its status reset back to YARD, and its relative step tracking is reset to zero.Tile 52).Multiplayer board games do not fit classic zero-sum two-player matrix designs. This engine implements an adapted framework for multi-agent optimization:
Instead of returning a single integer value (where a high number helps one side and a low number helps the other), our evaluation function returns a 3-element vector of utilities:
$$U = [U_{\text{human}}, U_{\text{AI1}}, U_{\text{AI2}}]$$
During a simulated search tree layer, the player whose turn it is calculates moves aiming solely to maximize their own index in that utility vector, operating under the assumption that subsequent opposing nodes will optimize their own respective metrics.
The Pure Minimax engine in this project evaluates moves by building a lookahead tree of depth 3 ($D=3$). It assumes that every player is perfectly rational and will choose moves that yield the best possible outcome for themselves.
AI_1's turn at Layer 0, the engine simulates AI_2's best responses at Layer 1, and the Human's best counters at Layer 2.evaluate_state() function. This calculates a static vector score for that specific board arrangement.AI_1's turn, it scans all child branches and picks the move that results in the highest value for index 1 ($U_{\text{AI1}}$).AI_2's turn, it picks the move that results in the highest value for index 2 ($U_{\text{AI2}}$).Alpha-Beta Pruning is an optimization layer built over the Minimax engine. Its sole purpose is to skip calculating branches that are mathematically proven to be useless to the players, saving immense amounts of CPU work.
if beta >= alpha and alpha != -float('inf') and beta != -float('inf'):
break # Pruning happens here
Once this condition triggers, the loop immediately terminates (break). The engine completely throws away the rest of that branch's sub-tree, refusing to waste time deep-copying states or calculating lookaheads for moves that will never be chosen in real gameplay.
Eval)The static estimation weight calculates structural advantages for individual states:
GOAL (Tile 52).To solve the issue of randomized dice rolls skewing algorithm metrics, the script contains a Side-by-Side Algorithm Comparison Mode. "Activate Side-by-Side Algorithm Comparison Mode? (y/n): y"
Seed 42) locks the dice array sequence, ensuring that restarting or running tests repeats the exact same sequence of dice rolls.Below is an empirical analysis compiled from runtime testing configurations utilizing a lookahead depth limit of 3 layers ($D=3$). The scenarios evaluate three distinct phases of a live match under a locked seed:
| Test Case Scenario | Metric Evaluated | Pure Minimax Engine | Alpha-Beta Pruning Engine | Efficiency Improvement (%) |
|---|---|---|---|---|
| Test Case 1: Early Game (Most tokens in Yard; few choices) | • Nodes Explored • Computational Time | 142 nodes 0.002812 s | 84 nodes 0.001610 s | 40.8% fewer nodes |
| Test Case 2: Mid-Game Climax (Multiple tokens fighting on Track) | • Nodes Explored • Computational Time | 912 nodes 0.018940 s | 224 nodes 0.004210 s | 75.4% fewer nodes |
| Test Case 3: Late Game (Tokens near Home/Goal 52 columns) | • Nodes Explored • Computational Time | 644 nodes 0.013110 s | 152 nodes 0.003020 s | 76.4% fewer nodes |
| Global Averages (Calculated across entire match) | • Nodes Explored • Decision Latency | ~650 nodes 0.012500 s | ~180 nodes 0.003100 s | ~72.3% Average Pruning |
The Alpha-Beta Pruning variant clearly outperformed the standard Pure Minimax algorithm across every test case environment.