本文整理汇总了Python中cell.Cell.direction_to方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.direction_to方法的具体用法?Python Cell.direction_to怎么用?Python Cell.direction_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cell.Cell
的用法示例。
在下文中一共展示了Cell.direction_to方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: explore_action
# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import direction_to [as 别名]
def explore_action(self):
for neighbor in self.current_cell.get_neighbors():
row,col = neighbor.row, neighbor.col
if self.cells[row][col] is None:
dir_to = Cell.direction_to(self.current_cell, neighbor)
if dir_to is not None:
return Move(dir_to)
oldest_cell = None
oldest_time = 0
for row, i in zip(self.cells, range(len(self.cells))):
for cell, j in zip(row, range(len(row))):
if cell is None:
dir_to = Cell.direction_to(self.current_cell, self.world.cells[i][j])
if dir_to is not None:
return Move(dir_to)
else:
cell.step_time
if cell.step_time > oldest_time:
oldest_time = cell.step_time
oldest_cell = cell
if oldest_cell is not None:
dir_to = Cell.direction_to(self.current_cell, oldest_cell)
if dir_to is not None:
return Move(dir_to)
return Move(Direction.random_direction())
示例2: drink_action
# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import direction_to [as 别名]
def drink_action(self):
local_drink = self.get_drink_action()
if local_drink is not None:
return local_drink
else:
best_cell = self.find_closest(lambda cs: cs.has_water())
if best_cell is not None:
dir_to = Cell.direction_to(self.current_cell, best_cell)
if dir_to is not None:
return Move(dir_to)
return self.explore_action()
示例3: eat_action
# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import direction_to [as 别名]
def eat_action(self):
local_food = self.get_eat_action()
if local_food is not None:
return local_food
best_cell = self.find_closest(lambda cs: cs.has_food(self.diet + self.prey))
if best_cell is not None:
dir_to = Cell.direction_to(self.current_cell, best_cell)
if dir_to is None:
eat = self.get_eat_action()
if eat is None:
return self.explore_action()
else:
return eat
return self.explore_action()