Ejemplo n.º 1
0
	// recursive function which does all search logic
	void DFBBMonteCarlo(StarcraftStateType & s, int depth)
	{		
	    
		printf("Depth %d\n", depth);
	
		// increase the node expansion count
		nodesExpanded++;
		
		
		// the time at which the last thing in the queue will finish
		int finishTime = s.getLastFinishTime();
		
		if (finishTime >= upperBound)
		{
		    return;
		}
		
		int bucket = getBucket(finishTime);
		int armyValue = s.getArmyValue();
		
		if (armyValue > armyValues[bucket])
		{
		    armyValues[bucket] = armyValue;
		    buildOrders[bucket] = getBuildOrder(s);
		}
		
		// if we are using search timeout and we are over the limit
		if (params.searchTimeLimit && (nodesExpanded % 1000 == 0) && (searchTimer.getElapsedTimeInMilliSec() > params.searchTimeLimit))
		{
			// throw an exception to unroll the recursion
			throw 1;
		}
		
		// get the legal action set
		ActionSet legalActions = s.getLegalActionsMonteCarlo(params.goal); 

		// if we have children, update the counter
		if (!legalActions.isEmpty())
		{
			numGenerations += 1;
			numChildren += legalActions.numActions();
			
			Action nextAction = legalActions.randomAction();
			
			StarcraftStateType child(s);
				
			int readyTime = child.resourcesReady(nextAction); 
			child.doAction(nextAction, readyTime);
			child.setParent(&s);
			DFBBMonteCarlo(child, depth+1);
		}
		else
		{
		    printf("No legal actions %d\n", depth);
		}
	}