task main()
{
	//initializeRobot();
	waitForStart();
	wait10Msec(200);
	servoChangeRate[elServo]=1;
	servoChangeRate[ringPlacer]=1;
	servo[elServo] = ES_POSITION_1;
	servo[ringPlacer] = RP_POSITION_3;
	servoChangeRate[elServo]=10;
	servoChangeRate[ringPlacer]=10;
	wait10Msec(200);
	gostraight (2500, 80);
	turnright (4350, 80);
	gostraight (3650, 80);
	wait10Msec(200);
	servo[elServo] = ES_POSITION_2;
	servo[ringPlacer] = RP_POSITION_2;
	wait10Msec(200);
	servo[ringPlacer] = RP_POSITION_3;
	wait10Msec(200);
	turnright(180, 80);
	turnleft(180, 80);
	turnright(180, 80);
	turnleft(180, 80);
	drival (-50, -50);
	wait10Msec(200);
	drival (0, 0);
	drival (0, 0);
}
Beispiel #2
0
void Tree1::rule1(int i)
{
	if (i == 0)
		drawline();
	else
	{
		rule1(i - 1);
		rule1(i - 1);
		turnright();
		glPushMatrix();
		turnright();
		rule1(i - 1);
		turnleft();
		rule1(i - 1);
		turnleft();
		rule1(i - 1);
		glPopMatrix();
		turnleft();
		glPushMatrix();
		turnleft();
		rule1(i - 1);
		turnright();
		rule1(i - 1);
		turnright();
		rule1(i - 1);
		glPopMatrix();
	}
}
Beispiel #3
0
void Fern::rule1(int i)
{
	
	if (i == 0)
		;
	else
	{
		rule2(i-1);
		turnleft();
		glPushMatrix();
		glPushMatrix();
		rule1(i-1);
		glPopMatrix();
		turnright();
		rule1(i-1);
		glPopMatrix();
		turnright();
		rule2(i - 1);
		glPushMatrix();
		turnright();
		rule2(i - 1);
		rule1(i - 1);
		glPopMatrix();
		turnleft(); 
		rule1(i - 1);

	}
}
void loop(){
  
  if (irrecv.decode(&results)){ //Check if the remote control is sending a signal
    if(results.value==0xFF6897){ //If an '1' is received, turn on robot
      power=1; }
    if(results.value==0xFF4AB5){ //If a '0' is received, turn off robot
      stopmove();
      power=0; }
    if(results.value==0xFF42BD){ //If an '*' is received, switch operating mode from automatic robot to remote control (press also "*" to return to automatic robot mode)
      modecontrol=1; //  Activate remote control operating mode
      stopmove(); //The robot stops and starts responding to the user's directions
    }
    irrecv.resume(); // receive the next value
  }
  
  while(modecontrol==1){ //The system gets into this loop during the remote control mode until modecontrol=0 (with '*')
    if (irrecv.decode(&results)){ //If something is being received
      translateIR();//Do something depending on the signal received
      irrecv.resume(); // receive the next value
     }
  }
  if(power==1){
  go();  // if nothing is wrong go forward using go() function above.
  ++numcycles;
  if(numcycles>130){ //Watch if something is around every certain number of cycles while moving forward 
    watchsurrounding();
    if(leftscanval<sidedistancelimit || ldiagonalscanval<distancelimit){
      turnright(turntime);
    }
    if(rightscanval<sidedistancelimit || rdiagonalscanval<distancelimit){
      turnleft(turntime);
    }
    numcycles=0; //Restart count of cycles
  }
  distance = watch(); // use the watch() function to see if anything is ahead (when the robot is just moving forward and not looking around it will test the distance in front)
  if (distance<distancelimit){ // The robot will just stop if it is completely sure there's an obstacle ahead (must test 25 times) (needed to ignore ultrasonic sensor false signals)
      ++thereis;}
  if (distance>distancelimit){
      thereis=0;} //Count is restarted
  if (thereis > 25){
    stopmove(); // Since something is ahead, stop moving.
    turndirection = decide(); //Decide which direction to turn.
    switch (turndirection){
      case 'l':
        turnleft(turntime);
        break;
      case 'r':
        turnright(turntime);
        break;
      case 'f':
        ; //Do not turn if there was really nothing ahead
        break;
    }
    thereis=0;
  }
 }
}
Beispiel #5
0
void Sierpinski::rule1(int i)
{
	if (i == 0)
		drawline();
	else{
		rule2(i - 1);
		turnright();
		rule1(i - 1);
		turnright();
		rule2(i - 1);

	}
}
Beispiel #6
0
	task main()
	{

		bSystemLeaveServosEnabledOnProgramStop=true;  // leaves power on so we are in home position after autonomous period, and so that the robot doesn't just fall down.

		home();
		servo[tail] = 127;	// stop tail just in case....
		wait10Msec(100);		// wait a bit...

		waitForStart(); 		// Wait for the beginning of autonomous phase.
/*
		drop();							// Bring arm into drop position

		motor[leftWheel] = 30;
		motor[rightWheel] = 30 ;
		wait1Msec(650); //was 500, 1000 doesn't work, 750 is too high

		seek_beacon();			//find IR beam

		spit();					  	//spit the cube (into the basket please...)

		gobackhome();				//trace back your steps

		home();							//get arm to home position
*/
		wait1Msec(35);			//wait a bit... before turning

		if(totrot<0)				// turn 90 depending where we come from
			turnleft(130.0);		// CALIBRATE!!!
		else
			turnright(130.0);

		lookforline();			// look for white line

		if(totrot<0)				// turn 90 to go up the ramp... CALIBRATE!
			turnright(130.0);
		else
			turnleft(130.0);

		motor[leftWheel] = 25;	// go up the ramp
		motor[rightWheel] = 25;

		wait10Msec(275); 				//CALIBRATE time to make sure we get on the ramp

		motor[leftWheel] = 0;		// stop motor
		motor[rightWheel] = 0;

		// done! ...  How did I do?

	}
