It's Life, Jim, but not as we know it
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
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)
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)
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)