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.


A zero-player game... Until today. You are to write a program that plays the Game of Life - and plays it to win, King of the Hill-style. Your opponent (singular) of course tries to do the same. The winner is either the last bot with any live cells, or the player with the most live cells after 10000 generations.

Game rules

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

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

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

The board is a (x,y) cells 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. There is a central server that will run bots and it can be found here


The arena server speaks a simple JSON protocol communicated through argv

Where Values is a JSON encoded string

  • y_size: the maximum y coords of tiles before they vanish
  • x_size: the maximum x coords of tiles before they vanish
  • tick_id: the current tick number
  • board: a dictionary with keys in the form '(y,x)' and values in the form bot_id (int)
  • bot_id: tiles in the board with this id are yours



Telling the server your choice:

  • Send the server a list of tiles to turn to your colour.
  • Only those that are empty will be changed
  • Nested coords list format
    • [[0,0], [0,1], [100,22]...]

NOTE: Your bot doesn't have to update the tiles at all - the server does the updating itself

Competition rules

  • If your implementation fails to follow the protocol, the turn it does will be forfeited; The server will assume no change in state
  • 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. Please 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.
  • In the event of a tie, both players have 1 win added to their total

Running the controller yourself

The source for the controller can be found here. There are 2 ways of running the controller:

  • Competition mode (terminal)
    • Setup with python3 get_answers.py
    • Run an all v all competition with each bot pitting it against every other.
  • Testing mode (GUI)
    • Run python3 nice_gui.py
    • Click Pull Answers
    • If you want to add your own answer to try it before posting, click File -> Add manual answer and find the file and choose the language it's written in.
    • If your language isn't present ping me and I'll try to get it installed on the server I will run it on (installation and running instructions would be nice too!)
    • Choose 2 bots to pit against each other
    • Click Run
    • Watch the game...
  • Installation
    • Requires python3
    • get_answers requires bs4 and html5lib
    • controller requires a way of running .sh files (MinGW on windows)

Example image of app


