def action(self, colony): # BEGIN 2.3 s = self.place t = (s.terminators)[:] if self.time_to_digest > 0: if self.digesting <= 0: self.eat_terminator(random_or_none(t)) else: self.digesting -= 1 else: self.eat_terminator(random_or_none(t))
def nearest_terminator(self, skynet): """Return the nearest Terminator in a Place that is not the SKYNET, connected to the ThrowerDragon's Place by following entrances. This method returns None if there is no such Terminator (or none in range). """ # BEGIN 1.3 and 2.1 count = 0 s = self.place m = self.place if self.min_range == None and self.max_range == None: while s != skynet: k = random_or_none(s.terminators) if k != None: return k s = s.entrance else: return None elif self.min_range == None: while s != skynet: if count <= self.max_range: k = random_or_none(s.terminators) if k != None: return k s = s.entrance count += 1 else: return None elif self.max_range == None: while s != skynet: if count >= self.min_range: k = random_or_none(s.terminators) if k != None: return k s = s.entrance count += 1 else: return None else: while s != skynet: if count >= self.min_range and count <= self.max_range: k = random_or_none(s.terminators) if k != None: return k s = s.entrance count += 1 else: return None
def nearest_terminator(self, skynet): """Return the nearest Terminator in a Place that is not the SKYNET, connected to the ThrowerDragon's Place by following entrances. This method returns None if there is no such Terminator (or none in range). """ # BEGIN 1.3 and 2.1 # Get the current_place of dragon current_place = self.place # Move our observation range ahead by min_range current_range = 0 while current_range < self.min_range and current_place != skynet: current_place = current_place.entrance current_range += 1 # Make a check if current_place has reached skynet or not if current_place == skynet: return None # Now return the first terminator within max_range while current_range <= self.max_range and current_place != skynet: if len(current_place.terminators) > 0: return random_or_none(current_place.terminators) current_place = current_place.entrance current_range += 1 # Here? That means either no terminator found or reached the end of colony return None
def get_south_text(self, map_tile): text = random_or_none( cache.memoryCache.map.defaultBottomMovingTexts) or "" text += self._get_side_text( map_tile, 1, lambda v_range: cache.memoryCache.map.getBottomCell( map_tile.posX, map_tile.posY, v_range)) return text
def action(self, colony): # BEGIN 2.3 "*** YOUR CODE HERE ***" # digesting is a variable that checks how many turns are left to digest if self.digesting > 0: self.digesting -= 1 else: return self.eat_terminator(random_or_none(self.place.terminators))
def nearest_terminator(self, skynet): """Return the nearest Terminator in a Place that is not the SKYNET, connected to the ThrowerDragon's Place by following entrances. This method returns None if there is no such Terminator (or none in range). """ # BEGIN 1.3 and 2.1 # 1.3 starts here if len(self.place.terminators) == 0: current=self.place.entrance while current.entrance != None: if len(current.terminators) != 0: return random_or_none(current.terminators) else: current = current.entrance return None else: return random_or_none(self.place.terminators)
def get_nearest_description(self, tile: MapTile): text = self._get_current_tile_text(tile) loking_for_way_prefix = random_or_none( cache.memoryCache.map.defaultLookingForWayPrefix) or "" text += '{0} {1}, {2}, {3}, {4}, '.format(loking_for_way_prefix, self.get_north_text(tile), self.get_east_text(tile), self.get_south_text(tile), self.get_west_text(tile)) return text
def action(self, colony): if self.digesting == 0: terminator = random_or_none(self.place.terminators) if terminator is not None: self.eat_terminator(terminator) self.digesting = self.time_to_digest else: self.digesting -= 1 # BEGIN 2.3 "*** YOUR CODE HERE ***"
def nearest_terminator(self, skynet): """Return the nearest Terminator in a Place that is not the SKYNET, connected to the ThrowerDragon's Place by following entrances. This method returns None if there is no such Terminator (or none in range). """ # BEGIN 1.3 and 2.1 place = self.place while place.entrance is not skynet: if len(place.terminators) is not 0: break place = place.entrance return random_or_none(place.terminators) # REPLACE THIS LINE
def nearest_terminator(self, skynet): """Return the nearest Terminator in a Place that is not the SKYNET, connected to the ThrowerDragon's Place by following entrances. This method returns None if there is no such Terminator (or none in range). """ # BEGIN 1.3 and 2.1 k = self.place count = 0 while k != skynet and (count < self.min_range or count > self.max_range or len(k.terminators) == 0): k = k.entrance count += 1 #print(self.min_range) if k == skynet or count < self.min_range or count > self.max_range: return None else: return random_or_none(k.terminators)
def _get_side_text(self, tile: MapTile, view_range: int, func): text = '' next_cell = func(view_range) if next_cell is None: text += self._get_unpassable_defaults(tile) elif next_cell.isUnpassable: text += self._get_unpassable_defaults(next_cell) if self._see_throw_condition( next_cell) & self.vision_range > view_range: text += " " + self._get_side_text(tile, view_range + 1, func) else: text += self._get_range_depended_text( next_cell, view_range) or " -not filled- " if self._see_throw_condition( next_cell) & self.vision_range > view_range: text += ", " + random_or_none( cache.memoryCache.map.defaultBehindsTexts ) + " " + self._get_side_text(tile, view_range + 1, func) return text
def _get_unpassable_defaults(self, tile: MapTile): biome = next( (b for b in cache.memoryCache.biomes if b.id == tile.biomeId), None) result = random_or_none(biome.unpassabledefaults) if biome else None return result or ""