Skip to content

Instantly share code, notes, and snippets.

@wandernauta
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wandernauta/9748410 to your computer and use it in GitHub Desktop.
Save wandernauta/9748410 to your computer and use it in GitHub Desktop.
Life

It's life, Jim, but not as we know it

You probably know Conway's Game of Life, the famous cellular automaton invented by mathematician John Conway. Life is a set of rules that, together, allow you to simulate a two-dimensional board of cells. The rules decide which cells on the board live and which ones die. With some imagination, you could say that Life is a zero-player game: a game with the objective to find patterns with interesting behavior, like the famous glider.

Glider

A zero-player game... Until today. You are to write a program that plays the Game of Life - and plays it to win, while your opponent's program tries to do the same. The winner is either the last bot standing, or the player with the most live cells after 5 minutes of clock time.

Game rules

The rules are almost the same as normal (B3/S23) Life:

  • A live cell with fewer than two friendly neighbors dies from underpopulation.
  • A live cell with two or three friendly neighbors survives.
  • A live cell with more than two friendly neighbors dies from overpopulation).
  • A dead cell with exactly three neighbors of the same player comes alive to fight for that player if there are less than three enemy neighbors.

...but after each generation, both you and your opponent get the opportunity to intervene. You can awake up to a maximum of 32 cells to fight for you. (Who goes first is decided by the server.)

The board is a 1024 × 1024 cell square. All squares are initially dead. The borders do not wrap around (this is not a torus-shaped world) and are permanently dead.

This is is a contest in the spirit of Battlebots and Core Wars. However, unlike those two, you are supposed to run your implementation on your own machine. You fight the other contestants on a central arena server.

Protocol

The arena server speaks a simple TLV protocol over TCP. Messages have the following format:

tlvvvvvvv...
^ Type (1 byte, ASCII)
 ^ Length (1 byte, unsigned int)
  ^ Values (Exactly length bytes of UTF-8)

You're probably going to want to write a client. Here's how:

  1. Connect to the central arena server (host life.twnc.org, TCP port 1970).
  2. Send an Identification message with an identification string (up to 250 bytes of UTF-8).
  3. Have your bot wait for a game to begin. The arena hosts one game at a time. You will fight either another contestant's bot, or a training round against my entry, which is not included in the competition.
  4. The game starts when you receive a Start message. Included in the message is the name of your opponent, which will start with "wandernauta/" if you're up against the training bot.
  5. When you receive a Move, apply it to your board. Moves are encoded as arrays of pairs of 16-bit unsigned integers. For each pair, set the cell at that X/Y-coordinate to the enemy's 'color'.
  6. When you receive a Generation marker, evolve your current view of the game board one step according to the rules above.
  7. When you receive a Turn message, it's your turn. Reply with a Move as soon as possible. (Don't want to interfere? Send a Move message with zero moves.)
  8. When you receive a Bye message, the game is over and you can disconnect. The value will tell you your score and your opponent's, in that order, as a pair of 32-bit unsigned integers.
  9. Reconnect when you're ready for another round.

Note that the server will not send you the entire state of the board for bandwidth. You'll have to keep track of that yourself.

Competition rules:

  • You should Identify as *name*/*bot*, where name is your StackExchange user name and bot is a PG-rated but otherwise very intimidating name for your implementation (Glider of Doom? DiveBomber? Pufferfish?)
  • If your implementation fails to follow the protocol, you'll be disconnected - and the game will be forfeited.
  • You are not allowed to willfully take advantage of a fault in the arena server.
  • Have your AI decide on moves in a sane time. Calculate strategies in advance if at all possible so you'll be able to send your next move as fast as reasonably possible.
  • Finally, please be nice to the server. It's there for your enjoyment.
  • Not following these rules can lead to disqualification.

Scoring

The bot with the largest KD spread, that is, the largest difference between the amount of wins and the amount of losses, wins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment