Skip to content
CS 233 // Spimbot
Pages

Trails and territory

When the bot's center enters a tile, the first matching rule applies:

  1. One of the newest 3 tiles of the bot's own trail: nothing happens, so a bot can turn back through the head of its trail.
  2. An older tile of the bot's own trail: the trail is canceled with HIT_OWN_TRAIL.
  3. A tile of the opponent's trail: the opponent's trail is canceled with SMUDGED, and the rules below apply to the tile.
  4. The bot's own territory: the bot's trail, if it has one, completes.
  5. An unowned tile or the opponent's territory: the tile joins the bot's trail and costs 1 paint. With no paint left, the bot is canceled with OUT_OF_PAINT, with or without a trail.

Completing a trail

#
Red drives up from its base in the upper left, then left, down and right, leaving a trail of light red tiles behind it. When it drives back into its base, the trail and the area it enclosed turn dark red: they are now red's territory.

When a trail completes, three steps run in order:

  1. Claim: every trail tile becomes the bot's territory, and so does every tile that the bot's territory now cuts off from the map edge, the opponent's territory included.
  2. Release: the opponent loses every tile of its territory that has no path to its base through its own territory, moving up, down, left or right. Those tiles become unowned. If the opponent loses any, it gets a TERRITORY_DISCONNECTED interrupt.
  3. Hole fill: the bot fills its holes, described below.

In the claim:

  • A path to the edge can cross any tile the bot does not own, walls included, so walls never help enclose an area.
  • Only tiles that this completion newly cuts off are claimed. The opponent's territory inside an area the bot had already enclosed stays the opponent's.
  • A base never changes owner, and a claimed tile under the opponent's trail keeps that trail.

A hole is an unowned tile, other than a wall, that has no path to the map edge except through the bot's territory. A hole becomes the bot's territory when it connects to the bot's base, moving up, down, left or right, through the bot's territory and other holes. A hole that walls cut off from the territory stays unowned.

Red territory surrounds blue's base, where a faint line marks each tile, with a block of blue territory to the right of the base. Red drives down the map's right edge, turns left, then drives up through the blue block, its light red trail leaving two blue tiles on the far side, cut off from blue's base. When the trail reaches red territory again, the trail and those two tiles turn red.

In this figure, red already owns the area around blue's base. Red's trail cuts two blue tiles off from blue's base, so blue loses them. They are then holes in red's territory, and red fills them.

LAST_CLAIMED_TILES then reads the tiles the completion gained: the trail, the enclosed tiles and the filled holes. In the figure it reads 4: the 2 trail tiles and the 2 filled holes.

Cancellation

#
Red drives up from its base in the upper left, then left, down and right, back into its own trail. The trail disappears, and red is back at the center of its base, stopped and still facing right.

When a bot is canceled:

  • It loses its trail. The trail's tiles keep their owners, and the paint spent on them is gone.
  • It returns to the center of its base with velocity 0, keeping its heading.
  • TRAIL_CANCELLED is raised, and LAST_TRAIL_CANCEL_REASON reads the latest reason.
Code Name Cause
0 NONE No cancellation yet
1 OUT_OF_PAINT The bot entered a tile that needed paint with none left
2 HIT_OWN_TRAIL The bot drove into its own trail behind the newest 3 tiles
3 SMUDGED The opponent drove through the trail
4 COLLISION The bots collided while this bot had a trail
5 FILLED_OVER The opponent's claim took or cut off the tile the trail started from or, for a bot without a trail, the tile it stands on