Example #1
0
 def __init__(self,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):
     self.snapshot = np.array([[0 for _ in range(ysize)]
                               for _ in range(xsize)])
     self.xsize = xsize  #int
     self.ysize = ysize  #int
     self.moment = 0
     self.new_id = 0
     self.mins = [[0 for _ in range(ysize)] for _ in range(xsize)]
     nut = total_mass
     for mi in mis:
         nut -= mi.mass
     for _ in range(nut):
         i = randint(0, xsize - 1)
         j = randint(0, ysize - 1)
         self.mins[i][j] += 1
     self.pedigree = []  #(int,int)[]
     self.occupy_map = [[[] for _ in range(self.ysize)]
                        for _ in range(self.xsize)]  #minion.Minion[][][]
     self.mis = []  #minion.Minion[]
     for mi in mis:
         self.register(mi)
     #additional attributes for test
     self.no_age = no_age
     self.no_birth = no_birth  #bool
     self.no_eat = no_eat  #bool
     self.no_energy = no_energy  #bool
     self.no_excrete = no_excrete  #bool
     self.no_hunt = no_hunt  #bool
     self.messiness = 0
     self.halluc = halluc  #bool
     self.hidden_mass = 0
     #measurement option
     self.record_pedigree = record_pedigree
Example #2
0
def construct_minion(dna, alen, pos, do_freeze):
    mi = Minion(dna)
    mi.take_mass((1 + 2 * alen)**2 - 9)
    if pos == (-1, -1):
        pos = (randint(0, xsize - 1), randint(0, ysize - 1))
    mi.pos = pos
    if do_freeze:
        mi.freeze()
    return mi
Example #3
0
def randLinearDNA():
    r = randint(0, 255)
    g = randint(0, 255)
    b = randint(0, 255)
    maxsize = randint(min_maxsize, max_maxsize)
    uptake = min_uptake + (max_uptake - min_uptake) * uniform()
    maxage = randint(min_maxage, max_maxage)
    weights = np.array(list(multiple_uniform(linear_wdim)), dtype=float)
    for i in range(linear_wdim):
        weights[i] = 1 - 2 * weights[i]
    group_sizes = np.empty(num_out, dtype=int)
    for i in range(num_out):
        group_sizes[i] = clear_idim
    colorTrait = ColorTrait(r, g, b)
    maxsizeTrait = PositiveTrait(maxsize)
    uptakeTrait = UnitTrait(uptake)
    maxageTrait = PositiveTrait(maxage)
    weightsTrait = FloatListTrait(weights, group_sizes)
    return LinearDNA(colorTrait, maxsizeTrait, uptakeTrait, maxageTrait,
                     weightsTrait)
Example #4
0
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)