示例#1
0
 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"
示例#2
0
    def setUp(self, agent_opts=None):
        spec = {"players": [SimpleHuman(make_human_opts())], "agent": {"pos": (0, 0)}}
        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()
    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()
示例#4
0
def add_ground_to_context(context_sparse,
                          target_coord,
                          flat=True,
                          random_height=True):
    min_y = min([c[0][1] for c in context_sparse] + [target_coord[1]])
    max_ground_depth = min_y - 1
    if max_ground_depth <= 0:
        return
    if random_height:
        ground_depth = random.randint(1, max_ground_depth)
    else:
        ground_depth = max_ground_depth

    pos_z = 63

    shift = (-16, pos_z - 1 - ground_depth, -16)
    spec = {
        "players": [],
        "item_stacks": [],
        "mobs": [],
        "agent": {
            "pos": (0, pos_z, 0)
        },
        "coord_shift": shift,
    }
    world_opts = Opt()
    # TODO: this maybe should be a variable??
    world_opts.sl = 32

    if flat or max_ground_depth == 1:
        spec["ground_generator"] = flat_ground_generator
        spec["ground_args"] = {"ground_depth": ground_depth}
    else:
        world_opts.avg_ground_height = max_ground_depth // 2
        world_opts.hill_scale = max_ground_depth // 2
    world = World(world_opts, spec)

    ground_blocks = []
    for l, d in world.blocks_to_dict().items():
        shifted_l = tuple([l[i] - shift[i] for i in range(3)])
        ground_blocks.append((shifted_l, d))
    context_sparse += ground_blocks
    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"
                },
            },
        }
示例#6
0
import logging

if __name__ == "__main__":
    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 = {