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


Python Helper.getAvailableChildren方法代码示例

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


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

示例1: calculate

# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import getAvailableChildren [as 别名]
def calculate(grid, maxdepth, is_it_max):
    if maxdepth == 0:
        return Helper.heuristic(grid)
    if not Helper.canMove(grid):
        return Helper.heuristic(grid)
    if is_it_max:
        v = -np.inf
        [children, moving] = Helper.getAvailableChildren(grid)
        for child in children:
            v = max(v,calculate(child,maxdepth-1,False))
        return v
    else:
        cells = [i for i, x in enumerate(grid) if x == 0]
        children = []
        v = np.inf
        for c in cells:
            gridcopy = list(grid)
            gridcopy[c]=2
            children.append(gridcopy)
            gridcopy = list(grid)
            gridcopy[c]=4
            children.append(gridcopy)
        for child in children:
            v = min(v,calculate(child,maxdepth-1,True))
        return v
开发者ID:ss4936,项目名称:2048,代码行数:27,代码来源:Minimax.py

示例2: getMove

# 需要导入模块: import Helper [as 别名]
# 或者: from Helper import getAvailableChildren [as 别名]
        def getMove(self, grid):
                mapgrid = []
                for i in range(4):
                        mapgrid.extend(grid.map[i])
                [children,moving] = Helper.getAvailableChildren(mapgrid)
                maxpath = -np.inf
                direction = 0
                print len(children),len(moving)
                for i in range(len(children)):
                        c = children[i]
                        emptyTiles = len([j for j, x in enumerate(c) if x == 0])
                        m = moving[i]
                        highest_value = -np.inf
                        selection = 2
##                        if selection == '1':
##                            maxdepth = 4
##                            highest_value = Minimax.calculate(c, maxdepth, False)
##                            if m == 0 or m == 2:
##                                highest_value += 10000
                        if selection == 2:
                            maxdepth = 4
                            highest_value = Minimaxab.calculate(c, maxdepth,-np.inf,np.inf, False)
                            if m == 0 or m == 2:
                                highest_value += 10000
                            print highest_value,c,m
                        if highest_value > maxpath:
                            direction = m
                            maxpath = highest_value
##                return int(raw_input())
                return direction
开发者ID:ss4936,项目名称:2048,代码行数:32,代码来源:PlayerAI.py


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