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


Python GameState.executeMove方法代码示例

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


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

示例1: valueOfMove

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
 def valueOfMove(self, board, move):
     board = self.game.preRotate(move, board)
     testGame = GameState()
     testGame.setBoard(board)
     testGame.setBoard(testGame.copyArr())
     value = 0
     
     # store previous information
     oldScore = testGame.getScore()
     oldMaxTile = testGame.getMaxTile()
     
     testGame.executeMove(Move.down)
     newScore = testGame.getScore()
     value += newScore - oldScore
     
     # check if the largest tile is in a corner after the move
     newMaxTile = testGame.getMaxTile()
     for corner in self.fourCorners:
         if testGame.gameArray[corner[0]][corner[1]] == newMaxTile:
             value *= self.maxInCornerMultiplier
             value += self.cornerBonusScaledByMax * newMaxTile
             value += self.enterCorner
     
     # penalty for moving down
     if move == Move.down:
         value -= self.moveDownPenalty * newMaxTile
     
     board = self.game.postRotate(move, board)
     return value
开发者ID:greengatz,项目名称:senior_project,代码行数:31,代码来源:GreedySearchPercentageDepth.py

示例2: estimateValue

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
 def estimateValue(self, depth, board, move):
     ev2 = [[0 for x in range(4)] for x in range(4)]
     ev4 = [[0 for x in range(4)] for x in range(4)]
     ev = 0
     numOptions = 0
     
     # go through all options
     if(self.game.isValid(move)): 
         baseGameUp = GameState()
         baseGameUp.setBoard(board)
         baseGameUp.executeMove(move)
         
         for x in range (0, 4):
             for y in range (0, 4):
                 if(baseGameUp.gameArray[x][y] == 0):
                     numOptions += 2
                     
                     # per cell ev expecting 4
                     pretendBoard2 = baseGameUp.copyArr()
                     pretendGame2 = GameState()
                     pretendBoard2[x][y] = 2
                     pretendGame2.setBoard(pretendBoard2)
                     searchEv = self.startSearch(pretendGame2.copyArr(), depth - 1)
                     ev2[x][y] = searchEv[1]
                     pretendGame4 = None
                 
                     # per cell ev expecting 4
                     pretendBoard4 = baseGameUp.copyArr()
                     pretendGame4 = GameState()
                     pretendBoard4[x][y] = 4
                     pretendGame4.setBoard(pretendBoard4)
                     searchEv = self.startSearch(pretendGame4.copyArr(), depth - 1)
                     ev4[x][y] = searchEv[1]
                     pretendGame4 = None
                 
                     pass
     return ev
开发者ID:greengatz,项目名称:senior_project,代码行数:39,代码来源:SearchSolver.py

示例3: searchDirection

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
 def searchDirection(self, board, depth, move):
     testGame = GameState()
     testGame.setBoard(board)
     testGame.setBoard(testGame.copyArr())
     
     # if the move isn't valid, don't consider it
     if (not testGame.isValid(move)):
         return -1
     
     # determine the value for making the move at this level
     ourValue = self.valueOfMove(testGame.gameArray, move)
     
     # if we have reached bottom depth, stop searching and return the heuristic value
     if depth == 1:
         return ourValue
     
     # using that as the starting board, check a lot of possibilities
     afterMove = testGame.executeMove(move)
     testGame.setBoard(afterMove)
     ev2 = [[0 for x in range(4)] for x in range(4)]
     ev4 = [[0 for x in range(4)] for x in range(4)]
     
     options = 0
     searchValue = 0
     
     # determine the value of each cell
     for x in range (0, 4):
         for y in range (0, 4):
             trialBoard = testGame.copyArr()
             if (trialBoard[x][y] == 0):
                 options += 1
                 
                 trialBoard[x][y] = 2
                 ev2[x][y] = self.search(trialBoard, depth - 1)[1]
                 
                 trialBoard[x][y] = 4
                 ev4[x][y] = self.search(trialBoard, depth - 1)[1]
                 trialBoard[x][y] = 0
     
     
     # adjust those cells for their likelihood
     for x in range (0, 4):
         for y in range (0, 4):
             searchValue += (ev2[x][y] * 0.9) / options
             searchValue += (ev4[x][y] * 0.1) / options
     
     return ourValue + searchValue
开发者ID:greengatz,项目名称:senior_project,代码行数:49,代码来源:GreedySearch.py

