コード例 #1
0
PilotAction OrbitalPilot::getCourse(SimFrame *frame, int depth)
{
	PilotAction bestAction;
	bestAction.score = evaluateAction(frame, NULL_ACTION, depth);
	if(frame->deltaV() == 0)
		return bestAction;

	//double horizonAngle = atan2( frame->position.x, frame->position.y) + PI/2;

	// search state space for optimal throttle value
	//double throttle = 1.0;
	for(double throttle = frame->config->params.throttleStep; throttle <= 1.0; throttle += frame->config->params.throttleStep)
	{
		// search state space for optimal orientation
		for(double angle = 0.0; angle < 2*PI; angle += frame->config->params.radialStep)
		{
			glm::dvec2 orientation( sin(angle), cos(angle) );

			PilotAction a = {orientation, throttle, 0.0};

			// anticipate consequences
			a.score = evaluateAction(frame, a, depth);

			// select best outcome
			if(frame->time == 0 && depth == frame->config->params.searchDepth){
				double angle = acos( glm::dot(a.orientation, glm::dvec2(frame->position.y, -frame->position.x))
					/ glm::length(frame->position) ) * 180/PI;

				printf("testing %.2lf, %.2lf -> %lf against %lf\n", a.throttle, angle, a.score, bestAction.score);
			}
			if(a.score < bestAction.score){
				if(frame->time == 0 && depth == frame->config->params.searchDepth)
					printf("new best score: %lf\n", a.score);
				bestAction = a;
			}
		}

	}

	if(depth == frame->config->params.searchDepth){
		double angle = acos( glm::dot(bestAction.orientation, glm::dvec2(frame->position.y, -frame->position.x))
			/ glm::length(frame->position) ) * 180/PI;
		printf("[%.2lf] %.2lf, %.2lf -> %lf\n", frame->time, bestAction.throttle, angle, bestAction.score);
	}

	return bestAction;
}
コード例 #2
0
ファイル: states.c プロジェクト: ecalot/princed
/* Evaluates a state: all conditions for all actions until a true is found and returns the next state id*/
int evaluateState(int state, tKey* key, tObject* kid, tRoom* room) {
	int i=state;
	while (!evaluateAction(i,key,kid,room)) i++;
	return i;
}