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


Python Group.getNeighbours方法代码示例

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


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

示例1: update

# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import getNeighbours [as 别名]
    def update(self,move):
        """
         Updates the board
        """
        movement=move.getListFormat()
        color = movement[0]
        posX = movement[1]
        posY = movement[2]
        
        pos=[posX, posY]
        
        if move.getColor() =='b':
            self.__board__[posX,posY] = 1
        else:
            self.__board__[posX,posY] = 2
            
        # history list update        
        self.__history__.append(movement)        
        
        
        # Store the metagroups attached to the last move: 
        flagMG = False
        bufferMG = []
        for MG in self.__metaGroupList__: 
            if (pos in MG.getBoundry()) and (color == MG.getColor()): 
                bufferMG += [self.__metaGroupList__.pop(self.__metaGroupList__.index(MG))]
        if len(bufferMG)>0: 
            flagMG = True
        #self.log.logDebug("meta-groups buffer: "+str(bufferMG))
        
        # create new "group"
        newGroup=Group(color,[posX,posY])
        
        # creating boundary for the new group 
        newBound=[]
        if pos[0]>0 and self.__board__[pos[0]-1,pos[1]]==0:
            newBound.append([pos[0]-1,pos[1]])
        if pos[0]<self.__size__-1 and self.__board__[pos[0]+1,pos[1]]==0 :
            newBound.append([pos[0]+1,pos[1]]) 
        if pos[1]>0 and self.__board__[pos[0],pos[1]-1]==0:
            newBound.append([pos[0],pos[1]-1])
        if pos[1]<18 and self.__board__[pos[0],pos[1]+1]==0:
            newBound.append([pos[0],pos[1]+1]) 
        
        # assign the boundary to the new group
        newGroup.setBoundAndLib(newBound)

        # checking joined boundaries and creating groups neighbors lists
        groups2join=[newGroup]    # groups to join with the new stone
        newNeighbours=[]          # groups which are neighbors to the new stone 
        
        # loop on all groups
        for group in self.__groupList__:
            
            # the current stone is in the boundary of a group
            if pos in group.getBoundry():  
                newBoundry=group.getBoundry()
                newBoundry.remove(pos)
                group.setBoundAndLib(newBoundry)
                 
                # the new stone is of the same color of the group
                if group.getColor()==color:
                    # there is a group to join
                    groups2join.append(group)
                else:
                    # the new stone is a neighbor of the group
                    newNeighbours.append(group)
                    
                # Check which groups from the MG are those which has 'move' in the boundary: 
                for MG in bufferMG: 
                    if group in MG.getGroups(): 
                        MG.getGroups().pop(MG.getGroups().index(group))
                
        # join the groups
        joinedBoundry=[]              # boundary
        joinedPos=[]                  # positions of the stones in the group
        joinedNeighbs=newNeighbours   # neighbors
        
        # loop over all groups to join
        for group in groups2join:
            joinedBoundry=joinedBoundry+[p for p in group.getBoundry() if p not in joinedBoundry] 
            joinedNeighbs=joinedNeighbs+[g for g in group.getNeighbours() if g not in joinedNeighbs] 
            joinedPos=joinedPos+group.getPos()
            if not group==newGroup:
                self.removeGroup(group)
        
        # set boundary, positions and neighbors of the new group
        newGroup.setBoundAndLib(joinedBoundry)
        newGroup.setPos(joinedPos)
        newGroup.addNeighb(joinedNeighbs)

        # append to the groups' list
        self.__groupList__.append(newGroup)
        
        # delete multiple neighbors from neighboring groups
        for group in joinedNeighbs:
            for g in groups2join:
                if g in group.getNeighbours():
                   group.delNeighb(g) 
            group.addNeighb([newGroup])
#.........这里部分代码省略.........
开发者ID:brigan,项目名称:rego,代码行数:103,代码来源:board.py


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