Esempio n. 1
0
 def get_info(self):
     info = MobInfo()
     info.entityId = self.entityId
     info.pos = Pos(*self.pos)
     info.look = Look(*self.look)
     info.mobType = self.mobType
     info.color = self.color
     info.mobname = self.mobname
     return info
Esempio n. 2
0
    def test_add_mob(self):
        # add mob
        chicken = {v: k for k, v in MOBS_BY_ID.items()}["chicken"]
        mob_id, mob_type, pos, look = 42, chicken, Pos(3, 4, 5), Look(0.0, 0.0)
        self.memory.set_mob_position(Mob(mob_id, mob_type, pos, look))

        # get mob
        self.assertIsNotNone(self.memory.get_entity_by_eid(mob_id))

        # update mob
        pos = Pos(6, 7, 8)
        look = Look(120.0, 50.0)
        self.memory.set_mob_position(Mob(mob_id, mob_type, pos, look))

        # get mob
        mob_node = self.memory.get_entity_by_eid(mob_id)
        self.assertIsNotNone(mob_node)
        self.assertEqual(mob_node.pos, (6, 7, 8), (120.0, 50.0))
    def setUp(self, agent_opts=None):
        spec = {
            "players": [Player(42, "SPEAKER", Pos(5, 63, 5), Look(270, 0), Item(0, 0))],
            "mobs": [],
            "item_stacks": [],
            "ground_generator": flat_ground_generator,
            "agent": {"pos": (0, 63, 0)},
            "coord_shift": (-16, 54, -16),
        }
        world_opts = Opt()
        world_opts.sl = 32
        self.world = World(world_opts, spec)
        self.agent = FakeAgent(self.world, opts=agent_opts)

        self.set_looking_at((0, 63, 0))
        self.speaker = self.agent.get_other_players()[0].name
        self.agent.perceive()
 def __init__(self):
     # Replica of test environment
     spec = {
         "players":
         [Player(42, "SPEAKER", Pos(5, 63, 5), Look(270, 0), Item(0, 0))],
         "mobs": [],
         "ground_generator":
         flat_ground_generator,
         "agent": {
             "pos": (0, 63, 0)
         },
         "coord_shift": (-16, 54, -16),
     }
     world_opts = Opt()
     world_opts.sl = 32
     self.world = World(world_opts, spec)
     self.agent = FakeAgent(self.world, opts=None)
     self.speaker = "cat"
Esempio n. 5
0
 def test_add_guardian_mob(self):
     guardian = {v: k for k, v in MOBS_BY_ID.items()}["guardian"]
     mob_id, mob_type, pos, look = 42, guardian, Pos(3, 4, 5), Look(0.0, 0.0)
     self.memory.set_mob_position(Mob(mob_id, mob_type, pos, look))
Esempio n. 6
0
 def get_player(self):
     return Player(1, "fake_agent", Pos(*self.pos), Look(0, 0), Item(0, 0))
Esempio n. 7
0
 def get_look(self):
     pitch = -np.rad2deg(np.arcsin(self._look_vec[1]))
     yaw = -np.rad2deg(np.arctan2(self._look_vec[0], self._look_vec[2]))
     return Look(pitch, yaw)
