コード例 #1
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
void
IPCP::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
{
	TRACE("IPCP: RCRBadEvent() state=%d\n", State());
	
	switch(State()) {
		case PPP_OPENED_STATE:
			NewState(PPP_REQ_SENT_STATE);
			SendConfigureRequest();
		
		case PPP_ACK_SENT_STATE:
			if(State() == PPP_ACK_SENT_STATE)
				NewState(PPP_REQ_SENT_STATE);
					// OPENED_STATE might have set this already
		
		case PPP_INITIAL_STATE:
		case PPP_REQ_SENT_STATE:
		case PPP_ACK_RCVD_STATE:
			if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3)
				SendConfigureNak(nak);
			else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3)
				SendConfigureNak(reject);
		return;
			// prevents the nak/reject from being m_freem()'d
		
		default:
			;
	}
コード例 #2
0
ファイル: Protocol.cpp プロジェクト: AmirAbrams/haiku
bool
PAP::Up()
{
	TRACE("PAP: Up() state=%d\n", State());

	switch (State()) {
		case INITIAL:
			if (Side() == PPP_LOCAL_SIDE) {
				NewState(REQ_SENT);
				InitializeRestartCount();
				SendRequest();
			} else if (Side() == PPP_PEER_SIDE) {
				NewState(WAITING_FOR_REQ);
				InitializeRestartCount();
				fNextTimeout = system_time() + kPAPTimeout;
			} else {
				UpFailedEvent();
				return false;
			}
		break;

		default:
			;
	}

	return true;
}
コード例 #3
0
ファイル: BackSparkSearch.c プロジェクト: simsim314/LifeAPI
int main()
{
	New();
	
	LifeState* snakePair = NewState("2ob2o$o3bo$bobo$2ob2o!", -15, -7);
	LifeTarget* target = NewTarget(snakePair);
	
	//For lower part
	LifeState* synth = NewState("obo$b2o$bo13$4bo$4b2o$3bobo$11b3o$11bo$12bo$18bo$17b2o$17bobo!", -20, -20);
	LifeState* gld = NewState("bo$2o$obo!", -6, 13, 1, 0, 0, 1);
	LifeIterator* iter = NewIterator(gld, -30, -30, 60, 60, 4);
	LifeTarget* targetEmpty = NewTarget(Captures[1], NewState("5o2bo2b5o$5ob3ob5o$6obob6o$5o2bo2b5o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o!", -20, -7));

	//For upper part
	//LifeState* synth = NewState("obo$b2o$bo13$4bo$4b2o$3bobo$11b3o$11bo$12bo$18bo$17b2o$17bobo5$11bo$10b2o$10bobo!", -20, -20);
	//LifeTarget* targetEmpty = NewTarget(Captures[1], NewState("15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$5o2bo2b5o$5ob3ob5o$6obob6o$5o2bo2b5o!", -20, -18));
	//LifeState* gld = NewState("2bo$2o$b2o!", -2, -23, 1, 0, 0, -1);
	//LifeIterator* iter = NewIterator(gld, -30, -10, 60, 60, 4);
	
	do
	{
		New();
		
		PutState(synth);
		PutState(iter);
		
		
		Run(210);
		Capture(0);
		Run(2);
		
		//if(ContainsTarget(targetEmpty) == NO && ContainsTarget(target) == YES && GetPop() != 12 + 5)
		if(ContainsTarget(targetEmpty) == NO && ContainsTarget(target) == YES)// && !AreEqual(0))
		{
			Print();
			
			New();
			
			PutState(synth);
			PutState(iter);
			
			PrintRLE();
			//Print();
			
			printf("\nSUCCESS\n");
			getchar();
			printf("\nSearching\n");
			
		}
	}
	while(Next(iter) == SUCCESS);
	
	printf("\nFinish\n");
	
	getchar();
}
コード例 #4
0
int main(int args, const char * argv[])
{
	int cpu = GetCPU(args, argv);
	
	New();
	
	LifeState* pat =  NewState("14bo$15bo13bobo$13b3o13b2o$30bo$3bobo5bo$4b2o3bobo16bo$4bo5b2o14b2o$27b2o3$4bo4b2o4bo3bo12bo$5bo4b2o4bobo12bo$3b3o3bo5b2ob2o11b3o3$16b2ob2o$16bo3bo$17bobo$16b2ob2o$4b3o23b3o$6bo23bo$5bo12bo12bo$17bobo$2o16bo16b2o$b2o31b2o$o35bo$9bo17bo$9b2o15b2o$8bobo15bobo2$20b3o$20bo$21bo2$15b3o$17bo$16bo!", -10, -10);
	LifeState* gld =  NewState("obo$b2o$bo!", 8, -9);

	LifeIterator *iter = NewIterator(gld, -20, -20, 40, 40, 4);
	
	printf("\nSearching...");	

	do
	{
		New();
		
		PutState(pat);
		PutState(iter);
			
		Run(37);
		
		if(IsDart() == YES)
		{
			printf("\n     Found it!!    \n");
			
			Print();
			
			New();
		
			PutState(pat);
			PutState(iter);
		
			printf("\n");
			PrintRLE();
			
			printf("\n\n");
			Print();
			
			printf("\n\n\n");
			Print(iter);
			
			getch();
			printf("\nsearching...");
		}
		
	}while(Next(iter) == SUCCESS);
	
	printf("\nFinished");
	getch();
}
コード例 #5
0
ファイル: Protocol.cpp プロジェクト: AmirAbrams/haiku
void
PAP::RNEvent(net_buffer *packet)
{
	TRACE("PAP: RNEvent() state=%d\n", State());

	NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet);
	if (bufferheader.Status() != B_OK)
		return;
	ppp_lcp_packet &lcp_hdr = bufferheader.Data();
	if (fRequestID != lcp_hdr.id) {
		// this packet is not a reply to our request

		// TODO: log this event
		gBufferModule->free(packet);
		return;
	}

	switch (State()) {
		case REQ_SENT:
			NewState(INITIAL);
			Interface().StateMachine().LocalAuthenticationDenied(
				Interface().Username());
			UpFailedEvent();
		break;

		default:
			;
	}

	gBufferModule->free(packet);
}
コード例 #6
0
ファイル: Protocol.cpp プロジェクト: AmirAbrams/haiku
bool
PAP::Down()
{
	TRACE("PAP: Down() state=%d\n", State());

	switch (Interface().Phase()) {
		case PPP_DOWN_PHASE:
			// interface finished terminating
		case PPP_ESTABLISHED_PHASE:
			// terminate this NCP individually (block until we finished terminating)
			NewState(INITIAL);
			DownEvent();
		break;

/*		case PPP_TERMINATION_PHASE:
			// interface is terminating
		break;

		case PPP_ESTABLISHMENT_PHASE:
			// interface is reconfiguring
		break;
*/
		default:
			;
	}

	return true;
}
task main()
{
	int state, event, action;
	while(true){
		if(event==NULL) event=getEvent();
		action=GetAction(state, event);
		event=DoAction(action);
		state=NewState(state, event);
	}
}
コード例 #8
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
void
IPCP::TOBadEvent()
{
	TRACE("IPCP: TOBadEvent() state=%d\n", State());
	
	switch(State()) {
		case PPP_CLOSING_STATE:
			NewState(PPP_INITIAL_STATE);
			ReportDownEvent();
		break;
		
		case PPP_REQ_SENT_STATE:
		case PPP_ACK_RCVD_STATE:
		case PPP_ACK_SENT_STATE:
			NewState(PPP_INITIAL_STATE);
			ReportUpFailedEvent();
		break;
		
		default:
			IllegalEvent(PPP_TO_BAD_EVENT);
	}
}
コード例 #9
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
bool
IPCP::Down()
{
	TRACE("IPCP: Down() state=%d\n", State());
	
	switch(Interface().Phase()) {
		case PPP_DOWN_PHASE:
			// interface finished terminating
			NewState(PPP_INITIAL_STATE);
			ReportDownEvent();
				// this will also reset and update addresses
		break;
		
/*		case PPP_TERMINATION_PHASE:
			// interface is terminating
		break;
		
		case PPP_ESTABLISHMENT_PHASE:
			// interface is reconfiguring
		break;
*/		
		case PPP_ESTABLISHED_PHASE:
			// terminate this NCP individually (block until we finished terminating)
			if(State() != PPP_INITIAL_STATE && State() != PPP_CLOSING_STATE) {
				NewState(PPP_CLOSING_STATE);
				InitializeRestartCount();
				SendTerminateRequest();
			}
			
			while(State() == PPP_CLOSING_STATE)
				snooze(50000);
		break;
		
		default:
			;
	}
	
	return true;
}
コード例 #10
0
ファイル: Protocol.cpp プロジェクト: AmirAbrams/haiku
void
PAP::RREvent(net_buffer *packet)
{
	TRACE("PAP: RREvent() state=%d\n", State());

	NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet);
	if (bufferheader.Status() != B_OK)
		return;
	ppp_lcp_packet &request = bufferheader.Data();
	int32 length = ntohs(request.length);
	uint8 *data = request.data;
	uint8 *userLength = data;
	uint8 *passwordLength = data + 1 + data[0];

	// make sure the length values are all okay
	if (6 + *userLength + *passwordLength > length) {
		gBufferModule->free(packet);
		return;
	}

	char *peerUsername = (char*) userLength + 1,
		*peerPassword = (char*) passwordLength + 1;
	const char *username = Interface().Username(), *password = Interface().Password();

	if (*userLength == strlen(username) && *passwordLength == strlen(password)
			&& !strncmp(peerUsername, username, *userLength)
			&& !strncmp(peerPassword, password, *passwordLength)) {
		NewState(ACCEPTED);
		Interface().StateMachine().PeerAuthenticationAccepted(username);
		UpEvent();
		SendAck(packet);
	} else {
		NewState(INITIAL);
		Interface().StateMachine().PeerAuthenticationDenied(username);
		UpFailedEvent();
		SendNak(packet);
	}
}
コード例 #11
0
ファイル: Smooth.cpp プロジェクト: xmariuca/SmoothLifeExample
void Smooth::Update() {
   for (int x=0;x<sizex;x++) {
     for (int y=0;y<sizey;y++) {
      (*fieldNew)[x][y]=NewState(x,y);
     }
   }

  std::vector<std::vector<density> > * fieldTemp;
  fieldTemp=field;
  field=fieldNew;
  fieldNew=fieldTemp;
  frame++;

}
コード例 #12
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
void
IPCP::RCRGoodEvent(struct mbuf *packet)
{
	TRACE("IPCP: RCRGoodEvent() state=%d\n", State());
	
	switch(State()) {
		case PPP_INITIAL_STATE:
			NewState(PPP_ACK_SENT_STATE);
			InitializeRestartCount();
			SendConfigureRequest();
			SendConfigureAck(packet);
		break;
		
		case PPP_REQ_SENT_STATE:
			NewState(PPP_ACK_SENT_STATE);
		
		case PPP_ACK_SENT_STATE:
			SendConfigureAck(packet);
		break;
		
		case PPP_ACK_RCVD_STATE:
			NewState(PPP_OPENED_STATE);
			SendConfigureAck(packet);
			ReportUpEvent();
		break;
		
		case PPP_OPENED_STATE:
			NewState(PPP_ACK_SENT_STATE);
			SendConfigureRequest();
			SendConfigureAck(packet);
		break;
		
		default:
			m_freem(packet);
	}
}
コード例 #13
0
ファイル: PerformanceTest.cpp プロジェクト: simsim314/LifeAPI
int main()
{
	long long evolved_cells = 0; 
	clock_t begin;
	//omp_set_num_threads(8);
	
	#pragma omp parallel
	{
		New();

		LifeState* snark = NewState("3o$o4bo$obobo$obo2bo$o$ob3o!", -3, -3);
		
		New();
		PutState(snark);

		int cycle = 0;

		for (int i = 0; i < 1243; i++)
		{
			Run(1);
			cycle += (64 * (2 + (GlobalState->max - GlobalState->min)));
		}

		#pragma omp single
		begin = clock();

		#pragma omp for 
		for (int iter_ix = 0; iter_ix < 30000; iter_ix++)
		{
			New();
			PutState(snark);
			Run(1243);
			
			#pragma omp critical
			evolved_cells += cycle; 
		}
	}
	
	clock_t end = clock();
	double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;

	std::cout << (evolved_cells / 1000000000) / elapsed_secs << " BCO/s \n";
	getchar();
}
コード例 #14
0
ファイル: ElevatorState.cpp プロジェクト: 2asoft/xray
void CElevatorState::SwitchState(Estate new_state)
{
	if(!StateSwitchInertion(new_state))return;
#ifdef DEBUG
if(ph_dbg_draw_mask.test(phDbgLadder))
				Msg("%s",dbg_state[new_state]);
#endif
	VERIFY(m_character);
	if((m_state!=clbClimbingUp&&m_state!=clbClimbingDown) &&
	   (new_state==clbClimbingUp||new_state==clbClimbingDown)
 	   )dBodySetGravityMode(m_character->get_body(),0);

	if((new_state!=clbClimbingUp&&new_state!=clbClimbingDown) &&
		(m_state==clbClimbingUp||m_state==clbClimbingDown)
		)dBodySetGravityMode(m_character->get_body(),1);

	//if(new_state==clbDepart) InitDepart();
	NewState();
	m_state=new_state;
}
コード例 #15
0
ファイル: luacpp.cpp プロジェクト: Daevian/Cloud
Cloud::Lua::StateUniquePtr Cloud::Lua::NewStateAndSetup()
{
    auto luaState = NewState();

    // open standard libs
    auto* s = luaState.get();
    luaL_openlibs(s);


    // redirect print function
    const luaL_Reg printlib[] = {
        { "print", Lua::LuaPrint },
        { nullptr, nullptr }, /* end of array */
    };

    lua_getglobal(s, "_G");
    luaL_setfuncs(s, printlib, 0);
    lua_pop(s, 1);


    return luaState;
}
コード例 #16
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
bool
IPCP::Up()
{
	TRACE("IPCP: Up() state=%d\n", State());
	
	// Servers do not send a configure-request when Up() is called. They wait until
	// the client requests this protocol.
	if(Interface().Mode() == PPP_SERVER_MODE)
		return true;
	
	switch(State()) {
		case PPP_INITIAL_STATE:
			NewState(PPP_REQ_SENT_STATE);
			InitializeRestartCount();
			SendConfigureRequest();
		break;
		
		default:
			;
	}
	
	return true;
}
コード例 #17
0
ファイル: Protocol.cpp プロジェクト: AmirAbrams/haiku
void
PAP::TOBadEvent()
{
	TRACE("PAP: TOBadEvent() state=%d\n", State());

	switch (State()) {
		case REQ_SENT:
		case WAITING_FOR_REQ:
			NewState(INITIAL);
			if (State() == REQ_SENT)
				Interface().StateMachine().LocalAuthenticationDenied(
					Interface().Username());
			else
				Interface().StateMachine().PeerAuthenticationDenied(
					Interface().Username());

			UpFailedEvent();
		break;

		default:
			;
	}
}
コード例 #18
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
void
IPCP::TOGoodEvent()
{
#if DEBUG
printf("IPCP: TOGoodEvent() state=%d\n", State());
#endif
	
	switch(State()) {
		case PPP_CLOSING_STATE:
			SendTerminateRequest();
		break;
		
		case PPP_ACK_RCVD_STATE:
			NewState(PPP_REQ_SENT_STATE);
		
		case PPP_REQ_SENT_STATE:
		case PPP_ACK_SENT_STATE:
			SendConfigureRequest();
		break;
		
		default:
			IllegalEvent(PPP_TO_GOOD_EVENT);
	}
}
コード例 #19
0
ファイル: LifeAPISample.c プロジェクト: ceebo/LifeAPI
int main()
{
	//Always start with new
	New();
	
	printf("\n\n================LifeAPISample with explanation: =============");
	printf("\n\n----- Blockic seeds for glider reflection example: ---\n\n\n\n");
	Continue();
	//create block and glider states
	LifeState* blck =  NewState("2o$2o!");
	LifeState* gld =  NewState("2o$obo$o!");

	//create iterators for glider and block (the second block is at (0,0))
	//The iterators replace 3 loops, on x, y, and s - you just use (Next), they also work together. 
	//start at (-10, -19) - iterate x in width of 20, y in width of 10
	LifeIterator *blckiter1= NewIterator(blck, -10, -10, 20, 10);
	
	//start at (-16, 6) - iterate x in width of 35, y remains. 
	LifeIterator *glditer= NewIterator(gld, -16, 5, 35, 1);

	//	Let's measure performance (remove all Continue(); statements to see the real time). 
	clock_t t = clock();
			
	do
	{
		//clear previous junk from GlobalState 
		New();
		
		//PutState works with LifeState and LifeIterator
		
		//Place block at (0,0)
		PutState(blck);
		
		//place block and glider, by their iterators data. 
		PutState(glditer);
		PutState(blckiter1);
		
		//Get population (to avoid blocks placed on same spot)
		int pop = GetPop();
		
		//block + block + glider
		if(pop != 5 + 4 + 4)
			continue;
		
		Run(1);
		
		//Check if blocks are interfering. 
		if(pop != GetPop())
			continue;
		
		//Just iterate - the glider will run all over tha place - we're on torus anyway 
		Run(180);
		
		//potential glider 
		if(GetPop() == 5)
		{	
			int min = GlobalState->min;
			int max = GlobalState->max;
			
			//evolve 
			Run(16);
			if(GetPop() == 5 && !(min == GlobalState->min && max == GlobalState->max))
			{
				//Success! let's report it here.
				
				//We do the same as we did previously to get here: 
				New();
						
				PutState(glditer);
				PutState(blckiter1);
				PutState(blck);
				
				printf("\n\n       SUCCESS!!    \n\n");
				printf("Here is the blockic seed:    \n\n");				
				//The iterators state is change only on Next. 
				
				Print();
				
				PrintRLE();
				
				printf("\n\nYou can copy-paste the rle into golly (remember to remove \"new line\" symbols)!!    \n\n");
				Continue();
				
			}
		
		}
	}
	//You can use Next for both iterators (works for up to 6) 
	while(Next(blckiter1, glditer) == SUCCESS);
	
	t = clock() - t;
	
	printf ("Total time: %d miliseconds\n",t);
	printf("\n\n\n\n\n                 THE END !!!\n\n\n\n\n\n");
	getch();
	return 0;
}
コード例 #20
0
void JankyAutoSequencer::StateEngine(int curState)
{
	switch(curState){
		case Rest:
			if(aMode==DONE){
				if(!done){
					printf("SEQUENCE DONE!!! YAYAYAY\n");
				 	done=true;
				}
			}
			else if(aMode==L_CROSS_AUTOLINE){
				NewState(Drive120Inches, "Left Cross Auto Line selected");
			}
			else if(aMode==L_SAME_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==L_OPPOSITE_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==M_LEFT_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==M_RIGHT_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==R_CROSS_AUTOLINE){
				NewState(Drive120Inches, "Right Cross Auto Line selected");
			}
			else if(aMode==R_SAME_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==R_OPPOSITE_SWITCH){
				NewState(CubeUp, "Lift cube to switch level");
			}
			else if(aMode==L_SAME_SCALE){
				NewState(CubeUpScale, "Lift cube to scale level");
				//NewState(Drive260Inches, "Left Same Scale Selected");
			}
			else if(aMode==R_SAME_SCALE){
				NewState(CubeUpScale, "Lift cube to scale level");
				//NewState(Drive260Inches, "Right Same Scale Selected");
			}
			else if(aMode==L_OPPOSITE_SCALE){
				NewState(Drive210Inches, "Left opposite scale Selected");
			}
			else if(aMode==R_OPPOSITE_SCALE){
				NewState(Drive210Inches, "Right opposite scale Selected");
			}
			break;
		case CubeUp:
			if(cubeUp->IsComplete()){
				if(aMode==L_SAME_SWITCH){
					NewState(Drive162Inches, "Left Same Switch selected");
				}
				else if(aMode==L_OPPOSITE_SWITCH){
					NewState(Drive60Inches, "Left to Right Switch selected");
				}
				else if(aMode==M_LEFT_SWITCH){
					NewState(Drive60Inches, "Middle to Left Switch selected");
					//NewState(VisionSegment, "Middle to Left Switch selected");
				}
				else if(aMode==M_RIGHT_SWITCH){
					NewState(Drive60Inches, "Middle to Right Switch selected");
					//NewState(VisionSegment, "Middle to Left Switch selected");
				}
				else if(aMode==R_SAME_SWITCH){
					NewState(Drive162Inches, "Right Same Switch selected");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(Drive60Inches, "Right to Left Switch selected");
				}
			}
			break;
		case CubeUpScale:
			if(cubeUpScale->IsComplete()){
				NewState(Drive260Inches, "Same Scale Selected");
			}
				/*if(aMode==L_SAME_SCALE){
					NewState(TurnRight30, "Done Driving to Left Scale Edge");
				}
				else if(aMode==R_SAME_SCALE){
					NewState(TurnLeft30, "Done Driving to Right Scale Edge");
				}
			}*/
			/*if(cubeUpScale->IsComplete()){
				NewState(Drive10Inches, "Done lifting cube to scale height");
			}*/
			break;
		case TurnLeft90:
			if(turnLeft90->IsComplete()){
				if(aMode==M_LEFT_SWITCH){
					NewState(Drive52Inches, "Done turning left 90 degrees to drive to left switch");
				}
				else if(aMode==M_RIGHT_SWITCH){
					NewState(Drive72Inches, "Done turning left 90 degrees to align to right switch front");
					//NewState(VisionSegment, "Done turning left 90 degrees to align to right switch front");
				}
				else if(aMode==R_SAME_SWITCH){
					NewState(Drive6Inches, "Done turning left 90 degrees to align to right switch edge");
				}
				else if(aMode==L_OPPOSITE_SWITCH){
					NewState(Drive72Inches, "Done turning left 90 degrees to align to right switch front");
					//NewState(VisionSegment, "Done turning left 90 degrees to align to left switch front");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(Drive144Inches, "Done turning left 90 degrees to drive to left switch");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(Drive240Inches, "Done turning left 90 degrees to drive to left scale");
				}
				else if(aMode==L_OPPOSITE_SCALE){
					NewState(Drive40Inches, "Need to drive closer to right scale plate");
				}
			}
			break;
		case TurnRight90:
			if(turnRight90->IsComplete()){
				if(aMode==M_RIGHT_SWITCH){
					NewState(Drive50Inches, "Done turning right 90 degrees to drive to right switch");
				}
				else if(aMode==M_LEFT_SWITCH){
					NewState(Drive72Inches, "Done turning right 90 degrees to align to left switch front");
					//NewState(VisionSegment, "Done turning right 90 degrees to align to left switch front");
				}
				else if(aMode==L_SAME_SWITCH){
					NewState(Drive6Inches, "Done turning right 90 degrees to align to left switch edge");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(Drive72Inches, "Done turning right 90 degrees to align to left switch front");
					//NewState(VisionSegment, "Done turning right 90 degrees to align to left switch front");
				}
				else if(aMode==L_OPPOSITE_SWITCH){
					NewState(Drive144Inches, "Done turning right 90 degrees to drive to right switch");
				}
				else if(aMode==L_OPPOSITE_SCALE){
					NewState(Drive240Inches, "Done turning right 90 degrees to drive to right scale");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(Drive40Inches, "Need to drive closer to left scale plate");
				}
			}
			break;
		case TurnLeft45:
			if(turnLeft45->IsComplete()){
				if(aMode==L_CROSS_AUTOLINE){
					NewState(Drive60Inches, "Done Turning Left 45 Degrees");
				}
				else if(aMode==R_CROSS_AUTOLINE){
					NewState(Drive120Inches, "Done Turning Left 45 Degrees at Right Field Edge");
				}
				else if(aMode==R_SAME_SCALE){
					NewState(CubeUpScale, "Need to bring cube to right height");
				}
				else if(aMode==L_OPPOSITE_SCALE){
					NewState(CubeUpScale, "Need to bring cube to right height");
				}
			}
			break;
		case TurnRight45:
			if(turnRight45->IsComplete()){
				if(aMode==R_CROSS_AUTOLINE){
					NewState(Drive60Inches, "Done Turning Right 45 Degrees");
				}
				else if(aMode==L_CROSS_AUTOLINE){
					NewState(Drive120Inches, "Done Turning Right 45 Degrees at Left Field Edge");
				}
				else if(aMode==L_SAME_SCALE){
					NewState(CubeUpScale, "Need to bring cube to right height");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(CubeUpScale, "Need to bring cube to right height");
				}
			}
			break;
		case TurnLeft30:
			if(turnLeft30->IsComplete()){
				NewState(Drive10Inches, "Done lifting cube to scale height");
				//NewState(CubeUpScale, "Need to bring cube to right height");
			}
			break;
		case TurnRight30:
			if(turnRight30->IsComplete()){
				NewState(Drive10Inches, "Done lifting cube to scale height");
				//NewState(CubeUpScale, "Need to bring cube to right height");
			}
			break;
		case Drive6Inches:
			if(drive6Inches->IsComplete()){
				NewState(ReleaseCube, "Aligned with switch edge");
			}
			break;
		case Drive10Inches:
			if(drive10Inches->IsComplete()){
				NewState(ReleaseCube, "Aligned with scale edge");
			}
			break;
		case Drive40Inches:
			if(drive40Inches->IsComplete()){
				if(aMode==L_OPPOSITE_SCALE){
					NewState(TurnLeft30, "Need to turn towards right scale plate");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(TurnRight30, "Need to turn towards left scale plate");
				}
			}
			break;
		case Drive50Inches:
			if(drive50Inches->IsComplete()){
				if(aMode==M_RIGHT_SWITCH){
					NewState(TurnLeft90, "Done aligning to left switch");
				}
			}
			break;
		case Drive52Inches:
			if(drive52Inches->IsComplete()){
				if(aMode==M_LEFT_SWITCH){
					NewState(TurnRight90, "Done aligning to left switch");
				}
			}
			break;
		case Drive60Inches:
			if(drive60Inches->IsComplete()){
				if(aMode==L_CROSS_AUTOLINE){
					NewState(TurnRight45, "Done driving to left field edge");
				}
				else if(aMode==R_CROSS_AUTOLINE){
					NewState(TurnLeft45, "Done driving to right field edge");
				}
				else if(aMode==M_LEFT_SWITCH){
					NewState(TurnLeft90, "Done driving to mid");
				}
				//else if(aMode==M_LEFT_SWITCH&&(c==1)){
					//NewState(TurnRight90, "Done aligning to left switch");
				//}
				else if(aMode==M_RIGHT_SWITCH){
					NewState(TurnRight90, "Done driving to mid");
				}
				//else if(aMode==M_RIGHT_SWITCH&&(c==1)){
					//NewState(TurnLeft90, "Done aligning to left switch");
				//}
				else if(aMode==L_OPPOSITE_SWITCH){
					NewState(TurnRight90, "Done driving mid");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(TurnLeft90, "Done driving mid");
				}
			}
			break;
		case Drive72Inches:
		//case VisionSegment:
			if(drive72Inches->IsComplete()){
			//if(visionSegment->IsComplete()){
				if(aMode==M_LEFT_SWITCH){
					NewState(ReleaseCube, "Done driving to left switch front");
				}
				else if(aMode==M_RIGHT_SWITCH){
					NewState(ReleaseCube, "Done driving to right switch front");
				}
				else if(aMode==L_OPPOSITE_SWITCH){
					NewState(ReleaseCube, "Done driving to left switch front");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(ReleaseCube, "Done driving to right switch front");
				}
			}
			break;
		case Drive120Inches:
			if(drive120Inches->IsComplete()){
				if(aMode==L_CROSS_AUTOLINE){
					NewState(Stop, "Crossed Auto Line on left side");
				}
				else if(aMode==R_CROSS_AUTOLINE){
					NewState(Stop, "Crossed Auto Line on right side");
				}
			}
			break;
		case Drive144Inches:
			if(drive144Inches->IsComplete()){
				if(aMode==L_OPPOSITE_SWITCH){
					NewState(TurnLeft90, "Done driving to align to right switch");
				}
				else if(aMode==R_OPPOSITE_SWITCH){
					NewState(TurnRight90, "Done driving to align to left switch");
				}
			}
			break;
		case Drive162Inches:
			if(drive162Inches->IsComplete()){
				if(aMode==L_SAME_SWITCH){
					NewState(TurnRight90, "Done Driving to Left Switch Edge");
				}
				else if(aMode==R_SAME_SWITCH){
					NewState(TurnLeft90, "Done Driving to Right Switch Edge");
				}
			}
			break;
		case Drive210Inches:
			if(drive210Inches->IsComplete()){
				if(aMode==L_OPPOSITE_SCALE){
					NewState(TurnRight90, "Done driving to field area between switch and scale");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(TurnLeft90, "Done driving to field area between switch and scale");
				}
			}
			break;
		case Drive240Inches:
			if(drive240Inches->IsComplete()){
				if(aMode==L_OPPOSITE_SCALE){
					NewState(TurnLeft90, "Done driving to right side scale");
				}
				else if(aMode==R_OPPOSITE_SCALE){
					NewState(TurnRight90, "Done driving to left side scale");
				}
			}
			break;
		case Drive260Inches:
			if(drive260Inches->IsComplete()){
				if(aMode==L_SAME_SCALE){
					NewState(TurnRight30, "Done Driving to Left Scale Edge");
				}
				else if(aMode==R_SAME_SCALE){
					NewState(TurnLeft30, "Done Driving to Right Scale Edge");
				}
				//NewState(CubeUpScale, "Need to bring cube to right height");
				/*if(aMode==L_SAME_SCALE){
					NewState(TurnRight30, "Done Driving to Left Scale Edge");
				}
				else if(aMode==R_SAME_SCALE){
					NewState(TurnLeft30, "Done Driving to Right Scale Edge");
				}*/
			}
			break;
		case ReleaseCube:
			if(releaseCube->IsComplete()){
				if(aMode==L_SAME_SCALE||aMode==R_SAME_SCALE||aMode==L_OPPOSITE_SCALE||aMode==R_OPPOSITE_SCALE){
					NewState(DriveBack10Inches, "Get away from the scale after loading");
				}
				else{
					NewState(Stop, "Done releasing cube on switch");
				}
			}
			break;
		case DriveBack10Inches: //TEST THS
			if(driveBack10Inches->IsComplete()){
				NewState(Stop, "Done releasing cube on switch");
			}
			break;
		case Stop:
			aMode=DONE;
			NewState(Rest, "Sequence Finished");
			break;
	}
}
コード例 #21
0
ファイル: Protocol.cpp プロジェクト: DonCN/haiku
void
IPCP::RCREvent(struct mbuf *packet)
{
	TRACE("IPCP: RCREvent() state=%d\n", State());
	
	KPPPConfigurePacket request(packet);
	KPPPConfigurePacket nak(PPP_CONFIGURE_NAK);
	KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT);
	
	// we should not use the same id as the peer
	if(fID == mtod(packet, ppp_lcp_packet*)->id)
		fID -= 128;
	
	nak.SetID(request.ID());
	reject.SetID(request.ID());
	
	// parse each item
	ppp_configure_item *item;
	in_addr_t *requestedAddress, *wishedAddress = NULL;
	for(int32 index = 0; index < request.CountItems(); index++) {
		item = request.ItemAt(index);
		if(!item)
			continue;
		
		// addresses have special handling to reduce code size
		switch(item->type) {
			case IPCP_ADDRESSES:
				// abandoned by the standard
			case IPCP_ADDRESS:
				wishedAddress = &fPeerRequests.address;
			break;
			
			case IPCP_PRIMARY_DNS:
				wishedAddress = &fPeerRequests.primaryDNS;
			break;
			
			case IPCP_SECONDARY_DNS:
				wishedAddress = &fPeerRequests.secondaryDNS;
			break;
		}
		
		// now parse item
		switch(item->type) {
			case IPCP_ADDRESSES:
				// abandoned by the standard
			case IPCP_ADDRESS:
			case IPCP_PRIMARY_DNS:
			case IPCP_SECONDARY_DNS:
				if(item->length != 6) {
					// the packet is invalid
					m_freem(packet);
					NewState(PPP_INITIAL_STATE);
					ReportUpFailedEvent();
					return;
				}
				
				requestedAddress = (in_addr_t*) item->data;
				if(*wishedAddress == INADDR_ANY) {
					if(*requestedAddress == INADDR_ANY) {
						// we do not have an address for you
						m_freem(packet);
						NewState(PPP_INITIAL_STATE);
						ReportUpFailedEvent();
						return;
					}
				} else if(*requestedAddress != *wishedAddress) {
					// we do not want this address
					ip_item ipItem;
					ipItem.type = item->type;
					ipItem.length = 6;
					ipItem.address = *wishedAddress;
					nak.AddItem((ppp_configure_item*) &ipItem);
				}
			break;
			
//			case IPCP_COMPRESSION_PROTOCOL:
				// TODO: implement me!
//			break;
			
			default:
				reject.AddItem(item);
		}
	}
	
	// append additional values to the nak
	if(!request.ItemWithType(IPCP_ADDRESS) && fPeerRequests.address == INADDR_ANY) {
		// The peer did not provide us his address. Tell him to do so.
		ip_item ipItem;
		ipItem.type = IPCP_ADDRESS;
		ipItem.length = 6;
		ipItem.address = INADDR_ANY;
		nak.AddItem((ppp_configure_item*) &ipItem);
	}
	
	if(nak.CountItems() > 0) {
		RCRBadEvent(nak.ToMbuf(Interface().MRU(), Interface().PacketOverhead()), NULL);
		m_freem(packet);
	} else if(reject.CountItems() > 0) {
		RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(),
			Interface().PacketOverhead()));
		m_freem(packet);
	} else
		RCRGoodEvent(packet);
}
コード例 #22
0
ファイル: LifeMP.c プロジェクト: Scorbie/LifeAPI
int main () 
{

printf("x = 0, y = 0, rule = B3/S23\n");
	
#pragma omp parallel
{
	New();
   
   LifeState* blck =  NewState("2o$o$b3o$3bo!");
   LifeState* gldL =  NewState("3o$2bo$bo!");
   LifeState* gldR =  NewState("bo$o$3o!");
   
   LifeIterator *iterL = NewIterator(gldL, -10, 5, 10, 1);
   
   LifeIterator *iterR1 = NewIterator(gldR, 0, -15, 10, 10, 4);
   LifeIterator *iterR2 = NewIterator(gldR, 0, -15, 10, 10, 4);
   
   int initPop = GetPop(blck);
   

   do{
    #pragma omp single nowait
	{
	
		if(Validate(iterR1, iterR2) != FAIL)
		{
			
			New();
			PutState(blck);
			PutState(iterL);
			PutState(iterR1);
			PutState(iterR2);

			int collide = NO;

			for(int i = 0; i < 4; i++)
			{
				if(GetPop() != 5 * 3 + initPop)
				{
				collide = YES;
				break;
				}
				
				Run(1);
			}

			if(collide != YES)
			{ 
				
				for(int i = 0; i < 300; i++)
				{
					Run(1);
					
					uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2);
					int found = NO;
					
					if(strlen(GlobalState->emittedGliders->value) != 0)
					break;
					
					int gen = GlobalState->gen;
					
					if(gld != 0 && GetPop() == 5)
					{
						found = YES;
						
						for(int j = 0; j < 4; j++)
						{
								 if(GlobalState->gen%4 == 0)
									break;
									
								 Run(1);
						}
						
						Capture(0);
						Move(Captures[0], (GlobalState->gen) / 4 + 4, (GlobalState->gen) / 4 + 4);
						Evolve(Captures[0], 2);
						
						New();
						PutState(blck);
						PutState(iterL);
						PutState(iterR1);
						PutState(iterR2);
						PutState(Captures[0]);
						
						Run(gen);
						
						uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2);
						
						if(gld != 0 && GetPop() == 10)
					{
							 New();
							 PutState(blck);
							 PutState(iterL);
							 PutState(iterR1);
							 PutState(iterR2);
							 PutState(Captures[0]);
							 
							#pragma omp critical
							{
								printf(GetRLE(GlobalState));
								printf("100$");
							}
						}
					}

					if(found == YES)
					break;

				}
			}
		}
	}
   }while(Next(iterL, iterR1, iterR2, NO));

}
	printf("!");
	printf("\n\nFINISH");
	getchar();
}
コード例 #23
0
ファイル: LifeAPISample3.c プロジェクト: ceebo/LifeAPI
int main()
{
	printf("\n\n================LifeAPISample with explanation: =============\n\n");
	printf("\n\n           Target with two gliders search example: \n\n");
	
	//Always start with New();
	New();
	
	//Initial pattern
	LifeState* pat =  NewState("obo$b2o$bo9$4bo$4b2o$3bobo$7b3o$7bo$8bo$14bo$13b2o$13bobo!", -20, -20);
	
	//target and inverse target
	LifeState* target =  NewState("$b2ob2o$bo3bo$2bobo$b2ob2o3$3bo$2bobo$3bo!", -18, -10);
	LifeState* inverse = NewState("7o$o2bo2bo$ob3obo$2obob2o$o2bo2bo$7o$7o$3ob3o$2obob2o$3ob3o$7o!", -18, -10);
	
	//Life target object contains the on and the off cells
	LifeTarget * fulltarget = NewTarget(target, inverse);
	
	//glider with (+1, -1) direction at (0,0)
	LifeState* gld =  NewState("b2o$obo$2bo!", 0, 0);
	
	New();
	PutState(pat);
	Print();
	printf("\n\n We have durty snake pair synthesis \n\n");
	Continue();
	Run(21);
	Print();
	Continue();
	printf("\n\n It destoryed after 2 generations \n\n");
	Run(2);
	Print();
	Continue();
	
	printf("\n\n We want to place 2 gliders to reach this configuration \n\n");
	
	New();
	PutState(target);
	Print();
	
	Continue();

	New();
	PutState(inverse);
	Print();
	
	printf("\n\n While all these cells should be off \n\n");
	Continue();

	printf("\n\nSearching... \n\n");
	
	//Gldier iterators always have 4 states
	LifeIterator *iter1 = NewIterator(gld, -27, 2, 15, 15, 4);
	LifeIterator *iter2 = NewIterator(gld, -27, 2, 15, 15, 4);
	
	do
	{
		if(Validate(iter1, iter2) == FAIL)
			continue; 
			
		New();
		
		PutState(pat);
		PutState(iter1);
		PutState(iter2);
		
		//100 should be enough
		Run(100);
		
		//ContainsTarget checks both "on" and "off" cells
		if(ContainsTarget(fulltarget) == YES)
		{
			printf("\nFound!\n\n");
			
			New();
			
			PutState(pat);
			PutState(iter1);
			PutState(iter2);

			PrintRLE();
			printf("\n\n");
			
			Print();
			
			Run(100);
			
			Print();
			
			Continue();
			printf("\Searching...\n\n");
		}
	}while(Next(iter1, iter2, "none") == SUCCESS);
	
	printf("\nFinished");
	getch();
}