本文整理汇总了Python中GameState.GameState.postRotate方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.postRotate方法的具体用法?Python GameState.postRotate怎么用?Python GameState.postRotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameState.GameState
的用法示例。
在下文中一共展示了GameState.postRotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GreedySearchPercentageDepth
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import postRotate [as 别名]
#.........这里部分代码省略.........
if (moveValue > bestValue):
bestMove = move
bestValue = moveValue
return (bestMove, bestValue)
'returns the number of matches that a given move would make'
'this only determines value of one move and no further searching'
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
'returns the expected value of a given move searching with the given likelihood'
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
'generic methods of every solver'
def getScore(self):
return self.game.getScore()
def getMaxTile(self):
return self.game.getMaxTile()
def getMoves(self):
return self.numMoves
def printGame(self):
self.game.printState()
pass
示例2: RegionSearch
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import postRotate [as 别名]
class RegionSearch(object):
"""
classdocs
"""
def __init__(self, inDepth):
"""
Constructor
"""
self.game = GameState()
self.numMoves = 0
self.depth = inDepth
pass
"keeps searching for moves until the game is complete"
def playGame(self):
self.game.printState(self.game.gameArray)
count = 0
while self.game.isGoing():
print("\nStarting move: " + datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S"))
testBoard = self.game.copyArr()
bestMove = self.search(testBoard, self.depth)
print(bestMove[0])
# when at the end, all decisions might lead to an inevitable failure
if not self.game.isValid(bestMove):
pass
# self.game.printState(self.game.gameArray)
self.game.takeMove(bestMove[0])
self.game.printState(self.game.gameArray)
self.numMoves = self.numMoves + 1
print(self.numMoves)
pass
"returns best move and the value of that move"
"best move is only useful for the top-level call"
def search(self, board, depth):
if depth == 0:
return (Move.up, 0)
bestMove = Move.up
bestValue = -1
move = Move.up
moveValue = self.searchDirection(board, depth, move)
if moveValue > bestValue:
bestMove = move
bestValue = moveValue
move = Move.left
moveValue = self.searchDirection(board, depth, move)
if moveValue > bestValue:
bestMove = move
bestValue = moveValue
move = Move.right
moveValue = self.searchDirection(board, depth, move)
if moveValue > bestValue:
bestMove = move
bestValue = moveValue
move = Move.down
moveValue = self.searchDirection(board, depth, move)
if moveValue > bestValue:
bestMove = move
bestValue = moveValue
return (bestMove, bestValue)
"returns the number of matches that a given move would make"
"this only determines value of one move and no further searching"
def valueOfMove(self, board, move):
board = self.game.preRotate(move, board)
value = 0
for x in range(0, 4):
value += self.game.countSlideDownMatches(x, board)
board = self.game.postRotate(move, board)
return value
"returns the expected value of a given move searching with the given depth"
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
#.........这里部分代码省略.........