コード例 #1
0
	def recursiveMiniMax(self, rootNodeObject=None):
                originalNode = deepcopy(rootNodeObject)
		
		if rootNodeObject.currentDepthOfNode < self.cutOffDepth:
			
			childNode = None
			for i in range(5):
				for j in range(5):
					if rootNodeObject.occupied_positions[i][j] == "*":
						
						pos = Position(i, j)
						#print pos,"RAKESH"
						if rootNodeObject.playMax == True:
							
                                                        rootNodeObject.occupied_positions = deepcopy(originalNode.occupied_positions)
							childNode = nextmin(rootNodeObject, rootNodeObject.value,rootNodeObject.occupied_positions, rootNodeObject.player, rootNodeObject.opponentPlayer, self.negative, rootNodeObject.currentDepthOfNode+1, False, [], rootNodeObject.value[i][j], pos, self.cutOffDepth)
						else:
							
                                                        rootNodeObject.occupied_positions = deepcopy(originalNode.occupied_positions)
							childNode = nextmin(rootNodeObject, rootNodeObject.value,rootNodeObject.occupied_positions, rootNodeObject.player, rootNodeObject.opponentPlayer, self.positive, rootNodeObject.currentDepthOfNode+1, True, [], rootNodeObject.value[i][j], pos, self.cutOffDepth)
						
						rootNodeObject.childNodes.append(childNode)
						self.recursiveMiniMax(childNode)
						print rootNodeObject

			
			if rootNodeObject.playMax == True:
				if rootNodeObject.parentNode != None:
					if rootNodeObject.parentNode.currentEvalFunction < rootNodeObject.currentEvalFunction:
						rootNodeObject.parentNode.currentEvalFunction = rootNodeObject.currentEvalFunction
						rootNodeObject.parentNode.bestChild = rootNodeObject.currentPosition
						
			else:
				
				if rootNodeObject.parentNode != None:
					if rootNodeObject.parentNode.currentEvalFunction >= rootNodeObject.currentEvalFunction:
						rootNodeObject.parentNode.currentEvalFunction = rootNodeObject.currentEvalFunction
						rootNodeObject.parentNode.bestChild = rootNodeObject.currentPosition
						
		return rootNodeObject
コード例 #2
0
	def __init__(self, value,occupied_positions, playerValue, opponentPlayerValue, cutOffDepthValue):
		self.gridBoxCell = []
		self.value=value
                self.occupied_positions=occupied_positions
		self.player = playerValue
		self.opponentPlayer = opponentPlayerValue
		self.cutOffDepth = cutOffDepthValue
		
                aaa=evaluation(self.value,self.occupied_positions,self.player,self.opponentPlayer)
                self.rootEvalFunction=aaa.eval()
                  
		
		self.negative = -100000
		self.positive = 100000
		self.bestRootNode = None
		print "Node,Depth,Value"
		self.rootNode = nextmin(None,value,occupied_positions, playerValue, opponentPlayerValue, self.negative, 0, False, [], self.negative, None, cutOffDepthValue)