Esempio n. 1
0
def distance_diff(reference, target, vision_range):
    # print (reference, target, vision_range)
    ref_h = reference[0]
    ref_w = reference[1]
    tar_h = target[0]
    tar_w = target[1]

    height = tar_h - ref_h
    width = tar_w - ref_w

    if abs(height) > (vision_range + 1):
        if ref_h > tar_h:
            tar_h += config.grid_height()
        else:
            ref_h += config.grid_height()
        height = tar_h - ref_h
        height_sign = 1
        if height < 0:
            height_sign = -1
        height %= vision_range + 1
        height *= height_sign

    if abs(width) > (vision_range + 1):
        if ref_w > tar_w:
            tar_w += config.grid_width()
        else:
            ref_w += config.grid_width()
        width = tar_w - ref_w
        width_sign = 1
        if width < 0:
            width_sign = -1
        width %= vision_range + 1
        width *= width_sign

    return [height, width]
Esempio n. 2
0
File: grid.py Progetto: snisarg/263C
 def __init_easy_prey(self,count):
     for i in range(count):
         coord = [randint(0, config.grid_height()-1), randint(0, config.grid_width()-1)]
         if not self.grid.is_obstacle(coord):
             prey = animat.EPrey(coord[0], coord[1])
             self.easy_preys.append(prey)
             self.grid.add_to_position(coord, prey)
         else:
             i -= 1
Esempio n. 3
0
File: grid.py Progetto: snisarg/263C
 def __init_predator(self,count):
     for i in range(count):
         coord = [randint(0, config.grid_height()-1), randint(0, config.grid_width()-1)]
         if not self.grid.is_obstacle(coord):
             predator = animat.Predator(coord[0], coord[1], i)
             self.predators.append(predator)
             self.grid.add_to_position(coord, predator)
         else:
             i -= 1
Esempio n. 4
0
File: grid.py Progetto: snisarg/263C
 def get_occupants_in(self, coord):
     coord[0] %= config.grid_height()
     coord[1] %= config.grid_width()
     return self.grid[coord[0]][coord[1]].occupants
Esempio n. 5
0
File: grid.py Progetto: snisarg/263C
 def add_to_position(self, coord, occupant):
     coord[0] %= config.grid_height()
     coord[1] %= config.grid_width()
     self.grid[coord[0]][coord[1]].occupants.append(occupant)
     return coord
Esempio n. 6
0
File: grid.py Progetto: snisarg/263C
 def __set_grass(self):
     for i in range(config.grass_count()):
         coord = (randint(0, config.grid_height()-1), randint(0, config.grid_width()-1))
         if not self.is_obstacle(coord):
             self.__set_floor(coord, OccupantType.GRASS)
Esempio n. 7
0
File: grid.py Progetto: snisarg/263C
 def __set_single_obstacles(self):
     for i in range(config.single_obstacle_count()):
         coord = (randint(0, config.grid_height()-1), randint(0, config.grid_width()-1))
         self.__set_floor(coord, OccupantType.OBSTACLE)
Esempio n. 8
0
File: grid.py Progetto: snisarg/263C
 def __init__(self):
     self.grid = [[GridCell(OccupantType.EMPTY) for i in range(config.grid_width())] for i in range(config.grid_height())]
     # self.set_single_obstacles()
     self.__set_grass()
Esempio n. 9
0
 def single_obstacles(self):
     for i in range(config.single_obstacle_count()):
         self.grid[randint(0, config.grid_height()-1)][randint(0, config.grid_width()-1)] = GridCell(OccupantType.OBSTACLE)
Esempio n. 10
0
 def modulus_movement(self):
     self.position_x %= config.grid_width()
     self.position_y %= config.grid_height()