void translateIR() { //Used when robot is switched to operate in remote control mode
  switch(results.value)
  {
  case 0xFF629D: //Case 'FORWARD'
    go();
    break;
  case 0xFF22DD: //Case 'LEFT'
    turnleft(turntime); 
    stopmove();  
    break;
  case 0xFF02FD: //Case 'OK'
    stopmove();   
    break;
  case 0xFFC23D: //Case 'RIGHT'
    turnright(turntime);
    stopmove(); 
    break;
  case 0xFFA857: //Case 'REVERSE'
    backwards();
    break;
  case 0xFF42BD:  //Case '*'
    modecontrol=0; stopmove(); // If an '*' is received, switch to automatic robot operating mode
    break;
  default: 
    ;
  }// End Case
  delay(500); // Do not get immediate repeat
} 
Beispiel #8
0
static void approachintersection(void * unusedpointer, unsigned long carnumber)
{ 
		
        int cardirection;
		int destdirection;
		int car_no=carnumber;
		
        /*
         * Avoid unused variable and function warnings.
         */
		 
        (void) unusedpointer;
		
        /*
         * cardirection is set randomly.
         */

        cardirection = random() % 4;
		destdirection = random() % 3;
		destdirection = (cardirection + destdirection + 1) % 4;
		
		
		if(cardirection-destdirection==2 || destdirection-cardirection==2) //if car wants to go straight
		gostraight(cardirection,car_no,destdirection);
		else if(destdirection-cardirection==1 || cardirection-destdirection==3) //if car wants to turn left
		turnleft(cardirection,car_no,destdirection);
		else 																	//else the car wants to turn right
		turnright(cardirection,car_no,destdirection);
		
}
Beispiel #9
0
void turnrightleft(player& pl)
{

  if (rand()%2 == 0)
     turnleft(pl);
  else
     turnright(pl);
}
Beispiel #10
0
void star_20 (int len)
{
  int i;
  for (i = 0; i < 20; i++) {
    forwd (len);
    turnright (162);
  }
}
Beispiel #11
0
void star (int len)
{
  int i;
  for (i = 0; i < 5; i++) {
    forwd (len);
    turnright (144);
  }
}
Beispiel #12
0
static
void
approachintersection(void * unusedpointer,
                     unsigned long carnumber)
{
    int car_direction;
    int turn_direction;
        /*
         * Avoid unused variable and function warnings.
         */

    (void) unusedpointer;
    (void) carnumber;
	(void) gostraight;
	(void) turnleft;
	(void) turnright;

        /*
         * cardirection is set randomly.
         */

    car_direction = random() % 4;
    turn_direction = random() % 3;


    // we enforce the FIFO ordering for the cars approaching
    // the intersection from the same direction
    if (car_direction == 0) {// North
        // north
        P(from_north);
    } else if (car_direction == 1) { //East
        P(from_east);
    } else if (car_direction == 2) {//South
        P(from_south);
    } else {
        assert(car_direction == 3); //West
        P(from_west);
    }

    // Step 1: approaching an intersection
    // message(APPROACHING, carnumber, car_direction, turn_direction);

    // kprintf("car: %d, from: %c, turn_direction: %d\n", carnumber, directions[car_direction], turn_direction);
    // after we approached the intersection, we enter it 
    if (turn_direction == TURN_LEFT) { //0
        turnleft(car_direction, carnumber);
    } else if (turn_direction == TURN_RIGHT) { //1
        turnright(car_direction, carnumber);
    } else {
        assert(turn_direction == GO_STRAIGHT); //2
        gostraight(car_direction, carnumber);
    }


    V(join_sem);
}
Beispiel #13
0
void star_6 (int len)
{
  int i;
  for (i = 0; i < 6; i++) {
    forwd (len);
    turnright (120);
    forwd (len);
    turnleft (60);
  }
}
task main()
{
//power,rotations
//1200 is around 1 rotation
//1200 rotations turn is 270 degrees
forward(50,1200);
wait1Msec(2000);
turnright(50,1200);
wait1Msec(2000);
turnleft(50,1200);
wait1Msec(2000);
backward(50,3600);
}
Beispiel #15
0
/*The integer for choice is based on the index of items in the keywords array in the main() function*/
void chooseMove(int choice, int duration)
{
    if (choice == 0)
        forward(duration);
    else if (choice == 1)
        reverse(duration);
    else if (choice == 2)
        turnright(duration);
    else if (choice == 3)
        turnleft(duration);
    else if (choice == 4)
        pause(duration);
}
Beispiel #16
0
void getinput()
{
//hit ESC to quit
if (key[KEY_ESC]) gameover = 1;
//WASD - SPACE keys control tank 1
if (key[KEY_W]) forward(0);
if (key[KEY_D]) turnright(0);
if (key[KEY_A]) turnleft(0);
if (key[KEY_S]) backward(0);
if (key[KEY_SPACE]&& loopcnt==LOOPDELAY) {fireweapon(0);
loopcnt=0;
}
//arrow - ENTER keys control tank 2
if (key[KEY_UP]) forward(1);
if (key[KEY_RIGHT]) turnright(1);
if (key[KEY_DOWN]) backward(1);
if (key[KEY_LEFT]) turnleft(1);
if (key[KEY_ENTER]&& loopcnt==LOOPDELAY) {fireweapon(1);
loopcnt=0;
}
//short delay after keypress
rest(20);
}
Beispiel #17
0
void sq_koch (int len, int level)
{
  if (0 == level) {
    forwd (len);
    return;
  }
  else {
    sq_koch (len / 4, level - 1);
    turnleft (90);
    sq_koch (len / 4, level - 1);
    turnright (90);
    sq_koch (len / 4, level - 1);
    turnright (90);
    sq_koch (len / 4, level - 1);
    sq_koch (len / 4, level - 1);
    turnleft (90);
    sq_koch (len / 4, level - 1);
    turnleft (90);
    sq_koch (len / 4, level - 1);
    turnright (90);
    sq_koch (len / 4, level - 1);
  }
}
Beispiel #18
0
void _3DTree::rule1(int i)
{
	if (i == 0)
		drawline();
	else
	{
		rule1(i - 1);
		glPushMatrix();
		turnright();
		pitchdown();
		rollleft();
		rule1(i - 1);
		glPopMatrix();
		glPushMatrix();
		rollleft();
		turnleft();
		turnleft();
		pitchdown();
		rule1(i - 1);
		glPopMatrix();
		turnaround();
		turnaround();
		rule1(i - 1);
		glPushMatrix();
		turnright();
		turnright();
		pitchdown();
		rollright();
		rule1(i - 1);
		glPopMatrix();
		glPushMatrix();
		turnleft();
		pitchdown();
		rule1(i - 1);
		glPopMatrix();
	}
}
Beispiel #19
0
void hilbert_right (int len, int level)
{
  int bearing;
  
  if (level > 0) {
    
    bearing = heading ();
    turnright (90);
    hilbert_left (len, level - 1);
    
    setheading (bearing);
    forwd (len);
    
    bearing = heading ();
    hilbert_right (len, level - 1);
    
    setheading (bearing);
    turnright (90);
    forwd (len);
    
    bearing = heading ();
    turnleft (90);
    hilbert_right (len, level - 1);
    
    setheading (bearing);
    turnright (90);
    forwd (len);
    
    bearing = heading ();
    turnright (90);
    hilbert_left (len, level - 1);
    setheading (bearing);
    
  }

}
Beispiel #20
0
//Interrupt handler to read IR sensors
void __ISR(_TIMER_1_VECTOR, ipl2) _Timer1Handler(void)
{
    //Reset the flag
    mT1ClearIntFlag();

    if(readpins(0) > 700)   //left
		{
                    if(leftspeed < 305)
                        leftspeed++;
                    if(rightspeed > 285)
                        rightspeed--;
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 600)
                if(readpins(2) > 700) //right
		{
                    if(leftspeed > 275)
                        leftspeed--;
                    if(rightspeed < 315)
                        rightspeed++;
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 900)
                if(readpins(1) > 900) //middle
		{
                    setpwmR(0);
                    setpwmL(0);
                    motorRstop();
                    motorLstop();
                    turnright();

                }
                for(i = 0; i < 5000; i++){};


}
Beispiel #21
0
float Walk::turnright(float theta)
{
	if(theta==0)
	{
		legRotfi=0;
		supLegRotfi=0;
		dribble();
		return 0;
	}
	if(theta>15)
		legRotfi=(1-(int)leg)*15;
	else
		legRotfi=(1-(int)leg)*theta;
	supLegRotfi=0;
	dribble();	
	theta=theta-legRotfi;
	turnright(theta);	
}
Beispiel #22
0
void koch (int len, int level)
{
  int newlen;
  if (0 == level) {
    forwd (len);
    return;
  }
  else {
    newlen = (int) ceil (len / 3.0);
    koch (newlen, level - 1);
    turnleft (60);
    koch (newlen, level - 1);
    turnright (120);
    koch (newlen, level - 1);
    turnleft (60);
    koch (newlen, level - 1);
  }
}
Beispiel #23
0
static
void
approachintersection(void * unusedpointer,
                     unsigned long carnumber)
{
        int cardirection;

        /*
         * Avoid unused variable and function warnings.
         */

        (void) unusedpointer;
        (void) carnumber;
	(void) gostraight;
	(void) turnleft;
	(void) turnright;

        /*
         * cardirection is set randomly.
         */

	//cardirection = 0 ---> from North
	//cardirection = 1 ---> from East
	//cardirection = 2 ---> from South
	//cardirection = 3 ---> from West

        cardirection = random() % 4;

	//move = 0 ---> go straight
	//move = 1 ---> go right
	//move = 2 ---> go left

	int move = random() % 3;

	//lock the intersections if 3 cars are already inside
	P(Slock);
	if(move == 0)
		gostraight(cardirection, carnumber);
	else if(move == 1)
		turnright(cardirection, carnumber);
	else if(move == 2)
		turnleft(cardirection, carnumber);
	V(Slock);
}
Beispiel #24
0
void turnright( void)
{
                          motorALL_ON();
                               
                                motor1_Forward(); 
								motor2_OFF();
								if ((checkbit(PINF,6)!=0 && checkbit(PINF,7)!=0 && checkbit(PINF,5)!=0)||(checkbit(PINF,6)!=0 && checkbit(PINF,7)==0 && checkbit(PINF,5)!=0))  //THE CROSSOVER DETECTED
                {
					
				               
                              
								j++;
							  
								/*lcd_gotoxy2(5);
								lcd_showvalue(j);*/
								PORTC=~j;
								_delay_ms(500);	
								
				}
								//PORTC=0x01;

if(((checkbit(PINF,6)==0) && (checkbit(PINF,7)==0) && (checkbit(PINF,5)==0)||(checkbit(PINF,6)!=0) && (checkbit(PINF,7)!=0) && (checkbit(PINF,5)!=0)) )
turnright();
}
Beispiel #25
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timer1Init();
    encodersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 310;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{
                if(readpins(0) > 300)   //left
		{
                    setpwmR(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed < 315)
                        leftspeed++;
                    if(rightspeed > 275)
                        rightspeed--;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 600)
                if(readpins(2) > 600) //right
		{
                    setpwmL(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed > 265)
                        leftspeed--;
                    if(rightspeed < 325)
                        rightspeed++;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 900)
                if(readpins(1) > 900) //middle
		{
                    setpwmR(0);
                    setpwmL(0);
                    motorRstop();
                    motorLstop();
                    turnright();

                }
                //for(i = 0; i < 1500; i++){};


	}

    return (EXIT_SUCCESS);
}
task main()
{
	initializeRobot();

	ereset();

	waitForStart();

	ch = 1;

	brake();
	wait1Msec(300);
	{
		motor[motorH] = 50;
		motor[motorI] = 50;
		wait1Msec(300);
		motor[motorH] = 0;
		motor[motorI] = 0;

		movebackward();
		wait1Msec(2000);

		servo[servo3] = 247;

		brake(); //temporary stop
		wait1Msec(300);

		turnleft(); //turn  left to face the center goal structure
		wait1Msec(1100);

		brake(); //temporary stop
		wait1Msec(100);

		turnright();
		wait1Msec(1100);

		brake();
		wait1Msec(100);

		movebackward();// move forward to the center goal structure
		wait1Msec(2525);

		brake();
		wait1Msec(1000);

		if (SensorRaw(irs) > 3 && SensorRaw(irs) < 7)//checks for the ir value to know if the center goal structure is at postion 1
		{ //center goal structure is in the 1

			moveforward(); // move forward to be adjacent to the kickstand
			wait1Msec(650);

			brake(); //temporary stop
			wait1Msec(50);

			turnright(); //turn right to face the kickstand
			wait1Msec(1550);

			brake(); //temporary stop
			wait1Msec(100);

			moveforward(); //moveforward to knock down the kickstand and to be adjacent to the ir beacon and center goal
			wait1Msec(1250);

			brake();
			wait10Msec(3000);

			motor[motorH] = -50;//resets the initialize
			motor[motorI] = -50;
			wait1Msec(300);
			motor[motorH] = 0;//stops the 80/20 so that it does not move
			motor[motorI] = 0;
		}

		else if(SensorRaw(irs) <= 3 || SensorRaw(irs) >= 7)//if the ir sensor senses a value between 3 and 7
		{ //center goal is in position 2/3
			movebackward();//move the robot back to be adjacent to the ir beacon
			wait1Msec(900);

			turnleft();//turns left to check for position 2.
			wait1Msec(900);

			movebackward();//moves abckwards to be next to the ir beacon
			wait1Msec(1250);

			ch = 0;//gives the integer chicks the value of of 0
		}

		if (SensorRaw(irs) >= 7 && SensorRaw(irs) <= 8)//if ir value is between 7 and 8
		{ //center goal structure is in the 3 position

			while(SensorRaw(irs) < 5)//if it senses a value less than 5 until it senses at 5
			{
				movebackward();
			}
			moveforward();//moves the robot forward to be adjacent to the
			wait1Msec(500);

			turnright();//turn right to face the kickstand
			wait1Msec(900);

			moveforward();//knocks down the kickstand
			wait1Msec(1000);
		}

		else
		{ //center goal structure is in the 2 position
			moveforward();//move forward to be adjacent to the kickstand
			wait1Msec(1259);

			turnright();//turn right to face the kickstand
			wait1Msec(1600);

			moveforward();//move forward to knock down the kickstand
			wait1Msec(1500);
		}
	}
}
Beispiel #27
0
//returns true for limit pass, pass or put, false for movement or 
// .. inp: a,b,c,d,e,f,g :
// a: forward, b: back, c: left, d: right,
// e: put, f: pass, g: pause
bool GTPWrapper::doThis(bool first, vector<double> inp)
{
  //  cout << "dothis inp: " << printvector(inp);
  //check for limits if within inc counter..
  if(first){
    if(fcount>=thinksteps){
      setPass(first);
      return true;
    }else 
      fcount++;
  }
  if(!first){
    if(scount>=thinksteps){
      setPass(first);
      return true;
    }else
      scount++;
  }

  //needs conflict resolution
  //first check for movement(default in kens code)
  //default in con  flicts; back & forward => forward, left & righ ->left
  bool forward,back,west,east;
  forward=back=west=east=false;
  bool moving = false;
  int *heading = getHeading(first);
  if(inp.at(0)>0.5){//forward..
    moving = true;
    if(*heading == 0)
      forward = true;
    else if(*heading == 1)
      east = true;
    else if(*heading == 2)
      back = true;
    else if(*heading == 3)
      west = true;
  }
  bool turned = false;
  if(inp.at(1)>0.5){//turn left
    turnleft(first);
    turned = true;
  }else if(inp.at(2)>0.5){//right..
    turnright(first);
    turned = true;
  }
  
  if(!moving&&!turned){
    int ind = 5;
    int n = 5;
//     if(headingsupport)
//       n++;
    double max=0.5;
    for(int i=3;i<n;i++){
      if(inp.at(i)>max){
	ind = i;
	max = inp.at(i);
      }
    }
    if(ind==5){//default
      //      cout << "doing nothing.." << endl;
      return false;
    }
    if(ind==3){
//       if(!justput)
      //cout << "putting " << getColoredCoord(first) << endl; 

//       if(justput)
// 	secondput = true;
//       justput = true;
//       if(justmoved && secondput)
// 	cout << "!!!! second put " << getColoredCoord(first) << endl;
      if(put(first)){//regardless of illegal move?? heh
	moves++;
// 	if(moves>4)
// 	cout<<"four moves!!!: " << endl << getLocalBoardAscii();
	unsetPass(first);
	unsetCount(first);
      }else{
	setPass(first);
	unsetCount(first);
      }
      return true;
    }else if(ind==4){
      //      cout << "passing" << endl;
      setPass(first);
      unsetCount(first);
      return true;
    }
//     else if(headingsupport&&ind==7){
//       //      cout << "turning around!!" << endl;
      
//       unsetPass(first);
//       return false;
//     }
  }else{
//     if(!justmoved)
    //cout << "fpass:"******" spass:"******" moving(fc:"<<fcount<<" sc:"<<scount<<")" << "forward: " << forward << " back: "<<back<<" west: "<<west<<"  east:" << east<< endl;
    unsetPass(first);
//     justmoved = true;
    //    unsetCount(first);
    if(forward)
      up(first);
    if(back)
      down(first);
    if(west)
      left(first);
    if(east)
      right(first);
    return false;
  }
  return true;
}
Beispiel #28
0
     static INLINE void tracepoint (int xp, int yp, int dir, unsigned int color, int xstart, int xend, int ystart, int yend)
{
    unsigned char *calc;
    cpixeldata_t mycolor;
    int i, lookdir;
    unsigned int c;
    int x, y;
    int periodicity = (dir & 8) != 0;
    dir &= ~8;
    calc = calculated + xp + yp * CALCWIDTH;

    if (!(*calc & (CALCULATED | CALCULATING))) {
        *calc |= CALCULATING;
        mycolor = (cpixeldata_t) calculatepixel (xp, yp, periodicity);
        putpixel (xp, yp, mycolor);
        *calc |= CALCULATED;
        *calc &= ~CALCULATING;
    } else {
        if (*calc & CALCULATING) {
            /*Bad luck..some other procesor is working with out pixel :) try
             *later.*/
            addstack (xp, yp, dir, color, periodicity);
            return;
        }
        mycolor = getpixel (xp, yp);
    }

    while (1) {
        periodicity = (mycolor == inset || color == inset);
        lookdir = turnright (dir);
        for (i = 0; i < 3; i++) {
            x = xp + dirrections[lookdir][0];
            y = yp + dirrections[lookdir][1];
            if (x >= xstart && x <= xend && y >= ystart && y <= yend) {
                calc = calculated + x + y * CALCWIDTH;
                if (!(*calc & (CALCULATED | CALCULATING))) {
                    *calc |= CALCULATING;
                    c = calculatepixel (x, y, periodicity);
                    putpixel (x, y, c);
                    *calc |= CALCULATED;
                    *calc &= ~CALCULATING;
                } else {
                    if (*calc & CALCULATING) {
                        /*Bad luck..some other procesor is working with out pixel :) try
                         *later.*/
                        addstack (xp, yp, dir, color, periodicity);
                        return;
                    }
                    c = getpixel (x, y);
                }
                if (c == mycolor)
                    break;
                if (c != color) {
                    int dir2 = turnright (lookdir);
                    int mask = (1 << dir2) + (1 << turnright (dir2));
                    if (!(*calc & mask)) {
                        addstack (x, y, dir2, mycolor, periodicity);
                    }
                    color = c;
                }
            }
            lookdir = turnleft (lookdir);
        }
        x = xp + dirrections[lookdir][0];
        y = yp + dirrections[lookdir][1];
        if (x >= xstart && x <= xend && y >= ystart && y <= yend) {
            calc = calculated + x + y * CALCWIDTH;
            if (!(*calc & (1 << lookdir))) {
                *calc |= (1 << lookdir);
                if (size < 10) {
                    addstack (x, y, lookdir, color, periodicity);
                    return;
                } else {
                    xp = x;
                    yp = y;
                    dir = lookdir;
                    calc = calculated + xp + yp * CALCWIDTH;
                }
            } else
                return;
        } else
            return;
    }
}
Beispiel #29
0
void main()
{

DDRA=0XFF;
DDRC=0xFF;
//PORTC=0XFF;           //led 
                    // PORT F Initialization
DDRF=0x00;
PORTF=0xFF;            //SENSOR


DDRB=0XF0;


DDRE=0x0F;  //motor enable
int i=PINF;
    
while(1)
   { 
 
 if(checkbit(i,4)==0)
  {
  PORTA=0X00;
   
   if(( checkbit(i,6)==0 && checkbit(i,7)!=0 && checkbit(i,5)!=0) || (checkbit(i,6)==0 && checkbit(i,7)==0 && checkbit(i,5)!=0))
		turnright();
  
	else if(( checkbit(i,6)!=0 && checkbit(i,7)!=0 && checkbit(i,5)==0) || (checkbit(i,6)!=0 && checkbit(i,7)==0 && checkbit(i,5)==0))

          turnleft();
		  
  else if(checkbit(i,5)==0 && checkbit(i,7)!=0 && checkbit(i,6)==0)                               
	{
		motorALL_ON();
		motor2_Forward();   
	   motor1_Forward();
		//PORTC=0x00;
		
			 if ((checkbit(i,6)!=0 && checkbit(i,7)!=0 && checkbit(i,5)!=0)||(checkbit(i,6)!=0 && checkbit(i,7)==0 && checkbit(i,5)!=0))  //THE CROSSOVER DETECTED
                {
					
				               
                              motorALL_ON();
                               motor2_Forward();   
							   motor1_Forward();
								j++;
							  
								/*lcd_gotoxy2(5);
								lcd_showvalue(j);*/
								PORTC=~j;
								_delay_ms(500);	
								
				}
	}
}						
	else
	 {
	    PORTA=0X0A;
        //_delay_ms(500);
        //PORTA=0X00; 
        motor2_OFF();
		motor1_OFF();
		motorALL_OFF();
		
		}

     }
  
}
Beispiel #30
0
void decidemove(player& pl)
{
    if (pl.wrongsteps <= 3 &&
	pl.steps <= 3)
    {
	return;
    }

    int r = rand()%30;
    switch(r)
    {
    case 0:
	    if (isrightempty(pl))
	    {
		turnright(pl);
		pl.steps = 0;
	    }
	    else if (isleftempty(pl))
	    {
		turnleft(pl);
	    pl.steps = 0;
	    }
	    break;
    case 1:
	if (isleftempty(pl))
	{
		turnleft(pl);
		pl.steps = 0;
	    }
	    else if (isrightempty(pl))
	    {
		turnright(pl);
		pl.steps = 0;
	}
	break;
    }

    if (isaheadempty(pl))
    {
	return;
    }
    else if (r%2 == 0)
    {
	if (isleftempty(pl))
	{
	    turnleft(pl);
	    pl.steps = 0;
	}
	else if (isrightempty(pl))
	{
	    turnright(pl);
	    pl.steps = 0;
	}
    }
    else
    {
	if (isrightempty(pl))
	{
	    turnright(pl);
	    pl.steps = 0;
	}
	else if (isleftempty(pl))
	{
	    turnleft(pl);
	    pl.steps = 0;
	}
    }

    if (r==0)
    {
	turnleft(pl);
	pl.steps = 0;
    }
    else if (r==1)
    {
	turnright(pl);
	pl.steps = 0;
    }
}