BitSnake takes an adversarial twist on the classic Snake game, transforming it into a multi‑agent arena where intelligent pathfinding meets survival dynamics. Unlike the solitary challenge of traditional Snake, BitSnake was designed as an environment where multiple autonomous agents interact within a shared space, constantly negotiating survival, growth, and competition. Inspired by earlier projects in adversarial search, this game was an attempt to create an experimental testbed of adjustable complexity—an arena where deterministic mechanics intersect with randomness and uncertainty, forcing agents to make rapid decisions not only against the static environment but also against unpredictable competitors. The result is an ecosystem where strategies evolve, mistakes are punished immediately, and even simple algorithms take on the appearance of cunning adversaries.
Beyond Classic Snake
Moving beyond perfect‑information, turn‑based games like Connect 4 and Gomoku, where outcomes are deterministic and the limits of the game tree can be mapped and searched exhaustively, Snake offered a compelling alternative: it is sequential and inherently fragile—one mistake often means instant death. By adding multiple agents and injecting live randomness into the environment, BitSnake became the perfect playground to explore how classical algorithms, heuristic pathfinders, and learning‑based agents adapt when survival depends on simultaneous choices made under uncertainty. The goal was to study not only which strategies win, but also how rules of vitality and mortality shape the behaviour of agents in a competitive ecosystem. To simulate non-deterministic decision-making under imperfect information, this project focuses on observing the performance of a neural agent against established algorithmic pathfinders.
Inside the Arena
The environment is governed by a shared global state. At every tick, all agents receive the exact same snapshot of the board and must act simultaneously. This ensures fairness—no agent sees into the future—but it also highlights how strategies diverge when each agent interprets the same state through a different lens.
-
Game Modes:
- Round‑based mode: All agents spawn at the start and compete until a single survivor remains, producing clear end‑game dynamics where long‑term planning matters.
- Live‑spawn mode: New agents can be introduced mid‑game, allowing continuous play and testing adaptability of strategies as the ecosystem evolves in unpredictable ways.
-
Life & Vitality Rules:
- Each snake’s body confers vitality points, essentially treating size as both an asset and a liability.
- Occupied cells add to life, but every movement consumes energy, introducing a built‑in decay process.
- Eating food replenishes vitality and extends the body, while senescence gradually erodes it, forcing snakes to remain active.
- These rules create an ongoing tension: expand too quickly and you may trap yourself; conserve too long and you may wither away. The balance between growth and sustainability becomes central to survival.
-
Agents:
- BFS Agent — greedily seeks the shortest path to food, embodying a naïve but effective survival instinct. It thrives in the short term but often dies young.
- A Agent* — balances path length with safety heuristics, preferring secure routes over reckless lunges. This agent tends to outlast greedy ones but may struggle to seize opportunities quickly.
- Neural Net Agent — trained on board states, it can operate under conditions of imperfect observability, in contrast to its deterministic peers. This introduces the possibility of learned nuance and behaviours that surprise even the designer.
-
Backend Architecture:
- Implemented in Java, structured around MVC principles.
- Agents run as independent threads but share a single authoritative game state, ensuring synchrony and preventing desynchronization errors.
- A Pub/Sub WebSocket layer streams tick‑by‑tick state updates to the client for smooth real‑time rendering.
- Snake creation leverages a factory pattern, allowing users to add new snakes on the fly during play, expanding the dynamics of the ecosystem instantly.
-
Randomness vs Determinism:
- The core rules of movement, collision, and growth are deterministic, meaning identical states with identical decisions yield identical outcomes.
- Randomness enters through food spawning (positions generated stochastically) and optional partial observability, which blinds agents to parts of the board.
- This blend creates strategic uncertainty, akin to competitive multi‑agent RL environments, where survival depends not only on good planning but also on hedging against incomplete knowledge.
-
Collision Handling:
- At each tick, all agents submit their intended moves simultaneously.
- The backend then applies these moves atomically, resolving conflicts fairly without race conditions.
- Collisions with walls, with other snakes, or with oneself result in instant elimination, forcing agents to weigh aggression against self‑preservation.
- The resolution system ensures no agent benefits unfairly from timing, emphasizing pure strategy over execution speed.
Emergent Behaviour
(Detailed behavioural analysis to be added once further experiments are complete.)
Even without finalized testing, the design makes clear that BitSnake can generate diverse emergent behaviours. Greedy agents often grow quickly but collide early. Heuristic agents survive longer by avoiding risk but may miss critical food opportunities. Neural agents, given partial observability, introduce unpredictability that reshapes how other agents must respond. Watching these interactions unfold feels less like programming rules and more like observing an ecosystem in motion.
Expanding the Horizon
- Richer Agent Pools: Introduce Reinforcement Learning methods such as Q‑Learning, Policy Gradients, or Actor‑Critic models to see how long‑term training changes survival dynamics.
- Complex Maps: Add hierarchical environments with walls, shifting corridors, and dynamic hazards that transform safe paths into death traps over time.
- Human‑in‑the‑Loop: Allow users to assume control of a snake mid‑game, pitting human adaptability against machine efficiency.
- Distributed Play: Scale the backend to support multiple clients across a network, enabling large‑scale, persistent ecosystems of snakes.
- Biological Inspirations: Extend the life rules with mechanics such as metabolism rates, reproductive splitting, or mutation of strategies over time.
Reflections
BitSnake was a step toward environments that mirror the real world more closely: uncertain, multi‑agent, and constantly in flux. It challenged me to think not just about algorithms in isolation but about systems in which rules, randomness, and agents interact to produce behaviours greater than the sum of their parts. In that way, it prepared me for tackling problems beyond games—systems where prediction, adaptation, and survival are tightly interwoven.