示例4: searchDirection

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
 def searchDirection(self, board, depth, move):
     testGame = GameState()
     testGame.setBoard(board)
     testGame.setBoard(testGame.copyArr())
     
     # if the move isn't valid, don't consider it
     if (not testGame.isValid(move)):
         return -1
     
     # determine the value for making the move at this level
     ourValue = self.valueOfMove(testGame.gameArray, move)
     
     # using that as the starting board, check the child's options
     afterMove = testGame.executeMove(move)
     searchValue = self.search(afterMove, depth - 1)[1]
     
     return ourValue + searchValue
开发者ID:greengatz,项目名称:senior_project,代码行数:19,代码来源:GreedySearchNoRandom.py

示例5: searchDirection

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
 def searchDirection(self, board, likelihood, move, depth):
     testGame = GameState()
     testGame.setBoard(board)
     testGame.setBoard(testGame.copyArr())
     
     # if the move isn't valid, don't consider it
     if (not testGame.isValid(move)):
         return -1
     
     #determine the value for making the move at this level
     ourValue = self.valueOfMove(testGame.gameArray, move)
     
     #'using that as the starting board, check a lot of possibilities'
     afterMove = testGame.executeMove(move)
     testGame.setBoard(afterMove)
     ev2 = [[0 for x in range(4)] for x in range(4)]
     ev4 = [[0 for x in range(4)] for x in range(4)]
     
     options = 0
     searchValue = 0
     
     # determine which cells can have a new tile
     trialBoard = testGame.copyArr()
     for x in range (0, 4):
         for y in range (0, 4):
             if (trialBoard[x][y] == 0):
                 options += 1
     
     # determine the value of each cell
     for x in range (0, 4):
         for y in range (0, 4):
             trialBoard = testGame.copyArr()
             if (trialBoard[x][y] == 0):
                 cellChance = likelihood / options
                 
                 trialBoard[x][y] = 2
                 ev2[x][y] = cellChance * 0.9 * self.search(trialBoard, likelihood * cellChance * 0.9, depth)[1]
                 trialBoard[x][y] = 0
                 
                 trialBoard[x][y] = 4
                 ev4[x][y] = cellChance * 0.9 * self.search(trialBoard, likelihood * cellChance * 0.1, depth)[1]
                 trialBoard[x][y] = 0
     
     return ourValue + searchValue
开发者ID:greengatz,项目名称:senior_project,代码行数:46,代码来源:GreedySearchPercentageDepth.py

示例6: searchDirection

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import executeMove [as 别名]
    def searchDirection(self, board, depth, move):
        testGame = GameState()
        testGame.setBoard(board)
        testGame.setBoard(testGame.copyArr())

        # if the move isn't valid, don't consider it
        if not testGame.isValid(move):
            return -1

        # determine the value for making the move at this level
        ourValue = self.valueOfMove(testGame.gameArray, move)

        #'using that as the starting board, check a lot of possibilities'
        afterMove = testGame.executeMove(move)
        testGame.setBoard(afterMove)

        options = 0
        searchValue = 0

        # arrays
        ev2 = [[0 for x in range(2)] for x in range(2)]
        ev4 = [[0 for x in range(2)] for x in range(2)]
        optionsInRegion = [[0 for x in range(2)] for x in range(2)]

        # determine value of the region
        for x in range(0, 2):  # location of region
            for y in range(0, 2):
                trialBoard = testGame.copyArr()
                validLocs = []
                for rx in range(0, 2):  # location within region
                    for ry in range(0, 2):
                        locX = (x * 2) + rx
                        locY = (y * 2) + ry

                        # take all 0s into account for likelihood
                        if trialBoard[locX][locY] == 0:
                            optionsInRegion[x][y] += 1
                            options += 1
                            validLocs += [(locX, locY)]

                # find a cell in the region to test
                possibilities = optionsInRegion[x][y]
                for loc in validLocs:
                    rand = randrange(0, 100)

                    # randomly select one cell in the region to care about
                    if rand < ((1 / possibilities) * 100):  # test whether or not this is the cell we care about
                        trialBoard[loc[0]][loc[1]] = 2
                        ev2[x][y] = self.search(trialBoard, depth - 1)[1]

                        trialBoard[loc[0]][loc[1]] = 4
                        ev4[x][y] = self.search(trialBoard, depth - 1)[1]
                        trialBoard[loc[0]][loc[1]] = 0
                        break
                    possibilities -= 1

                # reset our locations for the next region
                validLocs.clear()

        # adjust those region evs for their likelihood
        for x in range(0, 2):
            for y in range(0, 2):
                searchValue += (ev2[x][y] * 0.9) * (optionsInRegion[x][y] / options)
                searchValue += (ev4[x][y] * 0.1) * (optionsInRegion[x][y] / options)

        return ourValue + searchValue
开发者ID:greengatz,项目名称:senior_project,代码行数:68,代码来源:RegionSearch.py


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