示例#1
0
文件: bat.py 项目: annoyingcalc/Bat
    def print_plan(self, dy=0):
        center = self.clinfo.position
        visible_blocks = set()
        msg = ''
        for dz in range(-5, 6, 1):
            msg += '\n'
            for dx in range(-5, 6, 1):
                block_pos = Vec(dx, dy, dz).iadd(center)
                block_id, meta = self.world.get_block(*block_pos)
                visible_blocks.add((block_id, meta))

                if block_id == 0:
                    msg += '       '
                elif meta == 0:
                    msg += '%3i    ' % block_id
                else:
                    msg += '%3i:%-2i ' % (block_id, meta)

                if dx == dz == 0:  # mark bot position with brackets: [blockID]
                    msg = msg[:-8] + ('[%s]' % msg[-7:-1])

        for block_id, meta in sorted(visible_blocks):
            if block_id != 0:
                display_name = blocks.get_block(block_id, meta).display_name
                logger.info('%3i: %s' % (block_id, display_name))
        logger.info(msg)
示例#2
0
    def print_plan(self, dy=0):
        center = self.clientinfo.position.floor()
        visible_blocks = set()
        msg = ''
        for dz in range(-5, 6, 1):
            msg += '\n'
            for dx in range(-5, 6, 1):
                block_pos = Vector3(dx, dy, dz).iadd(center)
                block_id, meta = self.world.get_block(*block_pos)
                visible_blocks.add((block_id, meta))

                if block_id == 0:
                    msg += '       '
                elif meta == 0:
                    msg += '%3i    ' % block_id
                else:
                    msg += '%3i:%-2i ' % (block_id, meta)

                if dx == dz == 0:  # mark bot position with brackets: [123:45]
                    msg = msg[:-8] + ('[%s]' % msg[-7:-1])

        for block_id, meta in sorted(visible_blocks):
            if block_id != 0:
                display_name = blocks.get_block(block_id, meta).display_name
                logger.info('%3i:%-2i %s', block_id, meta, display_name)
        logger.info(msg)
    def _build_block_nodes(self, block, map_handle):

        # hack to make static object No. variable in class method
        if not hasattr(self._build_block_nodes.__func__, "objNo"):
            self._build_block_nodes.__func__.objNo = 0
        # Note: in 3DSpaceMap using structure node to represent block,
        # entity node to represent entity

        obj_node = self._atomspace.add_node(types.StructureNode, "obj%s" % (self._build_block_nodes.__func__.objNo))
        self._build_block_nodes.__func__.objNo += 1
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, obj_node, map_handle, [block.x, block.y, block.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(
            types.ConceptNode, blocks.get_block(block.blockid, block.metadata).display_name
        )
        material_link = add_predicate(self._atomspace, "material", obj_node, type_node)
        updated_eval_links.append(material_link)

        new_appeared_link = add_predicate(self._atomspace, "new_block", obj_node)
        updated_eval_links.append(new_appeared_link)

        return obj_node, updated_eval_links
示例#4
0
    def _build_block_nodes(self, block, map_handle):

        # hack to make static object No. variable in class method
        if not hasattr(self._build_block_nodes.__func__, "objNo"):
            self._build_block_nodes.__func__.objNo = 0
        # Note: in 3DSpaceMap using structure node to represent block,
        # entity node to represent entity

        obj_node = self._atomspace.add_node(
            types.StructureNode,
            "obj%s" % (self._build_block_nodes.__func__.objNo))
        self._build_block_nodes.__func__.objNo += 1
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, obj_node, map_handle,
                                        [block.x, block.y, block.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(
            types.ConceptNode,
            blocks.get_block(block.blockid, block.metadata).display_name)
        material_link = add_predicate(self._atomspace, "material", obj_node,
                                      type_node)
        updated_eval_links.append(material_link)

        new_appeared_link = add_predicate(self._atomspace, "new_block",
                                          obj_node)
        updated_eval_links.append(new_appeared_link)

        return obj_node, updated_eval_links
示例#5
0
 def get_block_slip(self):
     if self.pos.on_ground:
         block_pos = self.pos.floor()
         block_id, meta = self.world.get_block(
             block_pos.x, block_pos.y - 1, block_pos.z
         )
         return blocks.get_block(block_id, meta).slipperiness
     return 1
    def handle_vision_message(self,data):
        #print "handle_visiion_message"
        #TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name
            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            if old_block_handle.is_undefined():
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
            else:
                old_block_type_node = get_predicate(self._atomspace, "material",
                                                    Atom(old_block_handle, self._atomspace), 1)
                old_block_type = self._atomspace.get_name(old_block_type_node.h)
                if old_block_type == block_material:
                    continue
                elif block.blockid == 0:
                    blocknode, updated_eval_links = Atom(Handle(-1), self._atomspace), []
                else:
                    blocknode, updated_eval_links = self._build_block_nodes(block,
                                                                            map_handle)

                
                #TODO: not sure if we should add disappeared predicate here,
                #It looks reasonable but make the code more messy..
                disappeared_link = add_predicate(self._atomspace, "disappeared", Atom(old_block_handle, self._atomspace))
                updated_eval_links.append(disappeared_link)
            self._space_server.add_map_info(blocknode.h, map_handle, False, False,
                                            block.ROStimestamp,
                                            block.x, block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h,block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link.h,block.MCtimestamp, "MC")
            #print blocknode
            #print updated_eval_links

        #TODO: The code below stores the number of blocks of each type seen in the current field of view into the atomspace.  It is commented out as it should probably not store this until the code to erase old values is also added otherwise this data just piles up as new links from the same root node and it becomes a jumbled mess.
        #print "\nBlock material summary:  saw %s kinds of blocks" % len(material_dict)
        """
示例#7
0
    def periodic_event_handler(self):
        """Triggered every 5 seconds by a timer"""

        logger.info('My position: {0} pitch: {1} yaw: {2}'.format(
            self.clientinfo.position, self.clientinfo.position.pitch,
            self.clientinfo.position.yaw))

        # Place a block in front of the player
        self.interact.place_block(self.clientinfo.position +
                                  Vector3(-1, 0, -1))

        # Read a block under the player
        block_pos = self.clientinfo.position.floor()
        block_id, meta = self.world.get_block(*block_pos)
        block_at = blocks.get_block(block_id, meta)
        self.chat.chat('Found block %s at %s' %
                       (block_at.display_name, block_pos))
示例#8
0
    def periodic_event_handler(self):
        """Triggered every 5 seconds by a timer"""

        logger.info('My position: {0} pitch: {1} yaw: {2}'.format(
            self.clientinfo.position,
            self.clientinfo.position.pitch,
            self.clientinfo.position.yaw))

        # Place a block in front of the player
        self.interact.place_block(self.clientinfo.position
                                  + Vector3(-1, 0, -1))

        # Read a block under the player
        block_pos = self.clientinfo.position.floor()
        block_id, meta = self.world.get_block(*block_pos)
        block_at = blocks.get_block(block_id, meta)
        self.chat.chat('Found block %s at %s' % (block_at.display_name,
                                                 block_pos))
示例#9
0
 def block_collision(self, pos):
     for block_pos in gen_block_set(pos):
         block_id, meta = self.world.get_block(
             block_pos.x, block_pos.y, block_pos.z
         )
         block = blocks.get_block(block_id, meta)
         if not block.bounding_box:
             continue
         transform_vectors = []
         for i, axis in enumerate(UNIT_VECTORS):
             axis_pen = check_axis(
                 axis, pos[i], pos[i] + self.bbox[i],
                 block_pos[i], block_pos[i] + block.bounding_box[i]
             )
             if not axis_pen:
                 break
             transform_vectors.append(axis_pen)
         else:
             return transform_vectors
     return [Vector3()]*3
示例#10
0
 def block_collision(self, pos):
     # This line is confusing. Basically it figures out how many block
     # coordinates the bounding box currently occupies. It's not clear what
     # "b" stands for so take your pick: Blocks, Bounds, how-Big-is-the-Box
     b = (pos + self.bbox).ceil() - pos.floor()
     for block_pos in gen_block_set(pos, *zip((0, -1, 0), b)):
         block = blocks.get_block(*self.world.get_block(*block_pos))
         if not block.bounding_box:
             continue
         transform_vectors = []
         for i, axis in enumerate(UNIT_VECTORS):
             axis_pen = check_axis(
                 axis, pos[i], pos[i] + self.bbox[i],
                 block_pos[i], block_pos[i] + block.bounding_box[i]
             )
             if not axis_pen:
                 break
             transform_vectors.append(axis_pen)
         else:
             return transform_vectors
     return [Vector3()]*3
示例#11
0
 def get_block_slip(self):
     if self.pos.on_ground:
         bpos = self.pos.floor()
         return blocks.get_block(*self.world.get_block(*bpos)).slipperiness
     return 1
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle == None:
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.

                blocknode.av["sti"] = 200
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace, "material", old_block_handle, 1)
                old_block_type = old_block_type_node.name
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = old_block_handle.av["sti"]
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    old_block_handle.av["sti"] = cur_sti
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)

                disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(
                blocknode, map_handle, False, False, block.ROStimestamp, block.x, block.y, block.z
            )
            if old_block_handle == None:
                self._time_server.add_time_info(blocknode, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link, block.MCtimestamp, "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """
示例#13
0
 def get_block(self, pos):
     block_id, meta = self.world.get_block(*pos.vector)
     return blocks.get_block(block_id, meta)
示例#14
0
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid,
                                              block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle.is_undefined():
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(
                    block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.
                self._atomspace.set_av(blocknode.h, 200)
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace,
                                                    "material",
                                                    old_block_handle, 1)
                old_block_type = self._atomspace.get_name(
                    old_block_type_node.h)
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = self._atomspace.get_av(old_block_handle)['sti']
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    self._atomspace.set_av(old_block_handle, cur_sti)
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace,
                                                     "disappeared",
                                                     old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(
                        block, map_handle)

                disappeared_link = add_predicate(self._atomspace,
                                                 "disappeared",
                                                 old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(blocknode.h, map_handle, False,
                                            False, block.ROStimestamp, block.x,
                                            block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h,
                                                block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp,
                                                "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h, block.ROStimestamp,
                                                "ROS")
                self._time_server.add_time_info(link.h, block.MCtimestamp,
                                                "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """
示例#15
0
 def get_block(self, pos):
     return blocks.get_block(*self.world.get_block(*pos))
示例#16
0
 def get_block_slip(self):
     if self.pos.on_ground:
         bpos = self.pos.floor()
         return blocks.get_block(*self.world.get_block(*bpos)).slipperiness
     return 1
示例#17
0
 def get_block(self, pos):
     return blocks.get_block(*self.world.get_block(*pos))