Beispiel #1
0
 def random_field(self, move_range):
     new_x = self.x
     new_y = self.y
     while (new_x == self.x) and (new_y == self.y):
         while True:
             new_x = self.x + random.randint(-move_range, move_range)
             if (new_x >= 0) and (new_x < self.world.width):
                 break
         while True:
             new_y = self.y + random.randint(-move_range, move_range)
             if (new_y >= 0) and (new_y < self.world.height):
                 break
     return Field(new_x, new_y)
Beispiel #2
0
 def random_field(self):
     new_x = self.x
     new_y = self.y
     tries_all = 0
     while self.world.organisms_board[new_x][new_y].occupied and tries_all < 25:
         while True:
             new_x = self.x + random.randint(-1, 1)
             if (new_x >= 0) and (new_x < self.world.width):
                 break
         while True:
             new_y = self.y + random.randint(-1, 1)
             if (new_y >= 0) and (new_y < self.world.height):
                 break
         tries_all += 1
     return Field(new_x, new_y)
 def find_hogweed(self):
     closest_hogweed = None
     for x in self.world.organisms_list:
         if x.id == ID.hogweed.value:
             if closest_hogweed is not None:
                 if (max(abs(self.x - x.x), abs(self.y - x.y))) < max((abs(self.x - closest_hogweed.x)
                                                                       , abs(self.y - closest_hogweed.y))):
                     closest_hogweed = x
             else:
                 closest_hogweed = x
     if closest_hogweed is not None:
         return Field(self.x + self.dist_x_y(closest_hogweed.x, self.x),
                      self.y + self.dist_x_y(closest_hogweed.y, self.y))
     else:
         return -1
Beispiel #4
0
 def breed_field(self, x1, y1, x2, y2, other):
     if (self.cd == 0) and (other.cd == 0):
         self.cd += self.breeding
         other.cd += other.breeding
         breeding_list = [[] for _ in range(8)]
         counter = 0
         counter += self.check_breeding(breeding_list, x1, y1, counter)
         counter += self.check_breeding(breeding_list, x2, y2, counter)
         if counter > 0:
             index = random.randint(0, counter - 1)
             new_x = 0
             new_y = 0
             new_x += breeding_list[index][0]
             new_y += breeding_list[index][1]
             return Field(new_x, new_y)
         else:
             return -1
     return -1
Beispiel #5
0
 def downKey(self, event):
     if self.world.human_alive:
         if self.world.human_y < self.world.height - 1:
             self.world.human_move = Field(self.world.human_x,
                                           self.world.human_y + 1)
             self.next_turn()
Beispiel #6
0
 def upKey(self, event):
     if self.world.human_alive:
         if self.world.human_y > 0:
             self.world.human_move = Field(self.world.human_x,
                                           self.world.human_y - 1)
             self.next_turn()
Beispiel #7
0
 def rightKey(self, event):
     if self.world.human_alive:
         if self.world.human_x < self.world.width - 1:
             self.world.human_move = Field(self.world.human_x + 1,
                                           self.world.human_y)
             self.next_turn()
Beispiel #8
0
 def leftKey(self, event):
     if self.world.human_alive:
         if self.world.human_x > 0:
             self.world.human_move = Field(self.world.human_x - 1,
                                           self.world.human_y)
             self.next_turn()
Beispiel #9
0
 def empty_field(self):
     while True:
         x = random.randint(0, self.width - 1)
         y = random.randint(0, self.height - 1)
         if not self.organisms_board[x][y].occupied:
             return Field(x, y)