本文整理汇总了Python中Move.Move.__hash__方法的典型用法代码示例。如果您正苦于以下问题:Python Move.__hash__方法的具体用法?Python Move.__hash__怎么用?Python Move.__hash__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Move.Move
的用法示例。
在下文中一共展示了Move.__hash__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AIPlayer
# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import __hash__ [as 别名]
#.........这里部分代码省略.........
# Second: find the best possible move or explore
move = self.getBestMove(currentState)
self.PreviousMove = move
return move
##
# getBestMove
# Description:
# Given a current state, this method looks at all of the possible moves that can be made,
# If we role, and we get a number less than epsilon (the explore value) then we choose a random move
# Otherwise, we expand the move and get back what the state would look like if we took that move,
# we then compress this state, and see if that state is in our Memory.
# If it is in our memory, we see if it has the maximum util value of the other reachable states,
# if it is, then we update the maxUtil seen and set the move to return to the move associated with
# getting to that state.
# If it is not in our memory we skip it.
# If at the end, we have not found any states that match in our memory, make a random move.
#
# Parameter: CurrentState - an uncompressed state that is the current state that the AI is in.
# Return:
# move - The best move according to what we've learned OR a random move based on epsilon values.
##
def getBestMove(self, currentState):
# get all possible moves.
moves = listAllLegalMoves(currentState)
move = None
compressedCurState = self.consolidateState(currentState)
#current State Hash
stateHash = str(compressedCurState.__hash__())
role = random.random()
# if less than epsilon, explore via random move
if(role < self.epsilon):
move = moves[random.randint(0, len(moves) - 1)]
elif(move == None):
maxUtil = 0
for posMove in moves:
key = str(posMove.__hash__())
#if that state is in the dictionary
if key in self.stateUtilityMemory[stateHash]:
# get that states util
# this is done by getting the average score for that state.
keyUtil = self.stateUtilityMemory[stateHash][key][UTILITY_INDEX]
# if it's the best util we've seen set the move equal to that move, and update the maxUtil
if keyUtil > maxUtil:
maxUtil = keyUtil
move = posMove
# if for some reason the move is still none, get a random move
# this could occur if we haven't seen any of the states that the moves could give us.
if(move is None):
move = moves[random.randint(0, len(moves) - 1)]
return move
##
# updateMemory
# Description: