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


Python Memory.memorize_world_info方法代码示例

本文整理汇总了Python中memory.Memory.memorize_world_info方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.memorize_world_info方法的具体用法?Python Memory.memorize_world_info怎么用?Python Memory.memorize_world_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.memorize_world_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import memorize_world_info [as 别名]
class Decider:
    '''This class is responsible for deciding what to do next.
    It only thinks and decide on next action, and then ask
    handlers to do the job.
    '''

    def __init__(self):
        self._memory = Memory()

    def run_til_die(self):
        '''Runs in a loop until the robot dies.'''

        # The algorithm:
        # 1) Find water.
        # 2) Take water and get back to the nearest soil.
        # 3) Plant three corps.
        # 4) Water corps.
        # 5) If honor is enough, give birth to another robot.
        # 6) Continue from 2

        response = Communicator.send_action("info", [])
        if response['status'] == 500:
            print("Unexpected error:", response['error_code'], ":", response['error_message'])
            return

        self._memory.memorize_world_info(response['result'])
        print("I learned these about this world:", response['result'])

        print("Let's explore the world!")
        while True:
            # Checking the status.
            response = Communicator.send_action("status", [])
            if response['status'] == 500:
                # Error occured.
                if response['error_code'] == 'AuthenticationFailedError':
                    print("Seems that I'm dead. Goodbye beautiful world.")
                    break
                else:
                    print("Unexpected error:", response['error_code'], ":", response['error_message'])
                    break

            status = response['result']
            print("My current status is:", status)

            if (status['location'] == self._memory.get_first_plant_location() or
                status['location'] == self._memory.get_second_plant_location()):
                # Trying to eat this plant.
                EatingHandler().handle(self._memory, status['location'])

            if status['honor'] >= self._memory.get_birth_required_honor():
                print("Enough honor, let's giving birth to a child!")
                GiveBirthHandler().handle(self._memory)

            elif self._memory.get_nearest_water() is None:
                print("I still don't know any water. Let's find some!")
                WaterFindingHandler().handle(self._memory)

            elif not status['has_water']:
                print("No water on hand. Going to pick some.")
                WaterPickingHandler().handle(self._memory, status['location'])

            elif status['has_water'] and self._memory.get_first_plant_location() is None:
                print("I still didn't plant anything. Going to plant some corps.")
                PlantingHandler().handle(self._memory, status['location'])

            elif status['has_water'] and self._memory.get_first_plant_location() is not None:
                print("Going to water my plants.")
                WateringHandler().handle(self._memory, status['location'])
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:70,代码来源:decider.py


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