Esempio n. 8
0
 def get_other_players(self):
     return [Player(42, "SPEAKER", Pos(5, 63, 5), Look(270, 0), Item(0, 0))]
    def setUp(self, agent_opts=None):
        spec = {
            "players":
            [Player(42, "SPEAKER", Pos(5, 63, 5), Look(270, 0), Item(0, 0))],
            "mobs": [],
            "ground_generator":
            flat_ground_generator,
            "agent": {
                "pos": (0, 63, 0)
            },
            "coord_shift": (-16, 54, -16),
        }
        world_opts = Opt()
        world_opts.sl = 32
        self.world = World(world_opts, spec)
        self.agent = FakeAgent(self.world, opts=agent_opts)

        # More helpful error message to encourage test writers to use self.set_looking_at()
        self.agent.get_player_line_of_sight = Mock(
            side_effect=NotImplementedError(
                "Cannot call into C++ function in this unit test. " +
                "Call self.set_looking_at() to set the return value"))

        self.speaker = self.agent.get_other_players()[0].name
        self.agent.perceive()

        # Combinable actions to be used in test cases
        self.possible_actions = {
            "destroy_speaker_look": {
                "action_type": "DESTROY",
                "reference_object": {
                    "location": {
                        "location_type": "SPEAKER_LOOK"
                    }
                },
            },
            "copy_speaker_look_to_agent_pos": {
                "action_type": "BUILD",
                "reference_object": {
                    "location": {
                        "location_type": "SPEAKER_LOOK"
                    }
                },
                "location": {
                    "location_type": "AGENT_POS"
                },
            },
            "build_small_sphere": {
                "action_type": "BUILD",
                "schematic": {
                    "has_name": "sphere",
                    "has_size": "small"
                },
            },
            "build_1x1x1_cube": {
                "action_type": "BUILD",
                "schematic": {
                    "has_name": "cube",
                    "has_size": "1 x 1 x 1"
                },
            },
            "move_speaker_pos": {
                "action_type": "MOVE",
                "location": {
                    "location_type": "SPEAKER_POS"
                },
            },
            "build_diamond": {
                "action_type": "BUILD",
                "schematic": {
                    "has_name": "diamond"
                }
            },
            "build_gold_cube": {
                "action_type": "BUILD",
                "schematic": {
                    "has_block_type": "gold",
                    "has_name": "cube"
                },
            },
            "fill_all_holes_speaker_look": {
                "action_type": "FILL",
                "location": {
                    "location_type": "SPEAKER_LOOK"
                },
                "repeat": {
                    "repeat_key": "ALL"
                },
            },
            "go_to_tree": {
                "action_type": "MOVE",
                "location": {
                    "location_type": "REFERENCE_OBJECT",
                    "reference_object": {
                        "has_name": "tree"
                    },
                },
            },
            "build_square_height_1": {
                "action_type": "BUILD",
                "schematic": {
                    "has_name": "square",
                    "has_height": "1"
                },
            },
            "stop": {
                "action_type": "STOP"
            },
            "fill_speaker_look": {
                "action_type": "FILL",
                "location": {
                    "location_type": "SPEAKER_LOOK"
                },
            },
            "fill_speaker_look_gold": {
                "action_type": "FILL",
                "has_block_type": "gold",
                "location": {
                    "location_type": "SPEAKER_LOOK"
                },
            },
        }
Esempio n. 10
0
    log_formatter = logging.Formatter(
        "%(asctime)s [%(filename)s:%(lineno)s - %(funcName)s() %(levelname)s]: %(message)s"
    )
    logging.getLogger().setLevel(logging.DEBUG)
    logging.getLogger().handlers.clear()
    # set up stdout logging
    sh = logging.StreamHandler()
    sh.setLevel(logging.DEBUG)
    sh.setFormatter(log_formatter)
    logging.getLogger().addHandler(sh)

    opts = Opt()
    opts.sl = 32
    spec = {
        "players":
        [Player(42, "SPEAKER", Pos(0, 68, 0), Look(270, 80), Item(0, 0))],
        "mobs":
        [SimpleMob(make_mob_opts("cow")),
         SimpleMob(make_mob_opts("chicken"))],
        "agent": {
            "pos": (1, 68, 1)
        },
        "coord_shift": (-opts.sl // 2, 63 - opts.sl // 2, -opts.sl // 2),
    }
    world = World(opts, spec)
    agent = FakeAgent(world, opts=None)
    speaker_name = agent.get_other_players()[0].name
    move_speaker_pos = {
        "action_type": "MOVE",
        "location": {
            "location_type": "SPEAKER_POS"