当前位置: 首页>>代码示例>>Python>>正文


Python Cell.direction_to方法代码示例

本文整理汇总了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())
开发者ID:cnoziere,项目名称:DynamicWorld,代码行数:31,代码来源:animal.py

示例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()
开发者ID:cnoziere,项目名称:DynamicWorld,代码行数:14,代码来源:animal.py

示例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()
开发者ID:cnoziere,项目名称:DynamicWorld,代码行数:18,代码来源:animal.py


注:本文中的cell.Cell.direction_to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。