 get_square_on_subboard = (x,y) ->
 	3 * (y % 3) + (x % 3)
 
-first_unfilled = (subboard_index) ->
+ais.first_unfilled = (subboard_index) ->
 	return i for v,i in boards[subboard_index] when v is 0
 
-unfilled_squares = (subboard_index) ->
+ais.unfilled_squares = (subboard_index) ->
 	return (i for v,i in boards[subboard_index] when v is 0)
 
 # This is the call to mutate the board from user-space

		when "move" then add_move(event.data.x, event.data.y)
		when "go"
			ai_name = event.data.ai
			postMessage(ais[ai_name]())

# Given an x,y coordinate in the 81 square space,
# return the subboard it's on (0 1 2/3 4 5/6 7 8)

	add_move(x,y)
	return [x,y]

# The greedy ai picks the first open square on the currently active subboard.
ais["greedy"] = {}
ais["greedy"].move = () ->
	subboard = subboard_next[-1..][0]
	selection = ais.first_unfilled(subboard)
	x = selection % 3 + 3 * (subboard % 3)
	y = selection // 3 + 3 * (subboard // 3)
	add_move(x,y)
	return [x,y]

# The focused ai will play the best move for the current active subboard.
# That is, it 'focuses' on winning subboards.

reset()
