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)
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)
random.shuffle(blue_dnas) red_dnas.clear() for dna in tmp_red_dnas: red_dnas.append(dna) elif win == "none": red_dnas.clear() w.append_red_dnas(red_dnas) random.shuffle(red_dnas) blue_dnas.clear() w.append_blue_dnas(blue_dnas) 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)
total_mass = 40000 ininum_red,ininum_blue=120,240 red_maxsize,red_uptake,red_maxage=6,0.6,1600 blue_maxsize,blue_uptake,blue_maxage=4,0.4,1600 avg_consum_rate,consum_exp=0.01,0.5 exputil_cy.set_size(xsize, ysize) exputil_cy.set_heredity(merge_thres, mut_per_diff) world.set_consum(avg_consum_rate,consum_exp) red_dna=world.randLinearDNA_with(c=(255,0,0),mst_a=red_maxsize,utt_a=red_uptake,mat_a=red_maxage) blue_dna=world.randLinearDNA_with(c=(0,0,255),mst_a=blue_maxsize,utt_a=blue_uptake,mat_a=blue_maxage) mis=[] for _ in range(ininum_red): mis.append(world.construct_minion(red_dna,alen=1,pos=(-1,-1),do_freeze=False)) for _ in range(ininum_blue): mis.append(world.construct_minion(blue_dna,alen=1,pos=(-1,-1),do_freeze=False)) print(len(mis)) 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) def dof(w): w.one_step() print(w.get_population()) ct,mst,utt,mat,wt=w.get_nth_mi(0).get_dna().get_traits() print(ct.get_c(),mst.get_a(),utt.get_a(),mat.get_a()) exputil_cy.do(w, k, dof=dof, endf=lambda w: w.extincted() or w.limit(limit),