Emergent Behavior Sim
A Tron-style bot for the Case Closed datathon. It plays on a wrap-around grid and wins with layered spatial heuristics, no machine learning.
The game
Two players move around an 18×20 board whose edges wrap around, each leaving a permanent trail. Touch any trail and you're out. Head-on collisions go to the longer trail, and each player gets three boosts that allow a double move. A match lasts 500 turns or until someone crashes. My agent, UltraHeuristicAgent, runs as a Flask service that the judge engine asks for a move every turn.
The project name comes from how it plays. There's no trained model, just a handful of local rules about space, distance, and risk, but together they produce something that looks like strategy: expanding, pressuring, and sealing the opponent off.
Controlling space
Every move is scored by score_move(), mostly on how much space it leaves me:
- Flood fill (capped at 240 cells) measures how much of the board each player can still reach after a candidate move.
- Comparing my reachable area to the opponent's gives a space-advantage ratio,
(my_space − opp_space) / total, which shifts the bot between attacking and surviving.
In a Tron endgame, whoever controls more area usually wins, so that comes first and everything else adjusts it.
Trapping
The bot also models the opponent. evaluate_trap() estimates how much the opponent's space shrinks if I move into a given cell. evaluate_self_trap_potential() and should_self_trap() handle a move that sounds backwards: sealing myself into a region on purpose. That only makes sense when I'm more than 15% ahead on space and more than 5 cells from the opponent, and then it turns a space lead into a guaranteed win.
Pressure and lookahead
- Distance is Manhattan distance on the wrapped board.
- When more than 15% ahead on space, it closes to about 4 cells to apply pressure. When behind, it stays about 6 cells away and plays for territory.
- It watches how the opponent's distance changed over the last five moves to judge how aggressive it is.
lookahead_quality()simulates three moves ahead, rewarding branches with several escape routes and penalizing dead ends (−80) and one-way paths (−15).
Openings, boosts, and fallbacks
It opens with a short book of safe seven-move expansions for the two known spawn points, then hands off to the heuristics. Boosts are spent by rule:
- Emergency escape when few safe moves are left.
- Midgame catch-up (turns 40 to 200): a 35% chance to boost when more than 25% behind on space.
- After turn 360, use up whatever is left.
If scoring ever comes up empty, efficient_path_move() falls back to wall-following (right-hand rule, preferring paths with at least two safe cells ahead).
| phase | turns | behavior |
|---|---|---|
| Early | < 40 | Grab territory; opening book for known spawns |
| Midgame | 40–220 | Balance expanding and trapping; boost if behind >25% |
| Endgame | > 220 | Limit the opponent's options; boost when in danger |
Running it
Everything is Python behind a Flask server with the endpoints the judge expects (take the game state, return a direction, optionally with :BOOST). The repo includes a local judge and a sample opponent for practice matches, a compliance tester, and a Docker image for the competition sandbox (CPU only, under 5 GB).
Fernando Guzman