[Question]
  [
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](https://upload.wikimedia.org/wikipedia/commons/f/f2/Game_of_life_animated_glider.gif)
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](https://github.com/muddyfish/PPCG-Life)
## Protocol
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
Example:
```
 {"y_size":2000,"x_size":2000,"board":{},"bot_id":1,"tick_id":1}
 
```
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](https://github.com/muddyfish/PPCG-Life). 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](https://i.stack.imgur.com/oHQPv.png)](https://i.stack.imgur.com/oHQPv.png)
## Scoring
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](http://chat.stackexchange.com/rooms/41885/discussion-between-fawful-and-kevin-lau-not-kenny)
---
This question has been in development since 2014 and was the most upvoted question in the sandbox. Special Thanks goes to [Wander Nauta](https://codegolf.meta.stackexchange.com/users/19075/wander-nauta) (original author and concept), [PPCG Chat](http://chat.stackexchange.com/rooms/240/the-nineteenth-byte) (comments and help) and anyone who commented in the [sandbox post](https://codegolf.meta.stackexchange.com/a/1332/32686) (more comments).
  
[Answer]
# Ruby, InterruptingBlockMaker
Instead of initializing gliders like the TrainingBot, it tries to create a [5x5 block-making switch machine as mentioned on Wikipedia](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Examples_of_patterns) 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
  end
end
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]}
  end
  iterations -= 1
end
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})"]}
end
targets += interrupts.sample(30 - targets.size)
puts JSON.dump(targets)
```
[Answer]
## 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
q=json.loads(sys.argv[1])
x=q["x_size"];y=q["y_size"];F=[[0,1],[1,0],[1,1],[1,2],[2,0],[2,2]];D=[]
for g in [0]*5:
 X=randint(0,x);Y=randint(0,y);A=copy.deepcopy(F)
 for C in A:C[0]+=Y;C[1]+=X
 D+=A
print(D)
```
[Answer]
## 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:
    coord[0]+=y_add
    coord[1]+=x_add
move = new_glider
print json.dumps(move)
```
[Answer]
# 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;
    }
    @Override
    public String toString(){
        return"["+x+","+y+"]";
    }
}
    /**
     * 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];
  blockspam[7][1]=true;
  blockspam[5][2]=true;
  blockspam[7][2]=true;
  blockspam[8][2]=true;
  blockspam[5][3]=true;
  blockspam[7][3]=true;
  blockspam[5][4]=true;
  blockspam[3][5]=true;
  blockspam[1][6]=true;
  blockspam[3][6]=true;
  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++){
             if(blockspam[i][j])
             soldiers+=new coord(j+yOffSet,i+xOffSet).toString()+",";
         }
     }
  }
  soldiers=soldiers.substring(0,soldiers.length()-1);
  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()+",";
  }
  soldiers+="\b]";
  System.out.println(soldiers);
  //GO GO GO! Lets rule the board
    }
}
```
[Answer]
# 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 Orthagonal](http://www.conwaylife.com/wiki/C/2_orthogonal)s, 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())]
cellsleft=30
move=[]
choices = [[[1,2],[2,1],[0,0],[0,1],[0,2]],
           [[0,0],[0,1],[1,1],[1,0]],
           [[0,1],[1,0],[0,2],[0,3],[1,3],[2,3],[3,3],[4,3],[5,2],[5,0]],
           [[0,0],[1,0],[0,1],[2,1],[2,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:
        coord[0]=coord[0]*randomdirection[0]+y_add
        coord[1]=coord[1]*randomdirection[1]+x_add
        cellsleft-=1
    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])):
        cellsleft+=len(new_glider)
print(json.dumps(move))
```
[Answer]
## 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],
                 [35,3],[36,3],[35,4],[36,4]]
gun = [[11,5],[11,6],[11,7],
       [12,4],[12,8],
       [13,3],[13,9],
       [14,3],[14,9],
       [15,6],
       [16,4],[16,8],
       [17,5],[17,6],[17,7],
       [18,6],
       [21,3],[21,4],[21,5],
       [22,3],[22,4],[22,5],
       [23,2],[23,6],
       [25,1],[25,2],[25,6],[25,7]]
templates = [start_squares, gun]
def add_squares(pos, coords):
    new_squares = copy.deepcopy(coords)
    for coord in new_squares:
        coord[0]+=pos[0]
        coord[1]+=pos[1]
    return new_squares
def get_latest_pos():
    seed, template_id = divmod(tick_id, 2)
    random.seed(seed)
    cur_pos = [random.randrange(y_size),
               random.randrange(x_size)]
    cur_template = templates[template_id]
    try:
        return add_squares(cur_pos, cur_template)
    except IndexError:
        return []
move = get_latest_pos()
print json.dumps(move)
```
[Answer]
## 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
args=json.loads(sys.argv[1])
x=args["x_size"];y=args["y_size"]
square=[[0,0],[0,1],[1,0],[1,1]];D=[]
for g in range(7):
 X=randint(0,x);Y=randint(0,y)
 A=copy.deepcopy(square)
 for C in A:C[0]+=Y;C[1]+=X
 D+=A
print(D)
```
Although I am having trouble testing it
]