def construct_world(xsize,ysize,total_mass,num_dna,ininum,\ no_age=False,no_birth=False,no_eat=False, no_energy=False, no_excrete=False,\ no_hunt=False,halluc=False,alen_list=None,pos_list=None,freeze_list=None,\ record_pedigree=False): seed_py() dnas = [world_cy.randLinearDNA() for _ in range(num_dna)] mis=world_cy.dll_from_list(\ [world_cy.construct_minion(dnas[i%num_dna],\ alen=1 if alen_list is None else alen_list[i],\ pos=(-1,-1) if pos_list is None else pos_list[i],\ do_freeze=False if freeze_list is None else freeze_list[i])\ for i in range(ininum)]) return world_cy.World(xsize,ysize,total_mass,mis,no_age=no_age,no_birth=no_birth,\ no_eat=no_eat,no_energy=no_energy,no_excrete=no_excrete,no_hunt=no_hunt,\ halluc=halluc,record_pedigree=record_pedigree)
random.shuffle(blue_dnas) mis = [] for i in range(ininum_red): mis.append( world.construct_minion(red_dnas[i % len(red_dnas)], alen=1, pos=(-1, -1), do_freeze=False)) for i in range(ininum_blue): mis.append( world.construct_minion(blue_dnas[i % len(blue_dnas)], alen=1, pos=(-1, -1), do_freeze=False)) mis = world.dll_from_list(mis) w=world.World(xsize,ysize,total_mass,mis,no_age=False,no_birth=False,no_eat=False,\ no_energy=False,no_excrete=False,no_hunt=False,halluc=False,record_pedigree=False) red_keep, blue_keep = [False], [False] tmp_red_dnas.clear() w.append_red_dnas(tmp_red_dnas) tmp_blue_dnas.clear() w.append_blue_dnas(tmp_blue_dnas) dof = lambda w: dofun(w, red_keep, blue_keep, tmp_red_dnas, tmp_blue_dnas) win = exputil_cy.do(w, k, dof=dof, endf=endf, returnf=returnf, screen_off=True, print_moment=True, print_moment_period=1, screen_period=50)
def test_world(testname, dnas): if testname == "food(n)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], \ alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=True, no_birth=True, \ no_eat=False, no_energy=True, no_excrete=True, no_hunt=True, \ halluc=False, record_pedigree=False) elif testname == "food(h)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=True, no_birth=True, \ no_eat=False, no_energy=True, no_excrete=True, no_hunt=True, \ halluc=True, record_pedigree=False) elif testname == "hunt(o)": dna1, _ = furthest_color_dna_pair(dnas) mis = world.dll_from_list( \ [world.construct_minion(dna1,alen=4,pos=(0,0), do_freeze=False), \ world.construct_minion(dna1, alen=1, pos=(test_xsize//2,test_ysize//2),do_freeze=True)]) return world.World(test_xsize, test_ysize, test_total_mass, mis, no_age=True, no_birth=True, \ no_eat=True, no_energy=True, no_excrete=True, no_hunt=False, \ halluc=False, record_pedigree=False) elif testname == "hunt(e)": dna1, dna2 = furthest_color_dna_pair(dnas) mis = world.dll_from_list( \ [world.construct_minion(dna1,alen=4,pos=(0,0), do_freeze=False), \ world.construct_minion(dna2, alen=1, pos=(test_xsize//2,test_ysize//2),do_freeze=True)]) return world.World(test_xsize, test_ysize, test_total_mass, mis, no_age=True, no_birth=True, \ no_eat=True, no_energy=True, no_excrete=True, no_hunt=False, \ halluc=False, record_pedigree=False) elif testname == "rape(o)": dna1, _ = furthest_color_dna_pair(dnas) mis = world.dll_from_list( \ [world.construct_minion(dna1,alen=1,pos=(0,0), do_freeze=False), \ world.construct_minion(dna1, alen=4, pos=(test_xsize//2,test_ysize//2),do_freeze=True)]) return world.World(test_xsize, test_ysize, test_total_mass, mis, no_age=True, no_birth=True, \ no_eat=True, no_energy=True, no_excrete=True, no_hunt=True, \ halluc=False, record_pedigree=False) elif testname == "rape(e)": dna1, dna2 = furthest_color_dna_pair(dnas) mis = world.dll_from_list( \ [world.construct_minion(dna1,alen=1,pos=(0,0), do_freeze=False), \ world.construct_minion(dna2, alen=4, pos=(test_xsize//2,test_ysize//2),do_freeze=True)]) return world.World(test_xsize, test_ysize, test_total_mass, mis, no_age=True, no_birth=True, \ no_eat=True, no_energy=True, no_excrete=True, no_hunt=True, \ halluc=False, record_pedigree=False) elif testname == "birth(n)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], \ alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=False, no_birth=False, \ no_eat=False, no_energy=False, no_excrete=False, no_hunt=False, \ halluc=False, record_pedigree=False) elif testname == "birth(h)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], \ alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=False, no_birth=False, \ no_eat=False, no_energy=False, no_excrete=False, no_hunt=False, \ halluc=True, record_pedigree=False) elif testname == "messy(n)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], \ alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=True, no_birth=True, \ no_eat=False, no_energy=True, no_excrete=False, no_hunt=True, \ halluc=False, record_pedigree=False) elif testname == "messy(h)": mis = world.dll_from_list( \ [world.construct_minion(dnas[i % len(dnas)], \ alen=1,pos=(randint(0,xsize-1),randint(0,ysize-1)), do_freeze=False)\ for i in range(ininum)]) return world.World(xsize, ysize, total_mass, mis, no_age=True, no_birth=True, \ no_eat=False, no_energy=True, no_excrete=False, no_hunt=True, \ halluc=True, record_pedigree=False)