static void btl(int s, int, BS &b) { inc(turn(b,s)["CriticalRaise"], 1); }
Point2D < T > turn(const Point2D < T > &Point, const Point2D < T > &Of, const T &alpha) { Point2D < T > Tmp = turn(Point2D < T > (Point.x - Of.x, Point.y - Of.y), alpha); return Point2D < T > (Tmp.x + Of.x, Tmp.y + Of.y); }
static void btl(int s, int, BS &b) { if (turn(b,s)["Power"].toInt() > 0) { inc(turn(b,s)["CriticalRaise"], 2); } }
void rightDeg(int d) { turn(-d*PI/180.0); }
void ZagrosMotorsCmd::skypeCallback( const std_msgs::String& msgSkype) { numSteps = strlen( (const char* ) msgSkype.data.c_str()); if ( numSteps > 10 ) numSteps = 2; // likely just a mistake of holding down too many characters else if (numSteps > 5) numSteps = 5; for (int i = 1; i < numSteps; i++) if ( (msgSkype.data[i] != msgSkype.data[0]) && msgSkype.data[i] != msgSkype.data[0] + 32) return; // if string is not all identical characters, allowing for first character to be a capital, return cmdChar = msgSkype.data[0]; switch(cmdChar) // motor command { case 'w': // move forward case 'W': case 's': //move backward case 'S': move(); break; case 'd': //turn right case 'D': case 'a': // turn left case 'A': turn(); break; // ---------------------------------------------------------------------------------- // this block was added to support GUI driving, e.g., not driving with 1-5 characters // alaina 2012-03-12 // ---------------------------------------------------------------------------------- case 'o': // move forward without stopping case 'O': // move forward without stopping cmdChar = 'w'; // reset it to the forward character moveNoStop(); // accelerate and drive forward but don't stop after a certain number of steps break; case 'l': //move backward without stopping case 'L': //move backward without stopping cmdChar = 's'; // reset to the backward character moveNoStop(); // accelerate and drive backward but don't stop after a certain number of steps break; case 'c': //turn right without stopping case 'C': //turn right without stopping cmdChar = 'd'; // reset to "turn right" character turnNoStop(); // turn but don't stop after a certain number of steps break; case 'i': // turn left without stopping case 'I': // turn left without stopping cmdChar = 'a'; // reset to "turn left" character turnNoStop(); // turn but don't stop after a certain number of steps break; case 'x': slowStop(); // stop with deceleration break; case 'z': stop(); // stop with no deceleration break; // ---------------------------------------------------------------------------------- // end block - alaina 2012-03-12 // ---------------------------------------------------------------------------------- default: // unknown command //stop(); w// we need to ignore, not stop because otherwise we will stop when people are just saying stuff like "hi" break; } }
void driveBackFromCascade () { turn(-180); drive(36); turn(-90); }
void smugglecom_driver(int cn,int ret,int lastact) { struct smugglecom_data *dat; struct staffer_ppd *ppd; int co,in,didsay=0,talkdir=0; struct msg *msg,*next; dat=set_data(cn,DRD_SMUGGLECOMDRIVER,sizeof(struct smugglecom_data)); if (!dat) return; // oops... // loop through our messages for (msg=ch[cn].msg; msg; msg=next) { next=msg->next; // did we see someone? if (msg->type==NT_CHAR) { co=msg->dat1; // dont talk to other NPCs if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; } // dont talk to players without connection if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; } // only talk every ten seconds if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; } if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; } // dont talk to someone we cant see, and dont talk to ourself if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; } // dont talk to someone far away if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; } // get current status with player ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd)); if (ppd) { switch(ppd->smugglecom_state) { case 0: quiet_say(cn,"Greetings, %s!",ch[co].name); questlog_open(co,35); ppd->smugglecom_state++; didsay=1; break; case 1: quiet_say(cn,"I want you to find a book for me called 'the contraband book', which contains the names of four of the smuggler's most precious items."); ppd->smugglecom_state++; didsay=1; break; case 2: //quiet_say(cn,"Also, I will reward you for every piece of contraband you bring me. "); //ppd->smugglecom_state++; didsay=1; //break; // fall through intended for now case 3: quiet_say(cn,"Go now, and may Ishtar be with you."); ppd->smugglecom_state=4; didsay=1; break; case 4: break; case 5: if (questlog_isdone(co,36)) { ppd->smugglecom_state=7; break; } quiet_say(cn,"It lists four important items which I want you to retrieve: the Rainbow Pearls, the Crimson Ring, the Leopard Cape, and the Emerald Necklace. Find them, and bring them to me."); questlog_open(co,36); ppd->smugglecom_state++; didsay=1; break; case 6: if (ppd->smugglecom_bits==15) { ppd->smugglecom_state++; questlog_done(co,36); } break; case 7: quiet_say(cn,"Thank you, you are of great help in hurting the smuggler's operations."); if (questlog_isdone(co,37)) { ppd->smugglecom_state=10; break; } quiet_say(cn,"Now, as a final task, I want you to kill the smuggler's leader. Good luck!"); questlog_open(co,37); ppd->smugglecom_state++; didsay=1; break; case 8: break; case 9: quiet_say(cn,"Thank you for helping us, %s, you have been of great value.",ch[co].name); ppd->smugglecom_state++; didsay=1; questlog_done(co,37); break; case 10: break; } if (didsay) { dat->last_talk=ticker; talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y); dat->current_victim=co; notify_area(ch[cn].x,ch[cn].y,NT_NPC,NTID_DIDSAY,cn,0); } } } // talk back if (msg->type==NT_TEXT) { co=msg->dat3; if (ch[co].flags&CF_PLAYER) { ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd)); switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) { case 2: if (ppd && ppd->smugglecom_state<=4) { dat->last_talk=0; ppd->smugglecom_state=0; } if (ppd && ppd->smugglecom_state>=5 && ppd->smugglecom_state<=6) { dat->last_talk=0; ppd->smugglecom_state=5; } if (ppd && ppd->smugglecom_state>=7 && ppd->smugglecom_state<=8) { dat->last_talk=0; ppd->smugglecom_state=7; } break; case 3: if (ch[co].flags&CF_GOD) ppd->smugglecom_bits=ppd->smugglecom_state=0; break; } if (didsay) { talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y); dat->current_victim=co; } } } // got an item? if (msg->type==NT_GIVE) { co=msg->dat1; if ((in=ch[cn].citem)) { // we still have it int val; ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd)); if (it[in].ID==IID_STAFF_SMUGGLEBOOK && ppd && ppd->smugglecom_state<=4 && (ch[co].flags&CF_PLAYER)) { quiet_say(cn,"Thank you for the book, %s.",ch[co].name); questlog_done(co,35); destroy_item_byID(co,IID_STAFF_SMUGGLEBOOK); ppd->smugglecom_state=5; } else if (it[in].ID==IID_STAFF_SMUGGLEPEARLS && ppd && !(ppd->smugglecom_bits&SMUGGLEBIT_PEARLS) && (ch[co].flags&CF_PLAYER)) { quiet_say(cn,"Thank you for bringing back the %s, %s.",it[in].name,ch[co].name); val=questlog_scale(questlog_count(co,36),1000); dlog(co,0,"Received %d exp for doing quest Contraband I for the %d. time (nominal value %d exp)",val,questlog_count(co,36)+1,1000); give_exp(co,min(val,level_value(ch[co].level)/4)); ppd->smugglecom_bits|=SMUGGLEBIT_PEARLS; } else if (it[in].ID==IID_STAFF_SMUGGLERING && ppd && !(ppd->smugglecom_bits&SMUGGLEBIT_RING) && (ch[co].flags&CF_PLAYER)) { quiet_say(cn,"Thank you for bringing back the %s, %s.",it[in].name,ch[co].name); val=questlog_scale(questlog_count(co,36),1000); dlog(co,0,"Received %d exp for doing quest Contraband II for the %d. time (nominal value %d exp)",val,questlog_count(co,36)+1,1000); give_exp(co,min(val,level_value(ch[co].level)/4)); ppd->smugglecom_bits|=SMUGGLEBIT_RING; } else if (it[in].ID==IID_STAFF_SMUGGLECAPE && ppd && !(ppd->smugglecom_bits&SMUGGLEBIT_CAPE) && (ch[co].flags&CF_PLAYER)) { quiet_say(cn,"Thank you for bringing back the %s, %s.",it[in].name,ch[co].name); val=questlog_scale(questlog_count(co,36),1000); dlog(co,0,"Received %d exp for doing quest Contraband III for the %d. time (nominal value %d exp)",val,questlog_count(co,36)+1,1000); give_exp(co,min(val,level_value(ch[co].level)/4)); ppd->smugglecom_bits|=SMUGGLEBIT_CAPE; } else if (it[in].ID==IID_STAFF_SMUGGLENECKLACE && ppd && !(ppd->smugglecom_bits&SMUGGLEBIT_NECKLACE) && (ch[co].flags&CF_PLAYER)) { quiet_say(cn,"Thank you for bringing back the %s, %s.",it[in].name,ch[co].name); val=questlog_scale(questlog_count(co,36),1000); dlog(co,0,"Received %d exp for doing quest Contraband IV for the %d. time (nominal value %d exp)",val,questlog_count(co,36)+1,1000); give_exp(co,min(val,level_value(ch[co].level)/4)); ppd->smugglecom_bits|=SMUGGLEBIT_NECKLACE; } else { quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all."); if (give_char_item(co,ch[cn].citem)) ch[cn].citem=0; } // let it vanish, then if (ch[cn].citem) { destroy_item(ch[cn].citem); ch[cn].citem=0; } } } remove_message(cn,msg); } // do something. whenever possible, call do_idle with as high a tick count // as reasonable when doing nothing. dat->amgivingback=0; if (talkdir) turn(cn,talkdir); if (dat->last_talk+TICKS*30<ticker) { if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return; } do_idle(cn,TICKS); }
task main() { gyroCal(); move(82, 25); turn(90, 20); findLine(-40, 25); move(15, 25); lower(); tmove(-2000, 30); // raise house raise(); findLine(40, 25); turn(90, 20); tmove(-2500, 30); move(7, 30); turn(90, 20); findLine(-40, 25); lower(); move(3, 25); raise(); //flip stove move(7, 30); turn(270, 25); tmove(-2000, 30); findLine(40, 30); move(5, 15); turn(70, 15); move(60, 30); turn(20, 15); tmove(2000, 25); move(-4, 20); turn(90, 15); findLine(40, 20); move(10, 15); // push sign findLine(-40, 20); move(-25, 30); turn(90, 20); tmove(-1500, 25); move(22, 20); turn(40, 20); move(40, 20); //herd food pmove(30, 20, 25); move(-5, 20); turn(70, 20); tmove(1500, 20); move(-2, 20); turn(90, 15); move(30, 20); lower(); move(20, 20); }
void goOnRamp(int loc) { if(loc == 1) { turn(55,45,L_CODE); movein(40,21); turn(55,55,R_CODE); movein(40,35); turn(55,90,R_CODE); movein(40,33); } else if(loc == 2) { turn(55,58,L_CODE); movein(40,22); turn(55,55,R_CODE); movein(40,36); turn(55,100,R_CODE); movein(40,36); } else if(loc == 3) { turn(55,60,R_CODE); movein(40,22); turn(55,55,L_CODE); movein(40,36); turn(55,100,L_CODE); movein(40,36); } else{ turn(55,45,R_CODE); movein(40,22); turn(55,55,L_CODE); movein(40,35); turn(55,90,L_CODE); movein(40,32); } }
void Turtle::turnLeft(){ turn(turnAngle); }
void Turtle::turnRight(){ turn(-turnAngle); }
static void tu(int s, int, BS &b) { if (b.true_rand() % 5 == 0) { turn(b,s)["TurnOrder"] = 2; turn(b,s)["QuickClawed"] = true; } }
static void m2m(int s, int, BS &b) { turn(b,s)["ItemMod2Modifier"] = poke(b,s)["IMMetroCount"]; }
static void btl(int s, int, BS &b) { if (poke(b,s)["Num"] == poke(b,s)["ItemArg"]) { inc(turn(b,s)["CriticalRaise"], 2); } }
//Move to the goal so we can pick it hookUpGoal void moveToGoal() { //Sebastian turn(135); drive(23); }
void turnRight() { string direction = "right"; turn(direction); }
void driveToCascade () { turn(-90); drive(12); turn(90); drive(12); }
int main(int argc, char *argv[]) { int index_size = 1048576; int argnr = 1; int i; if (argc < 3) { printf("Usage: %s [-i size] <in-file> <out-file>\n\n", argv[0]); printf(" -i size\tIndex size, must be a multiple of 2 (default=1048576).\n\n"); return 0; } while (argv[argnr][0]=='-') { if (!strcmp(argv[argnr], "-i")) { argnr++; index_size = atoi(argv[argnr]); } argnr++; } union byte4 mask, increment; mask.i = turn(index_size -1); increment.i = 0x80000000 / (index_size/2); for (i=0; i<4; i++) { switch (mask.byte[i]) { case 0x00: case 0xff: break; case 0x01: mask.byte[i] = 0x80; break; case 0x03: mask.byte[i] = 0xc0; break; case 0x07: mask.byte[i] = 0xe0; break; case 0x0f: mask.byte[i] = 0xf0; break; case 0x1f: mask.byte[i] = 0xf8; break; case 0x3f: mask.byte[i] = 0xfc; break; case 0x7f: mask.byte[i] = 0xfe; break; default: fprintf(stderr, "Error: index_size must be multiple of 2!\n"); return -1; } } // printf("mask = %.8x\n", mask.i); // printf("increment = %.8x\n", increment.i); FILE *infile = fopen(argv[argnr], "r"), *outfile = fopen(argv[argnr+1], "w"); if (infile == NULL) { perror("Could not open file for reading.\n\n"); return -1; } if (outfile == NULL) { perror("Could not open file for writing.\n\n"); return -1; } buffer = malloc(buffer_size * sizeof(record)); outbuf = malloc(outbuf_size * sizeof(off_t)); unsigned int current = 0; off_t address = 0; int outpos = 0; // printf("------- %.8x --------------------------------------------------------------------------------\n", current); outbuf[outpos++] = address; while (!feof(infile)) { int num_items = fread(buffer, sizeof(record), buffer_size, infile); printf("."); fflush(stdout); for (i=0; i<num_items; i++) { int top = turn(*(unsigned int*)&buffer[i].sha1[0]); while ((top&mask.i) > current) { current+= increment.i; // printf("------- %.8x -------------------------------------------------------------------------------- %i\n", current, address); outbuf[outpos++] = address; if (outpos >= outbuf_size) { // Flush output-buffer: fwrite(outbuf, sizeof(off_t), outbuf_size, outfile); outpos = 0; printf("o"); fflush(stdout); } } /* int j; for (j=0; j<20; j++) printf("0x%.2X,", buffer[i].sha1[j]); printf("\t%.8X", buffer[i].DocID); // printf("\t%.8x %.8x", top, top & mask.i); printf("\n"); */ address+= sizeof(record); } } fwrite(outbuf, sizeof(off_t), outpos, outfile); fclose(infile); fclose(outfile); }
task main() { initializeRobot(); int waitValue = 0; nNxtExitClicks = 3; while (nNxtButtonPressed != 0 && nNxtButtonPressed != 3){ nxtDisplayCenteredTextLine(0, "%d milliseconds", waitValue); if (nNxtButtonPressed == 1){ waitValue += 1000; wait1Msec(325); } if (nNxtButtonPressed == 2){ waitValue -= 1000; wait1Msec(300); } if (waitValue > 30000) waitValue = 30000; if (waitValue < 0) waitValue = 0; } waitForStart(); wait1Msec(waitValue); int ir = 0; resetEncoders(); int dist1 = 16*in; // 1st search and raise lift ClearTimer(T1); while (leftEnc() < dist1+(43*in) && ir == 0) { move(-a); if (time1[T1] < b) { lift(100); } else { lift(0); } if (SensorValue[infared] >= 4 && leftEnc() > dist1) ir = 1; } move(0); // finish raising lift while (time1[T1] < b) { lift(100); } lift(0); // ir not found if (ir == 0) ir = 2; // align if (ir == 1) { wait1Msec(100); if ( (abs(nMotorEncoder[Left]) > dist1) && (abs(nMotorEncoder[Left]) < dist1+9.5*in) ) d = 2*in; if ( (abs(nMotorEncoder[Left]) > dist1+(9.5*in)) && (abs(nMotorEncoder[Left]) < dist1+(21.5*in)) ) d = 12*in; if ( (abs(nMotorEncoder[Left]) > dist1+(21.5*in)) && (abs(nMotorEncoder[Left]) < dist1+(38*in)) ) d = 31*in; if ( (abs(nMotorEncoder[Left]) > dist1+(38*in)) && (abs(nMotorEncoder[Left]) < dist1+(43*in)) ) d = 41*in; while( ((abs(nMotorEncoder[Left])/in)+1 < (dist1+d)/in) ^ ((abs(nMotorEncoder[Left])/in)-1 > (dist1+d)/in) )//while( int(abs(nMotorEncoder[Left])) != int(dist1+d) ) { if (abs(nMotorEncoder[Left]) > dist1+d) move(20); if (abs(nMotorEncoder[Left]) < dist1+d) move(-20); } move(0); } if (ir == 2) { wait1Msec(500); while (abs(nMotorEncoder[Left]) > dist1) move(a); } move(0); // dump cube servo[bucket] = 245; wait1Msec(1500); servo[bucket] = 130; wait10Msec(100); // move to end of row and lower lift ClearTimer(T1); while (abs(nMotorEncoder[Left]) > (dist1-(6*in))) { move(a); if (time1[T1] < 1400) { motor[Lift1] = -100; motor[Lift2] = -100; } else { motor[Lift1] = 0; motor[Lift2] = 0; } } move(0); // swing 90 deg right and lower lift resetEncoders(); while (abs(nMotorEncoder[Left]) < 24*in) { swingRight(a); if (time1[T1] < c) { motor[Lift1] = -100; motor[Lift2] = -100; } else { motor[Lift1] = 0; motor[Lift2] = 0; } } move(0); // move infront of ramp resetEncoders(); while (abs(nMotorEncoder[Left]) < 21*in) { move(a); if (time1[T1] < c) { motor[Lift1] = -100; motor[Lift2] = -100; } else { motor[Lift1] = 0; motor[Lift2] = 0; } } move(0); // turn 90deg left resetEncoders(); while (abs(nMotorEncoder[Left]) < 9.5*in) { turn(-a); if (time1[T1] < c) { motor[Lift1] = -100; motor[Lift2] = -100; } else { motor[Lift1] = 0; motor[Lift2] = 0; } } move(0); //finish lowering lift while (time1[T1] < c) { motor[Lift1] = -100; motor[Lift2] = -100; } motor[Lift1] = 0; motor[Lift2] = 0; // move up ramp wait1Msec(250); resetEncoders(); while (abs(nMotorEncoder[Left]) < 30*in) move(-100); move(0); }
void Character::lookAt(Coordinate* c){ if(path != NULL) stopMoving(); turn(dirTo(c)); }
task main() { //waitForStart(); /*wait1Msec(2000); motor[armLeft] = 100; motor[armRight] = 100; motor[plow] = 75; wait1Msec(100); motor[plow] = 0; motor[armLeft] = 0; motor[armRight] = 0;*/ bool nope = false; nMotorEncoder[driveLeft] = 0; while(nMotorEncoder[driveLeft] < 4500) { motor[driveLeft] = 100; motor[driveRight] = 100; } motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(200); nMotorEncoder[driveLeft] = 0; turn(-120,75); /*while(abs(nMotorEncoder[driveLeft]) < 2100) //1800 { motor[driveLeft] = -100; motor[driveRight] = 100; }*/ motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(200); nMotorEncoder[driveLeft] = 0; while(SensorValue[IR] != 5) { writeDebugStreamLine("%d", SensorValue[IR]); //writeDebugStreamLine("%d", nMotorEncoder[driveLeft]); //if(time1[T1] > 6000) //break; //else //{ if(nMotorEncoder[driveLeft] > 5500) { nope = true; break; } motor[driveLeft] = 100; motor[driveRight] = 100; //} } //time1[T1] = 0; motor[driveLeft] = 0; motor[driveRight] = 0; int temp = nMotorEncoder[driveLeft]; if(!nope) { while(nMotorEncoder[driveLeft] < (temp+200)) { motor[driveLeft] = 100; motor[driveRight] = 100; } motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(750); } writeDebugStreamLine("%d", nMotorEncoder[driveLeft]); servo[cube] = 0; wait1Msec(800); servo[cube] = 125; wait1Msec(800); nMotorEncoder[driveLeft] = 0; /*while(SensorValue[Ultra] > 25) { motor[driveLeft] = -100; motor[driveRight] = -100; } motor[driveLeft] = 0; motor[driveRight] = 0;*/ if(!nope) { while(nMotorEncoder[driveLeft] > (-temp - 300)) { motor[driveLeft] = -100; motor[driveRight] = -100; } motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(400); } else { while(nMotorEncoder[driveLeft] > (-5250 - 150)) { motor[driveLeft] = -100; motor[driveRight] = -100; } motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(400); } turn(-30,75); nMotorEncoder[driveLeft] = 0; /*while(nMotorEncoder[driveLeft] > -4500) { motor[driveLeft] = -100; motor[driveRight] = -100; }*/ motor[driveLeft] = -100; motor[driveRight] = -100; wait1Msec(1500); motor[driveLeft] = 0; motor[driveRight] = 0; wait1Msec(300); turn(-75,75); nMotorEncoder[driveLeft] = 0; /*while(nMotorEncoder[driveLeft] > -3800) { motor[driveLeft] = -100; motor[driveRight] = -100; }*/ motor[driveLeft] = -100; motor[driveRight] = -100; wait1Msec(1500); motor[driveLeft] = 0; motor[driveRight] = 0; }
task main() { init(); waitForStart(); StartTask(keepHeading); StartTask(raiseLiftWhile); driveSonar(1,25,50); allStop(); wait1Msec(100); backward(20); wait1Msec(700); sticksDown(); wait1Msec(250); allStop(); wait1Msec(300); //LIFT releaseBalls(); allStop(); wait1Msec(3000); retainBalls(); allStop(); wait1Msec(750); lowerLift(80); while (nMotorEncoder[intake] > 220) //while the encoder wheel turns one revolution { } allStop(); wait1Msec(100); turn(1,19,70); allStop(); wait1Msec(100); drive(0,2.0,100); allStop(); wait1Msec(100); turn(0,170,100); allStop(); wait1Msec(100); sticksUp(); drive(1,.3,100); allStop(); wait1Msec(100); turn(0,180,100); allStop(); wait1Msec(100); //while(SensorValue[sonarSensor]>40){ // backward(100); //} //turnToGlobalHeading(-15); allStop(); wait1Msec(100); drive(1,1.3,100); allStop(); wait1Msec(100); turnToGlobalHeading(-78); allStop(); wait1Msec(100); while(SensorValue[sonarSensor]>25){ backward(30); } allStop(); wait1Msec(100); while(SensorValue[sonarSensor]<200){ left(50); } allStop(); wait1Msec(100); turn(0,18,100); allStop(); wait1Msec(100); driveSonar(1,25,50); backward(30); wait1Msec(700); sticksDown(); wait1Msec(250); allStop(); turn(1,17,70); allStop(); wait1Msec(100); drive(0,2.7,100); allStop(); wait1Msec(100); turn(0,175,100); allStop(); wait1Msec(50); sticksUp(); drive(1,.8,100); }
void leftDeg(int d) { turn(d*PI/180.0); }
void IRramp(int left , int delay) { int mult = 1; int beacon = 0; int boost = 0; if(left) //account for starting position mult = - 1; else mult = 1; if(delay) // wait for other team but go faster { wait1Msec(5000); boost = 20; } else boost = 0; if(!left) { // get intp initial position move(mult * 10, 20 + boost); turn(mult * -42, 40 + boost); //Raise the arm while(nMotorEncoder[arms] > -4900) { motor[arms] = -30; } motor[arms] = 0; wait10Msec(25); } else { //get into initial postion move(mult * 15, 20 + boost); turn(mult * -44, 40 + boost); move(-25, 20); wait10Msec(25); //raise the arm while(nMotorEncoder[arms] > -4900) { motor[arms] = -30; } motor[arms] = 0; } //check at each position if(getSeeker()) { beacon = 1; writeDebugStreamLine("found becon at 1"); dump(left); } if(!beacon) { adjustedMove(mult * 25, 20 + boost); wait1Msec(250); if(getSeeker() && !beacon) { beacon = 2; writeDebugStreamLine("found becon at 2"); dump(left); } if(!beacon) { adjustedMove( mult * 55, 20 + boost); wait10Msec(25); if(getSeeker() && !beacon) { beacon = 3; writeDebugStreamLine("found becon at 3"); dump(left); } if(!beacon) { adjustedMove(mult * 25, 20 + boost); wait10Msec(25); beacon = 4; writeDebugStreamLine("found becon at 4"); //arived at last basket w/o sensing beacon, dump regardless dump(left); } } } wait10Msec(50); //decide how far to go based on position int add = 0; if(beacon == 1) add = 100; else if(beacon == 2) add = 75; else if(beacon == 3) add = 25; else add = 0; if(left) add += 25; //lift the wrist back up while(nMotorEncoder[wrist1] < -5) { motor[wrist1] = 20; motor[wrist2] = 20; } motor[wrist1] = 0; motor[wrist2] = 0; //drive to end of baskets if(left) { turn(-90, 50 + boost); move(mult * (15+add), 50 + boost); while(nMotorEncoder[arms] < -250) { motor[arms] = 40; } motor[arms] = 0; } else { turn(-90, 50 + boost); while(nMotorEncoder[arms] < -250) { motor[arms] = 40; } motor[arms] = 0; move(mult * (15+add), 50 + boost); } //two-point turn in tight space turn(mult * 45, 50 ); move(mult * 25, 50 + boost); turn(mult * 30, 50 ); move(mult * 80, 50 + boost); turn(-90, 50 + boost); //Drive onto ramp move(-50, 70 + boost); move(-40, 90); }
SHAPE_LINE_CHAIN PNS_MEANDER_SHAPE::genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, PNS_MEANDER_TYPE aType, int aAmpl, int aBaselineOffset ) { const PNS_MEANDER_SETTINGS& st = Settings(); int cr = cornerRadius(); int offset = aBaselineOffset; int spc = spacing(); if( aSide ) offset *= -1; VECTOR2D dir_u_b( aDir.Resize( offset ) ); VECTOR2D dir_v_b( dir_u_b.Perpendicular() ); if( 2 * cr > aAmpl ) { cr = aAmpl / 2; } if( 2 * cr > spc ) { cr = spc / 2; } m_meanCornerRadius = cr; SHAPE_LINE_CHAIN lc; start( &lc, aP + dir_v_b, aDir ); switch( aType ) { case MT_EMPTY: { lc.Append( aP + dir_v_b + aDir ); break; } case MT_START: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); break; } case MT_FINISH: { start( &lc, aP - dir_u_b, aDir ); turn ( 90 ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); break; } case MT_TURN: { start( &lc, aP - dir_u_b, aDir ); turn( 90 ); forward( std::abs( offset ) ); uShape ( aAmpl - cr, cr + offset, spc - 2 * cr ); forward( std::abs( offset ) ); break; } case MT_SINGLE: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); lc.Append( aP + dir_v_b + aDir.Resize ( 2 * st.m_spacing ) ); break; } default: break; } if( aSide ) { SEG axis ( aP, aP + aDir ); for( int i = 0; i < lc.PointCount(); i++ ) lc.Point( i ) = reflect( lc.CPoint( i ), axis ); } return lc; }
Vector2D < T > turn(const Vector2D < T > &Vector, const Point2D < T > &Of, const T &alpha) { Point2D < T > Tmp = turn(Point2D < T >(-Of.x + Vector.x, -Of.y + Vector.y), alpha); return Vector2D < T > (Of.x + Tmp.x, Of.y + Tmp.y); }
static void ts(int s, int, BS &b) { addFunction(turn(b,s), "BeforeTargetList", "FocusEnergy", &btl); }
//Used to drive off the ramp, activated by the public boolean instance field, startOnRamp void driveOffRamp() { drive(70); turn(-90); drive(47); }
int othello_ai::turn(othello16 o_upper, int player, int backpoint, int depth) { // 检查超时 int runtime = get_time(); if (runtime > 1800) { std::cerr<<"time "<<runtime<<" overflow"<<std::endl; return (player == o.mycolor) ? MAXVALUE : -MAXVALUE; } -- depth; // std::cerr<<"player "<<player<<" my color "<<o.mycolor<<std::endl; othello16 o_t; int value_t, value_mark; std::pair<int, int> step_mark (-1, -1); // 初始化value_mark if (player == o.mycolor) { value_mark = -MAXVALUE; } else { value_mark = MAXVALUE; } std::vector< std::pair<int, int> > nextlist = o_upper.allmove(player); std::string map = o_upper.tostring(); if ( nextlist.size() == 0 ) { // 无可下点 std::cerr<<"nowhere to move "; return (player == o.mycolor) ? -MAXVALUE : MAXVALUE; } else if (depth <= 0) { // 到达最深层,计算估价函数值 // std::cerr<<"tree hight "<<depth<<std::endl; std::vector< std::pair<int, int> >::iterator it; for (it = nextlist.begin() ; it != nextlist.end(); ++ it) { // 初始化当前棋盘 o_t.init(o.mycolor, map); // 落子 o_t.play(player, (*it).first, (*it).second); // string2map(o_t.tostring()); value_t = evaluation(o_t, player); std::cerr<<std::endl<<"depth "<<DEPTH - depth<<":"; for (int k = 0; k < DEPTH - depth; k ++) std::cerr<<" "; std::cerr<<"leaf ("<<(*it).first<<", "<<(*it).second<<") value "<<value_t<<", "; if ( (player == o.mycolor && value_t >= value_mark) || (player != o.mycolor && value_t <= value_mark) ) { value_mark = value_t; } // 剪枝 if (player == o.mycolor && value_mark >= backpoint) { std::cerr<<"cut beta parent value "<<backpoint<<" current value "<<value_mark<<std::endl; return value_mark; } else if (player != o.mycolor && value_mark <= backpoint) { std::cerr<<"cut alpha parent value "<<backpoint<<" current value "<<value_mark<<std::endl; return value_mark; } } return value_mark; } else { // 普通情况 std::vector< std::pair<int, int> >::iterator it; for (it = nextlist.begin() ; it != nextlist.end(); ++ it) { // 初始化当前棋盘 o_t.init(o.mycolor, map); // 落子 o_t.play(player, (*it).first, (*it).second); // string2map(o_t.tostring()); value_t = turn(o_t, 3 - player, value_mark, depth); if (value_t == MAXVALUE || value_t == -MAXVALUE) { // 子问题超时 break; } std::cerr<<std::endl<<"depth "<<DEPTH - depth<<":"; for (int k = 0; k < DEPTH - depth; k ++) std::cerr<<" "; std::cerr<<"node ("<<(*it).first<<", "<<(*it).second<<") value "<<value_t<<", "; if ( (player == o.mycolor && value_t >= value_mark)// 己方落子 || (player != o.mycolor && value_t <= value_mark) ) {//对方落子 value_mark = value_t; step_mark.first = (*it).first; step_mark.second = (*it).second; } // 剪枝 if (player == o.mycolor && value_mark >= backpoint) { std::cerr<<"cut beta parent value "<<backpoint<<" current value "<<value_mark<<std::endl; break; } else if (player != o.mycolor && value_mark <= backpoint) { std::cerr<<"cut alpha parent value "<<backpoint<<" current value "<<value_mark<<std::endl; break; } } if (depth = DEPTH - 1) { next.first = step_mark.first; next.second = step_mark.second; } return value_mark; } }
static void atl(int s, int, BS &b) { if (turn(b,s).value("ActivateLifeOrb").toBool() && !b.hasWorkingAbility(s, Ability::MagicGuard)) { //b.sendItemMessage(21,s); b.inflictDamage(s,b.poke(s).totalLifePoints()/10,s); } }