The bot with the most wins starting from 12/07/2016 (12th July) 14/07/2016 (14th July, couldn't work out how to run a bot) wins.

Help with the controller/gui can be asked in this chat room

This question has been in development since 2014 and was the most upvoted question in the sandbox. Special Thanks goes to Wander Nauta (original author and concept), PPCG Chat (comments and help) and anyone who commented in the sandbox post (more comments).

  • 27
    \$\begingroup\$ Huh, I thought this would never make it out of the sandbox. Great! \$\endgroup\$
    – Luis Mendo
    Jun 28, 2016 at 21:23
  • \$\begingroup\$ Typo: 12/06/2016 (12th July) \$\endgroup\$
    – Luis Mendo
    Jun 28, 2016 at 21:32
  • 4
    \$\begingroup\$ +1. You deserve the AED award for bringing this great question out of the sandbox! \$\endgroup\$
    – agtoever
    Jul 3, 2016 at 18:59
  • 1
    \$\begingroup\$ @KevinLau-notKenny oh, okay. Can you run a command in a file? \$\endgroup\$
    – Riker
    Jul 6, 2016 at 1:16
  • 1
    \$\begingroup\$ @Magenta When I get them (I'd completely forgotten about this even though it's been in a constantly open tab), I'm running it now \$\endgroup\$
    – Blue
    Aug 20, 2016 at 10:00

7 Answers 7


Ruby, InterruptingBlockMaker

Instead of initializing gliders like the TrainingBot, it tries to create a 5x5 block-making switch machine as mentioned on Wikipedia at a random point in the maze. Then, with its remaining activations, it just finds enemy points and tries to pepper the nearby area with your cells in an attempt to interrupt them from growing and possibly messing up their patterns. Your cells will die in the next generation, but maybe they also stopped some growth to slow down your opponent!

v2: Optimized slightly (?) to try to minimize timeouts.

v3: Optimized interruption code to pre-sample a subset of active blocks before rejecting our own cell locations, to prevent timeouts further at the cost of some effectiveness in the interrupt cell attacks.

require 'json'

class Range
  def product range2
    self.to_a.product range2.to_a

args = JSON.parse(ARGV[0])
bot_id = args["bot_id"]
width  = args["x_size"]
height = args["y_size"]
board  = args["board"]

generator = [[2,2], [2,3], [2,6], [3,2], [3,5], [4,2], [4,5], [4,6], [5,4], [6,2], [6,4], [6,5], [6,6]]

targets = []

iterations = 50
gen_location = nil
while !gen_location && iterations > 0
  y = rand height - 9
  x = rand width  - 9
  temp = (0...9).product(0...9).map{|_y, _x| [y + _y, x + _x]}
  if temp.all?{|_y,_x| !board["(#{y},#{x})"]}
    gen_location = temp
    targets += generator.map{|_y, _x| [y + _y, x + _x]}

  iterations -= 1

enemies = board.keys.sample(100).reject {|k| board[k] == bot_id}
interrupts = []
enemies.each do |location|
  y, x = location.scan(/\d+/).map &:to_i
  interrupts |= ((y-1)..(y+1)).product((x-1)..(x+1)).reject{|y, x| gen_location.include?([y,x]) || board["(#{y},#{x})"]}

targets += interrupts.sample(30 - targets.size)

puts JSON.dump(targets)
  • \$\begingroup\$ @muddyfish thanks, that fixed it! Now the only issue is that Windows command line commands have a hardcoded limit of 8191, which means that at a certain point in the simulation the bots will crash from being unable to parse the truncated JSON string. It's an OS issue, so I guess I have have to look into a Linux cloud box or something in order to test my bot~ \$\endgroup\$
    – Value Ink
    Jun 29, 2016 at 21:09
  • \$\begingroup\$ @muddyfish I already mentioned that Windows has problems because of the command line limit, that last error was on Cloud9 which is ostensibly a Linux box. How does my bot fare on your Linux box (since you implied that you had one)? \$\endgroup\$
    – Value Ink
    Jun 29, 2016 at 22:45
  • \$\begingroup\$ Turns out I hadn't committed it but the numbers in bot_score show how many wins each bot has against other bots \$\endgroup\$
    – Blue
    Jun 30, 2016 at 21:11
  • \$\begingroup\$ All right, thanks! Unfortunately, Cloud9 indeed does not have a GUI and Windows still can't run the simulation without breaking its command limit eventually, but at least I got a brief look into how the bots fare against each other. Also, I get to see my bot fight against itself to the end some times because they keep attacking each other and preventing enough growth to break the character limit, although it does time out occasionally... \$\endgroup\$
    – Value Ink
    Jun 30, 2016 at 21:33

Python 3, Exploder

Puts small exploders around the place, with no regard to whether there is already a block there.

from random import randint
import sys,json,copy
for g in [0]*5:
 for C in A:C[0]+=Y;C[1]+=X
  • 1
    \$\begingroup\$ I can't believe that after all my work setting up block-making switches for indefinite growth and a system specifically built to demolish growth structures, a simple exploder-based system bested mine in combat :o \$\endgroup\$
    – Value Ink
    Mar 7, 2017 at 22:40
  • \$\begingroup\$ I don't know how it does either, because I can't run the controller for whatever reason. \$\endgroup\$
    – Magenta
    Mar 8, 2017 at 7:50

Python 2, TrainingBot

Because everyone needs one of these!

import random, copy
import sys, json

args = json.loads(sys.argv[1])
bot_id = args["bot_id"]
x_size = args["x_size"]
y_size = args["y_size"]
cur_tick = args["tick_id"]
board = args["board"]

glider = [[1,2],[2,1],[0,0],[0,1],[0,2]]

x_add = random.randrange(x_size)
y_add = random.randrange(y_size)
new_glider = copy.deepcopy(glider)
for coord in new_glider:
move = new_glider
print json.dumps(move)

Java, Troll Bot

Troll Bot has thought about it, and he realizes he does NOT care about the enemy. In fact he just spams these factories to produce more of his guys randomly all over the map. After a while he realized that any additional cells are best used in clumps. These blocks of four cells will stick together and stop gliders in their tracks! He does not think he just fights. Also he is a big supporter of verbose object oriented programming. The troll also assumes that coords are in the format y,x, and he is asking to be tested. Just put him in a file called "TrollBot.java", and he'll be set!

package trollbot;

 * @author Rohans
public class TrollBot{
public static class coord{
    public int x;
    public int y;
    public coord(int inX,int inY){
        x = inX;
        y = inY;
    public String toString(){
     * Input the JSON as the first cla
     * @param args the command line arguments
    public static void main(String[] args) {
       String JSON="{\"bot_id\":1,\"y_size\":1000,\"x_size\":1000,\"board\":{}}";
    String[] JArray=args[0].split(",");
       int botId=Integer.parseInt(JSON.charAt(10)+"");
    int xSize=Integer.parseInt(JArray[2].substring(JArray[2].indexOf(":")+1));
    int ySize=Integer.parseInt(JArray[1].substring(JArray[1].indexOf(":")+1));
    int[][] board = new int[xSize][ySize];//0 indexed
//todo: parse the board to get an idea of state
    String soldiers="[";    
//for now just ignore whats on the board and put some troll cells on
    //Attempts to create 3 10 cells factories of cells, hoping it does not place it on top of allies
    //Then puts random 2/2 blocks
  boolean[][] blockspam=new boolean[10][8];
  for(int z=0;z<3;z++){
     int xOffSet=(int) (Math.random()*(xSize-11));
     int yOffSet=(int) (Math.random()*(ySize-9));
     //stay away from edges to avoid odd interactions
     for(int i=0;i<blockspam.length;i++){
         for(int j=0;j<blockspam[i].length;j++){
             soldiers+=new coord(j+yOffSet,i+xOffSet).toString()+",";
  for(int i=0;i<8;i++){
            int y=(int ) (Math.random()*(ySize-1));
            int x = (int) (Math.random()*(xSize-1));
      soldiers+=new coord(y,x).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";
                          soldiers+=new coord(y,x+1).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";


  //GO GO GO! Lets rule the board


Python 3, RandomBot

This bot has trouble making intelligent decisions, but it at least knows not to try to place things on top of other things. It'll randomly create gliders, boats, C/2 Orthagonals, and 2x2 blocks with various orientations, ensuring that when they're placed they're not overlapping with something else, ally or enemy.

This bot wasn't tested, seeing as I'm receiving all sorts of errors when I try to run the GUI. Also, I used the TrainingBot as the base and just edit, so any similarities in code is probably because of that.

import random, copy
import sys, json
args = json.loads(sys.argv[1])
bot_id = args["bot_id"]
x_size = args["x_size"]
y_size = args["y_size"]
board = args["board"]
occupied = [tuple(key) for key,value in iter(board.items())]
choices = [[[1,2],[2,1],[0,0],[0,1],[0,2]],
while cellsleft>0:
    x_add = random.randrange(x_size)
    y_add = random.randrange(y_size)
    new_glider = copy.deepcopy(random.choice(choices))
    randomdirection = random.choice([[1,1],[1,-1],[-1,1],[-1,-1]])
    maxy=max([y[0] for y in new_glider])
    maxx=max([x[1] for x in new_glider])
    for coord in new_glider:
    set([tuple(x) for x in new_glider]) 
    if not set([tuple(x) for x in new_glider]) & (set(occupied)|set([tuple(x) for x in move])) and cellsleft>0:
        if min(y[0] for y in new_glider)<0: new_glider = [[y[0]+maxy,y[1]] for y in new_glider]
        if min(y[1] for y in new_glider)<0: new_glider = [[y[0],y[1]+maxx] for y in new_glider]
        move += new_glider
    elif set([tuple(x) for x in new_glider]) & (set(occupied)|set([tuple(x) for x in move])):

  • 1
    \$\begingroup\$ The GUI is most likely failing because of your print(sys.argv[1]) on line 3, which messes up the output (the simulator expects only the string of coordinates you want to wake up). Also, the last line of your program is missing a closing paren. \$\endgroup\$
    – Value Ink
    Jun 30, 2016 at 22:56
  • \$\begingroup\$ @KevinLau-notKenny The GUI was failing on the training bot and the Ruby bot as well. I removed that line, though, and added back in the closing paren (I think that latter one was a copy-paste error). \$\endgroup\$
    – Steven H.
    Jun 30, 2016 at 23:04
  • \$\begingroup\$ What operating system are you on, and what errors appear in the command line when you run it? Currently it's a known bug that Windows cannot properly run the sim because of arguments passed through command line being truncated when they exceed the command line character limit of around 8000. \$\endgroup\$
    – Value Ink
    Jun 30, 2016 at 23:21
  • \$\begingroup\$ @KevinLau-notKenny I'm using Windows 10, and I've gotten... well, a lot of errors. The first thing was BeautifulSoup not wanting to find html5lib, then not finding the folder containing all the bots (I had to change the code for both of these), and since then the running of either Python bot has resulted in a non-0 return code 1. \$\endgroup\$
    – Steven H.
    Jun 30, 2016 at 23:24
  • \$\begingroup\$ Windows still can't run the code if there are too many active cells on the screen... But as for your other errors, it might be because TrainingBot wants Python 2? \$\endgroup\$
    – Value Ink
    Jun 30, 2016 at 23:27

Python, GuyWithAGun

He's a guy, he's got a gun; he's mad. He just dumps glider guns everywhere with no regard to what anyone else is doing

import random, copy
import sys, json

args = json.loads(sys.argv[1])
bot_id = args["bot_id"]
x_size = args["x_size"]
y_size = args["y_size"]
tick_id = args["tick_id"]
board = args["board"]

start_squares = [[0,5],[2,5],[1,6],[2,6],
gun = [[11,5],[11,6],[11,7],

templates = [start_squares, gun]

def add_squares(pos, coords):
    new_squares = copy.deepcopy(coords)
    for coord in new_squares:
    return new_squares

def get_latest_pos():
    seed, template_id = divmod(tick_id, 2)
    cur_pos = [random.randrange(y_size),
    cur_template = templates[template_id]
        return add_squares(cur_pos, cur_template)
    except IndexError:
        return []

move = get_latest_pos()

print json.dumps(move)

Python 3, SquareBot

Puts squares everywhere- maybe

Squares are static objects in Life- they do not move. So if I place enough inert objects around the place, the gliders and explosions that others create will possibly be blocked, or at least dampened.

-Adapted from TrainingBot

from random import randint
import sys,json,copy
for g in range(7):
 for C in A:C[0]+=Y;C[1]+=X

Although I am having trouble testing it


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.