コード例 #1
0
ファイル: skypoint.cpp プロジェクト: Bugsbane/kstars
bool SkyPoint::bendlight() {

    // NOTE: This should be applied before aberration
    // NOTE: One must call checkBendLight() before unnecessarily calling this.
    // We correct for GR effects

    // NOTE: This code is buggy. The sun needs to be initialized to
    // the current epoch -- but we are not certain that this is the
    // case. We have, as of now, no way of telling if the sun is
    // initialized or not. If we initialize the sun here, we will be
    // slowing down the program rather substantially and potentially
    // introducing bugs. Therefore, we just ignore this problem, and
    // hope that whenever the user is interested in seeing the effects
    // of GR, we have the sun initialized correctly. This is usually
    // the case. When the sun is not correctly initialized, rearth()
    // is not computed, so we just assume it is nominally equal to 1
    // AU to get a reasonable estimate.
    Q_ASSERT( m_Sun );
    double corr_sec = 1.75 * m_Sun->physicalSize() / ( ( std::isfinite( m_Sun->rearth() ) ? m_Sun->rearth() : 1 ) * AU_KM * angularDistanceTo( static_cast<const SkyPoint *>(m_Sun) ).sin() );
    Q_ASSERT( corr_sec > 0 );

    SkyPoint sp = moveAway( *m_Sun, corr_sec );
    setRA(  sp.ra() );
    setDec( sp.dec() );
    return true;
}
コード例 #2
0
ファイル: skypoint.cpp プロジェクト: monisha4/kstars-hackfest
bool SkyPoint::bendlight() {

    // NOTE: This should be applied before aberration
    // NOTE: One must call checkBendLight() before unnecessarily calling this.
    // We correct for GR effects
    Q_ASSERT( m_Sun );
    double corr_sec = 1.75 * m_Sun->physicalSize() / ( m_Sun->rearth() * AU_KM * angularDistanceTo( static_cast<const SkyPoint *>(m_Sun) ).sin() );
    Q_ASSERT( corr_sec > 0 );

    SkyPoint sp = moveAway( *m_Sun, corr_sec );
    setRA(  sp.ra() );
    setDec( sp.dec() );
    return true;
}
コード例 #3
0
ファイル: Project.c プロジェクト: ruffsl/ECE425
void CBOT_main( void )
{
	// Initialize variables
	int btnValue=0;//value of button pushed
	int i=0;//loop counter

	BOOL	ltContact;//left contact sensor
	BOOL	rtContact;//right contact sensor


	float	ltLght;//left light reading
	float	rtLght;//right light reading

	unsigned char data;
	unsigned char pixel1 = 0;
	unsigned char pixel2 = 0;
	unsigned char pixel3 = 0;
	unsigned char pixel4 = 0;
	unsigned char pixel5 = 0;
	unsigned char pixel6 = 0;
	unsigned char pixel7 = 0;
	unsigned char pixel8 = 0;

	ATopstat = ATTINY_open();//open the tiny microcontroller
	LEopstat = LED_open(); //open the LED module
	LCopstat = LCD_open(); //open the LCD module
	STEPPER_open(); // Open STEPPER module for use.
	SPKR_open(SPKR_BEEP_MODE);//open the speaker in beep mode
	
	LED_open();
	I2C_open();
	ADC_open();//open the ADC module
 	ADC_set_VREF( ADC_VREF_AVCC );// Set the Voltage Reference first so VREF=5V.

	
	btnValue = WaitButton();

	// Infinite loop
	while (1)
    {
	// check sensors
	//checkIR();
	// if no obstacle detected MOVE
	// if obstacle detected STOP
	// moveCollide();
	moveAway();
		
    }
}// end the CBOT_main()
コード例 #4
0
ファイル: WallFollow_LightTrack.c プロジェクト: ruffsl/ECE425
/*******************************************************************
* Function:			char moveBehavior (int)
* Input Variables:	int
* Output Return:	char
* Overview:		    This is the flow for the behavior of the robot
********************************************************************/
char moveBehavior( int behavior)
{
	// Check the moveAway behavior for obstacles
	if(moveAway()){
		Ierror = 0;
		return 1; 
	}
	
	// Check the moveLight behavior for light. 
	// If it sees light track the light. 
	// If it is in front of the light kill moveLight and move to moveRetreat
	if(lightFlagStatus==0){
		if(moveTrackLight()){
			Ierror = 0;
			return 2;
		}
	}
	
	// Check the moveRetreat behavior.
	// If it returns a zero (contacts detect obstacle) have it stop itself and inhibit moveWall
	if(retreatFlagStatus==1){
		if(moveRetreat()){
			Ierror = 0;
			return 3;
		}
	}
	
	// Run the moveWall behavior
	if(moveWall()){
		Ierror = 0;
		return 4;
	}
	
	// if(moveWander()){
		// Ierror = 0;
		// return 5;
	// }

	return 0;	
}
コード例 #5
0
ファイル: NpcMovementObject.cpp プロジェクト: slumki/Gameka
int NpcMovementObject::update(int dt) {

	if(AcceleratedParticle::update(dt) == -1) {
		return -1;
	}


	switch(movementType) {
	case PARADO:

		break;
	case SEGUE_PERSONAGEM:
		if(playerData->getPlayer() != NULL) {
			follow(*playerData->getPlayer()->position, dt);
		}

		break;
	case FOGE_PERSONAGEM:
		moveAway(*playerData->getPlayer()->position, dt);
		break;
	case MOVE_ESQUERDA_DIREITA:
		velocity->y = 0;
		//position->addScaledVector(velocity, dt);
		if(position->x > gameObjectInstance->x + movementRadius) {
			position->x = gameObjectInstance->x + movementRadius - 2;
			direction = -1;
			velocity->x = - gameObjectInstance->gameObject->vx/250.0f;
		} else if(position->x < gameObjectInstance->x - movementRadius) {
			position->x = gameObjectInstance->x - movementRadius + 1;
			direction = 1;
			velocity->x = + gameObjectInstance->gameObject->vx/250.0f;
		}

		break;
	case MOVE_CIMA_BAIXO:
		position->addScaledVector(velocity, dt);
		if(position->y > gameObjectInstance->y + movementRadius) {
			position->y = gameObjectInstance->y + movementRadius - 1;
			direction = -1;
			velocity->y = - gameObjectInstance->gameObject->vx/250.0f;
		} else if(position->y < gameObjectInstance->y - movementRadius) {
			position->y = gameObjectInstance->y - movementRadius + 1;
			direction = 1;
			velocity->y = + gameObjectInstance->gameObject->vx/250.0f;
		}

		break;
	case MOVIMENTO_CIRCULAR:
		movementAngle += angularVelocity*dt;
		if(movementAngle > 2*M_PI) {
			movementAngle = 0;
		}


		this->position->x = gameObjectInstance->x + sin(movementAngle)*movementRadius;
		this->position->y = gameObjectInstance->y + cos(movementAngle)*movementRadius;



		break;
	}

	if(!(velocity->y == 0 && velocity->x == 0)) {
		angle = atan((velocity->x/velocity->y));
		if(velocity->y < 0) {
			angle += M_PI;
		}
	}

	if(playerData->getPlayer() != NULL) {
		if(playerData->getPlayer()->collidesWith(this)){
			if(inputManager->isKeyPressed(SDLK_z) || inputManager->isKeyPressed(SDLK_SPACE)) {
				if(this->gameObjectInstance->dialogueData != NULL) {
					modalManager->pushModal(new DialogueText(this->gameObjectInstance->dialogueData, DialogueText::POS_DOWN, dt));
				}
			}
		}
	}

	setSpriteDirectionAngle((360 - (angle*180/M_PI + 270)));

	return 0;
}
コード例 #6
0
ファイル: reserve.c プロジェクト: shepheb/kernel
// reservation server protocol:
// send a MSG_RESERVE_REQUEST with the list of nodes you want to reserve
// if blocking, you'll block until the nodes are all available, at which point you'll get an ok
// if non-blocking, you'll immediately either get an ok or a fail, depending on whether the request is satisfiable
// when you want to unreserve, send a MSG_RESERVE_RELEASE with the nodes you want to release; you'll get NOTHING BACK
void reservation_server(void) {

	// allocate a list of blocked tasks and the requests they made
	BlockList bl[MAX_ENGINEERS];
	// initialize all of the bl elements to invalid
	int blIndex;
	for (blIndex=0; blIndex<MAX_ENGINEERS; blIndex++) {
		bl[blIndex].tid = -1; // tid == -1 means invalid
	}


	// deadlock detection algorithm:
	// * maintain hold list (hl) in addition to bl.
	// * accomodateRequest also returns a list of engineers I'm waiting on
	// * if I do need to block, this list is necessarily non-empty
	// * then check the block lists for these same engineers and see if they're blocked on anything I hold
	// * if so, that's a deadlock.
	// but there's no way I can implement this tonight.


	RegisterAs("reservationserver");

	FOREVER {

		// receive buffers
		int tid;
		MsgReservation request;
		MsgReservation reply;

		Receive(&tid, (char *)&request, sizeof(MsgReservation));

		switch(request.type) {

			case MSG_RESERVE_REQUEST_BLOCKING: ;
				Node *rcNode = resConflict(request.numNodes, request.nodes, tid);
				if (rcNode == NULL) { // if the request can be accomodated, log it
					logReservation(request.numNodes, request.nodes, tid, request.iAmPacman, request.trainNum, request.curDir);
				} else { // else if the request cannot be accomodated
					// deadlock detection

					printf0("Res Serv.: Checking for deadlock...\n\r");

					// the tid of the task that currently has this reservation
					int otherTid = (rcNode->type == NODE_SWITCH) ? ((Switch *)(rcNode))->reserverTid : ((Sensor *)(rcNode))->reserverTid;
					int blIndex = findTidInBlockList(otherTid, bl);

					printf2("Res Serv.: otherTid: %d, otherIsblocked? %d!\n\r", otherTid, blIndex != -1);

					// if this other tid is blocked and wants a node we own, that's a deadlock
					if (blIndex != -1 && blWantsNodeHeldBy(bl[blIndex], tid)) {

						// we now know we have a deadlock, so it's time to resolve it
						printf2("Res Serv.: DEADLOCK between tr. %d and tr. %d!\n\r", request.trainNum, bl[blIndex].trainNum);

						// if we're the pacman or
						// the other one isn't a pacman and we have the lower train number
						if (request.iAmPacman ||
							(!((rcNode->type == NODE_SWITCH) ? ((Switch *)rcNode)->reserverIAmPacman : ((Sensor *)rcNode)->reserverIAmPacman)
								&& (request.trainNum <= ((rcNode->type == NODE_SWITCH) ? ((Switch *)rcNode)->reserverTrainNum : ((Sensor *)rcNode)->reserverTrainNum) ))) {

							// find a node to move to
							Node *nodeToMoveTo = moveAway(request.trainLoc, request.curDir == 'F' ? 'B' : 'F');

							printf1("Res Serv.: GTFO self (train %d) to ", request.trainNum);
							if (nodeToMoveTo == NULL) {
								printf0("NULL");
							} else {
								printNode2(nodeToMoveTo);
							}
							printf1(", curDir %c!\n\r", (int)request.curDir);

							if (nodeToMoveTo == NULL) { // if we can't move away, it's the game over case
								printf0("res. serv.: case 1.\n\r");

								int pacmanServerTid = WhoIs("pacmanserver");
								char c = MSG_PACMAN_GAMEOVER;
								int retVal = Send(pacmanServerTid, &c, 1, NULL, 0);
								printf1("res. serv.: retVal from Reply to PMS: %d\n\r", retVal);

								reply.type = MSG_RESERVE_GAMEOVER;
								retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								int i;
								for (i=0; i<MAX_ENGINEERS; i++) {
									if (bl[i].tid != -1) {
										reply.type = MSG_RESERVE_GAMEOVER;
										retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
										printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
									}
								}
							} else { // else if we can move away, send the move reply
								reply.type = MSG_RESERVE_MOVE;
								reply.numNodes = 1;
								reply.nodes[0] = nodeToMoveTo;
								printf0("res. serv.: about to reply case 2.\n\r");
								int retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
							}

						} else { // else the other train needs to move out of the way

							// find a node to move to
							Node *nodeToMoveTo = moveAway(bl[blIndex].trainLoc, bl[blIndex].curDir == 'F' ? 'B' : 'F');

							printf1("Res Serv.: GTFO other (train %d) to ", bl[blIndex].trainNum);
							if (nodeToMoveTo == NULL) {
								printf0("NULL");
							} else {
								printNode2(nodeToMoveTo);
							}
							printf1(", curDir %c!\n\r", (int)bl[blIndex].curDir);

							if (nodeToMoveTo == NULL) { // if we can't move away, it's the game over case
								printf0("res. serv.: case 1.\n\r");

								int pacmanServerTid = WhoIs("pacmanserver");

								char c = MSG_PACMAN_GAMEOVER;
								int retVal = Send(pacmanServerTid, &c, 1, NULL, 0);
								printf1("res. serv.: retVal from Reply to PMS: %d\n\r", retVal);

								reply.type = MSG_RESERVE_GAMEOVER;
								retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								int i;
								for (i=0; i<MAX_ENGINEERS; i++) {
									if (bl[i].tid != -1) {
										reply.type = MSG_RESERVE_GAMEOVER;
										retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
										printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
									}
								}

							} else { // else if we can move away, send the move reply

								reply.type = MSG_RESERVE_MOVE;
								reply.numNodes = 1;
								reply.nodes[0] = nodeToMoveTo;
								printf0("res. serv.: about to reply case 2.\n\r");
								int retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								// remove the other train from the block list, since he's no longer going to be blocked
								bl[blIndex].tid = -1;

								// now, block the current train, waiting for the other one to get ouf of the way
								blockTask(tid, request.iAmPacman, request.trainNum, request.trainLoc, request.curDir, request.numNodes, request.nodes, bl);
							}
						}

					} else { // else if it's not a deadlock, just a reservation conflict, handle it normally by blocking
						blockTask(tid, request.iAmPacman, request.trainNum, request.trainLoc, request.curDir, request.numNodes, request.nodes, bl);
					}
				}
				break;
			case MSG_RESERVE_REQUEST_NONBLOCKING:
				if (resConflict(request.numNodes, request.nodes, tid) == NULL) { // if the request can be accomodated, log it and reply
					logReservation(request.numNodes, request.nodes, tid, request.iAmPacman, request.trainNum, request.curDir);
					reply.type = MSG_RESERVE_OK;
					Reply(tid, (char *)&reply, sizeof(MsgReservation));
				} else { // else if the request cannot be accomodated, send a fail message back
					reply.type = MSG_RESERVE_FAIL;
					Reply(tid, (char *)&reply, sizeof(MsgReservation));
				}
				break;
			case MSG_RESERVE_RELEASE:
				logRelease(request.numNodes, request.nodes, request.trainNum); // log the release
				Reply(tid, NULL, 0); // reply with a NULL buffer
				// now, check if any waiting task can now be awoken due to the release
				for (blIndex = 0; blIndex<MAX_ENGINEERS; blIndex++) {
					// if the bl entry is valid and we can now accomodate it, do so
					if (bl[blIndex].tid != -1 && resConflict(bl[blIndex].numNodes, bl[blIndex].nodes, bl[blIndex].tid) == NULL) {
						// log the reservation
						logReservation(bl[blIndex].numNodes, bl[blIndex].nodes, bl[blIndex].tid, bl[blIndex].iAmPacman, bl[blIndex].trainNum, bl[blIndex].curDir);
						// reply to the task, telling it the reserve has finally been processed
						reply.type = MSG_RESERVE_OK;
						Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
						// ...and invalidate its entry in the block list
						bl[blIndex].tid = -1;
					}
				}
				break;
			default:
				bwprintf(COM2, "ERROR: illegal reservation request type %d! Halt!!!", request.type);
				Halt();
				break;
		} // switch
	} // FOREVER

	return; // can't happen due to above FOREVER loop
}
コード例 #7
0
void ZerglingMicro::micro(BWAPI::Unit* unit)
{
	Task task = this->hc->ta->getTaskOfUnit(unit);
	
	UnitGroup allies = allEigenUnits().inRadius(dist(12), unit->getPosition());
	UnitGroup enemiesground = allEnemyUnits().inRadius(dist(10), unit->getPosition()).not(isFlyer);
	UnitGroup enemiesair = allEnemyUnits().inRadius(dist(7), unit->getPosition())(isFlyer);
	if(amountCanAttackGround(enemiesair) > 0 && amountCanAttackAir(allies) == 0)
	{
		unit->move(moveAway(unit));
	}
	else
	{
		if(task.getType() == ScoutTask)
		{
			if(allEnemyUnits().not(isBuilding).inRadius(dist(4), unit->getPosition()).size() > 0)
			{
				unit->move(moveAway(unit));
			}
			else
			{
				if(unit->getDistance(task.getPosition()) < dist(4) && BWAPI::Broodwar->isVisible(BWAPI::TilePosition(task.getPosition())))
				{
					if(!unit->isMoving())
					{
						int x = unit->getPosition().x();
						int y = unit->getPosition().y();
						int factor = dist(10);
						int newx = x + (((rand() % 30)-15)*factor);
						int newy = y + (((rand() % 30)-15)*factor);
						unit->move(BWAPI::Position(newx, newy).makeValid());
					}
				}
				else
				{
					unit->move(task.getPosition());
				}
			}
		}
		else
		{
			UnitGroup swarms = allUnits()(Dark_Swarm);
			BWAPI::Unit* swarm = getNearestUnit(unit->getPosition(), swarms);
			if(swarm != NULL && swarm->getPosition().getDistance(unit->getPosition()) < dist(9))
			{
				if(!isUnderDarkSwarm(unit) && !unit->isAttacking())
				{
					unit->attack(swarm->getPosition());
				}
				else
				{
					UnitGroup enemiesunderswarm = allEnemyUnits().inRadius(dist(6), unit->getPosition()).not(isFlyer);
					if(!unit->isAttacking() && enemiesunderswarm.size() > 0)
					{
						unit->attack(getNearestUnit(unit->getPosition(), enemiesunderswarm));
					}
				}
			}
			else
			{
				if(allies.size() < amountCanAttackGround(enemiesground))
				{
					unit->move(moveAway(unit));
				}
				else
				{
					if(enemiesground.inRadius(dist(3), unit->getPosition()).size() > 0)
					{
						// game AI
					}
					else
					{
						if(enemiesground.size() > 0)
						{
							BWAPI::Unit* nearest = getNearestUnit(unit->getPosition(), enemiesground);
							unit->attack(nearest);
						}
						else
						{
							UnitGroup* ug = this->hc->eiugm->getGroupOfUnit(unit);
							if(ug != NULL && tooSplitUp(dist(7), *ug))
							{
								BWAPI::Unit* nearest = getNearestUnit(ug->getCenter(), *ug);
								unit->attack(nearest);
							}
							else
							{
								unit->move(task.getPosition());
							}
						}
					}
				}
			}
		}
	}
}