def main():
  target_x = 15
  target_y = 8

  selection_rate  = .05
  crossover_rate  = .7
  mutation_rate   = .01

  blocks = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,8,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,0,0,0,1,0,0,0,0,0,0,5,1,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  [blocks, width, height] = fixBlocks(blocks)
  ga = GA(blocks, (target_x, target_y, height, width, selection_rate, crossover_rate, mutation_rate))
  sample = individual(50) 
  # pop = population(100, 40)
  # test = []
  # for i in range(200):
  #   a_fitness = ga.averageFitness(pop)
  #   pop = ga.evolve(pop)
  #   test.append((a_fitness, pop))

  # test = sorted(test)
  # sample = test[-1][1]

  # test2 = []
  # for individual in sample:
  #   test2.append((ga.fitness(individual), individual))

  # test2 = sorted(test2)
  # sample2 = test2[-1][1]
  # print sample2
  ga.visualize(sample)
      elif i == 11:
        start = start + np.array([-20, 0, -20, 0])

def individual(length):
  individual = [randint(0, 1) for x in range(length)]
  return ''.join(str(e) for e in individual)

def population(num_people, length):
  return [individual(length) for x in range(num_people)]

target_x = 15
target_y = 8

selection_rate  = .05
crossover_rate  = .7
mutation_rate   = .001

blocks = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,8,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,0,0,0,1,0,0,0,0,0,0,5,1,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
[blocks, width, height] = fixBlocks(blocks)

ga = GA(blocks, (target_x, target_y, height, width, selection_rate, crossover_rate, mutation_rate))
pop = population(100, 70)
test = []
for individual in pop:
  test.append((ga.fitness(individual), individual)) 

test = sorted(test)
print test[1][-1]
ga.visualize(test[1][-1])