bool makeObs (float x, float y) { vec pos = {x, y, floatZero}, deg30 = {0.5f, floatZero, floatZero}; if (hitTarget(myState, pos)) { setVelocity(zeroVec); setTargetAngVel(deg30); if (!startedYet) { #if printDebug DEBUG(("Started obstacle\n")); #endif game.startObstacle(); } else { float curSize = game.getCurrentObstacleSize(); if (dust < floatItsml || curSize > 0.299f || curSize - prevSize < floatItsml) { #if printDebug DEBUG(("Ended obstacle\n")); #endif game.stopObstacle(); return true; } prevSize = curSize; } startedYet = true; } else { api.setPositionTarget(pos); //slowGo(pos); startedYet = false; setTargetAngVel(zeroVec); prevSize = floatZero; } return false; }
void remDust () { int count = game.getIdentifiedObstacles(obstacles); for (int i = 0; i < count; i ++) { if (obstacles[i].visible && chg) { game.shrinkObstacle(obstacles[i].ID); return; } } }
void loop() { //Variable Initialization time ++; api.getMyZRState(myState); api.getOtherZRState(otherState); phase = game.getCurrentPhase(); fuel = game.getFuelRemaining(); myScore = game.getScore(); otherScore = game.getOtherScore(); dust = game.getRemainingMaterial(); chg = game.getCharge(); if (time < 2) { red = statePos(myState)[0] < floatZero; } //Debug Console DEBUG(("\nDevilTech Message Screen: Fall 2012\n")); #if printDebug DEBUG(("Debug Info\n")); DEBUG(("\tTime (s)\t%d\tPhase\t%d\tPlayer\t%s\n", time, phase, (red ? "Red" : "Blue"))); DEBUG(("\tFuel\t%.3f\tDust\t%.3f\tChg\t%d\n", fuel, dust, chg)); DEBUG(("\tScore\t%.2f\tOther Score\t%.2f\n", myScore, otherScore)); DEBUG(("\tOther Message\t%u\n", otherMessage)); printVec("\tMy Pos (m)", statePos(myState)); printVec("\tMy Vel (m/s)", stateVel(myState)); printVec("\tMy Att (unitvec)", stateAtt(myState)); printVec("\tMy AngVel (rad/s)", stateAngVel(myState)); printVec("\tOther Pos (m)", statePos(otherState)); printVec("\tOther Vel (m/s)", stateVel(otherState)); printVec("\tOther Att (unitvec)", stateAtt(otherState)); printVec("\tOther AngVel (rad/s)", stateAngVel(otherState)); #endif //Game Logic vec temp; game.getItemLocation(2, temp); if (!game.haveObject(0)) getItem(0);/* else if (!game.haveObject(1) && !game.otherHasObject(1) && count2 < 25) { getItem(1); count2 ++; }*/ else if (!game.haveObject(2) && !game.otherHasObject(2) && disBetweenPts(otherState, temp) > 0.075f && count3 < 25) { getItem(2); count3 ++; } else { smartGo(red ? 0.055f : -0.055f, -0.065f); if (phase == 3) removeObs(); } }
void removeObs () { int num = game.getVisibleObstacles(obstacles); for (int i = 0; i < num; i ++) { int m = 3; while (chg && m) { chg --; m --; game.shrinkObstacle(obstacles[i].ID); } } }
//END::PAGE::Absolute Value //BEGIN::PAGE::gotoItem // makes SPHERE go to specified item void gotoItem(int n) { api.getMyZRState(sphere); game.getItemLocation(n, itemLoc); api.setPositionTarget(itemLoc); if(isClose(itemLoc) && isStopSpin() && isStopMove()) { if(startTurnX == n) { if(startX > 0) { torques[0] = -sphere[7]; torques[1] = sphere[6]; } else if(startX < 0) { torques[0] = sphere[7]; torques[1] = -sphere[6]; } api.setAttitudeTarget(torques); startTurnX = startTurnX + 1; } } else { if(startTurnX == n && abs(sphere[11]) > minAngularSpeed) { rotation[2] = resetRotationTorque; //rotation needed to stop before next item api.setTorques(rotation); } } }
void getItem (int itemNo) { #if printDebug DEBUG(("getItem(%d) Info\n", itemNo)); #endif if (game.getCurrentPhase() == 1) { smartGo(red ? -0.45 : 0.45, statePos(myState)[1] < -0.05f ? 0.073f : 0.0505f); #if printDebug DEBUG(("\tMoving to Zone 2\n")); #endif return; } vec iloc; game.getItemLocation(itemNo, iloc); #if printDebug printVec("\tItemPos (m)", iloc); #endif overshoot(iloc); vec degs = {floatZero, floatZero, 0.62f}; setTargetAngVel(hitTarget(myState, iloc) ? degs : zeroVec); }
void remDust () { int i = obsDetected = game.getIdentifiedObstacles(obstacles); api.setAttitudeTarget(makeVec(floatZero, -1.0f, floatZero)); #if printDebug DEBUG(("remDust()\n")); DEBUG(("\tDetected\t%d\n", obsDetected)); #endif while (i -- && chg) { #if printDebug DEBUG(("\tObstacle ID\t%d\tRadius\t%.3f\n", obstacles[i].ID, obstacles[i].size)); printVec("\t\tObstacle Location", obstacles[i].loc); #endif if (obstacles[i].visible) { #if printDebug DEBUG(("\t\tShrinking\n")); #endif game.shrinkObstacle(obstacles[i].ID); return; } } }
bool makeObs (vec loc) { #if printDebug DEBUG(("makeObs()\n")); printVec("\tAt loc (m):", loc); #endif if (!cloudOn) { targetAtt[0] = -myState[6]; targetAtt[1] = -myState[7]; targetAtt[2] = -myState[8]; game.startObstacle(); cloudOn = true; } else if (hitTarget(myState, loc)) { game.stopObstacle(); cloudOn = false; return true; } #if printDebug printVec("\tTarget att", targetAtt); #endif api.setAttitudeTarget(targetAtt); api.setPositionTarget(loc); return false; }
void getItem (int itemNo) { #if printDebug DEBUG(("getItem(%d) Info\n", itemNo)); #endif vec iloc; game.getItemLocation(itemNo, iloc); #if printDebug printVec("\tItemPos (m)", iloc); #endif api.setPositionTarget(iloc); if (hitTarget(myState, iloc)) { vec temp = {0.75f, floatZero, floatZero}; setTargetAngVel(temp); } else { setTargetAngVel(zeroVec); } }
/* In order to collect an item, the following conditions must be true: 1. You must be < 0.05 meters away 2. You must have an angular velocity of < 2.3 degrees/second 3. You must have a linear velocity of < 0.01 meters per second 4. You must turn 90 degrees in any direction once 1,2,3 are true to collect an item. The function is able to accept ints 0, 1, and 2, which correspond to items in the game. 1,2,3 are accounted for in their own various functions, isClose, isStopSpin, isStopMove 4 is accounted for with the rotation below with the function setAttitudeTarget */ void gotoItem(int n) { api.getMyZRState(sphere); game.getItemLocation(n, itemLoc); api.setPositionTarget(itemLoc); if(isClose(itemLoc) && isStopSpin() && isStopMove()) { //the purpose of startTurnX is to make sure you only turn once per item, save fuel if(startTurnX == n) { /* changes attitude vector from current position to either 90 degrees clockwise 90 degrees counterclockwise */ if(startX > 0) { torques[0] = -sphere[7]; torques[1] = sphere[6]; } else if(startX < 0) { torques[0] = sphere[7]; torques[1] = -sphere[6]; } api.setAttitudeTarget(torques); startTurnX = startTurnX + 1; } } else { //stops the robot by applying torque if(startTurnX == n && abs(sphere[11]) > minAngularSpeed) { rotation[2] = resetRotationTorque; //rotation needed to stop before next item api.setTorques(rotation); } } }
void loop(){ api.getMyZRState(sphere); if(startObstacle) { game.startObstacle(); startObstacle = false; } if(isStart < 3) { /*At the start of the game, we can determine which robot we are by looking at the starting x value. Red starts at (-0.4, -0.6) while blue starts at (0.4, -0.6). This allows us to specify certain values. (usually just to mirror the robot), make sure it does the same thing but in a reflected direction. */ startX = sphere[0]; if(startX > 0) { resetRotationTorque = 0.0005; torques[2] = -0.005; } else if(startX < 0) { resetRotationTorque = -0.0005; torques[2] = 0.005; } api.setTorques(torques); isStart = isStart + 1; } switch(game.getCurrentPhase()) // 1 is area 1, 2 is area 2, 3 is area 3 { case 1: //makes item, and proceeds to next zone once below a certain threshold. if(game.getRemainingMaterial() < 0.03) { game.stopObstacle(); if(abs(sphere[11]) > minAngularSpeed) { torques[2] = resetRotationTorque; api.setTorques(torques); } velocity[1] = 0.055; //min distance for item api.setVelocityTarget(velocity); } break; case 2: //gets item 0, only required one, and gets out of there to nab time bonus if(!game.haveObject(0)) { gotoItem(0); } else { location[0] = -itemLoc[0] * 0.5; location[1] = 0.12 - (itemLoc[1] - 0.12) * 0.5; api.setPositionTarget(location); } break; case 3: //makes it to the end, shrinks any visible obstacles. velocity[1] = -0.07; api.setVelocityTarget(velocity); count = game.getVisibleObstacles(visibleObstacles); if(count != 0) { for(int i = 1; i <= count; i++) { game.shrinkObstacle(i); } } break; default: break; } }
void loop(){ api.getMyZRState(sphere); if(startObstacle) { game.startObstacle(); startObstacle = false; } if(isStart < 3) { startX = sphere[0]; if(startX > 0) { resetRotationTorque = 0.0005; torques[2] = -0.005; } else if(startX < 0) { resetRotationTorque = -0.0005; torques[2] = 0.005; } api.setTorques(torques); isStart = isStart + 1; } switch(game.getCurrentPhase()) // 1 is area 1, 2 is area 2, 3 is area 3 { case 1: if(game.getRemainingMaterial() < 0.03) { game.stopObstacle(); if(abs(sphere[11]) > minAngularSpeed) { torques[2] = resetRotationTorque; api.setTorques(torques); } velocity[1] = 0.055; //min distance for item api.setVelocityTarget(velocity); } break; case 2: if(!game.haveObject(0)) { gotoItem(0); } else { location[0] = -itemLoc[0] * 0.5; location[1] = 0.12 - (itemLoc[1] - 0.12) * 0.5; api.setPositionTarget(location); } break; case 3: velocity[1] = -0.07; api.setVelocityTarget(velocity); count = game.getVisibleObstacles(visibleObstacles); if(count != 0) { for(int i = 1; i <= count; i++) { game.shrinkObstacle(i); } } break; default: break; } }
void loop() { //Variable Initialization time ++; api.getMyZRState(myState); api.getOtherZRState(otherState); phase = game.getCurrentPhase(); fuel = game.getFuelRemaining(); myScore = game.getScore(); otherScore = game.getOtherScore(); dust = game.getRemainingMaterial(); chg = game.getCharge(); if (time < 2) { red = statePos(myState)[0] < floatZero; } //Debug Console DEBUG(("\nDevilTech Message Screen: Fall 2012\n")); #if printDebug DEBUG(("Debug Info\n")); DEBUG(("\tTime (s)\t%d\tPhase\t%d\tPlayer\t%s\n", time, phase, (red ? "Red" : "Blue"))); DEBUG(("\tFuel\t%.3f\tDust\t%.3f\tChg\t%d\n", fuel, dust, chg)); DEBUG(("\tScore\t%.2f\tOther Score\t%.2f\n", myScore, otherScore)); DEBUG(("\tOther Message\t%u\n", otherMessage)); printVec("\tMy Pos (m)", statePos(myState)); printVec("\tMy Vel (m/s)", stateVel(myState)); printVec("\tMy Att (unitvec)", stateAtt(myState)); printVec("\tMy AngVel (rad/s)", stateAngVel(myState)); printVec("\tOther Pos (m)", statePos(otherState)); printVec("\tOther Vel (m/s)", stateVel(otherState)); printVec("\tOther Att (unitvec)", stateAtt(otherState)); printVec("\tOther AngVel (rad/s)", stateAngVel(otherState)); #endif vec att = {floatZero, -1.0f, floatZero}; if (!obsCreated) { if (makeObs(red ? -0.17f : 0.17f, -0.63f)) obsCreated ++; } else if (obsCreated == 1) { if (makeObs(red ? -0.47f : 0.47f, -0.03f)) obsCreated ++; } else if (phase == 1) { vec temp = {norm((red ? -0.45f : 0.45f) - myState[0], 0.015f), 0.05f, floatZero}; setVelocity(temp); //api.setAttitudeTarget(att); } else { if (!game.haveObject(0)) getItem(0); else if (!game.haveObject(1) && !game.otherHasObject(1)) getItem(1); else if (!game.haveObject(2) && !game.otherHasObject(2) && !game.haveObject(1)) getItem(2); else { if (game.haveObject(1) || game.haveObject(2)) { api.setAttitudeTarget(att); } vec temp = {floatZero, floatZero, floatZero}; if (phase == 2) { vec temp2 = {(red ? 0.04f : -0.04f), 0.09f, floatZero}; attToTarget(myState, temp2, temp); vecScale(temp, 0.057f); temp[2] = maintainZ(); setVelocity(temp); } else { if (!alreadySet) { alreadySet = true; top = myState[2] > floatZero; } if (myState[1] > -0.4f) { remDust(); temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f); temp[1] = -0.051f; temp[2] = maintainZ(); } else if (myState[1] > -0.6f) { temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f); temp[1] = -0.022f; temp[2] = maintainZ(); } else { temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f); temp[1] = floatZero; temp[2] = (top ? -0.055f : 0.055f); DEBUG(("Top:\t%d\t%.3f\n", top, temp[2])); } setVelocity(temp); } } } }
void loop() { //Constant Variables zeroVec[0] = zeroVec[1] = zeroVec[2] = floatZero; //Variable Initialization time ++; api.getMyZRState(myState); api.getOtherZRState(otherState); phase = game.getCurrentPhase(); dust = game.getRemainingMaterial(); chg = game.getCharge(); if (!time) red = myState[0] < floatZero; if (time < 30 && otherState[1] > 0.1f) otherRush = true; //Trilateration api.getMyZRState(tripos[time]); game.pingForItems(tridis[time]); //Debug Console #if printDebug DEBUG(("\nUS#7 DevilTech BACON Hart District\nMessage Screen: Fall 2012\n")); DEBUG(("Debug Info\n")); DEBUG(("\tTime (s)\t%d\tPhase\t%d\tPlayer\t%s\n", time, phase, (red ? "Red" : "Blue"))); DEBUG(("\tFuel\t%.3f\tDust\t%.3f\tChg\t%d\n", game.getFuelRemaining(), dust, chg)); DEBUG(("\tMy Score\t%.3f\tOther Score\t%.3f\n", game.getScore(), game.getOtherScore())); DEBUG(("\tObstacles Created\t%d\n", obsCreated)); DEBUG(("\tOther Rush\t%d\n", otherRush)); printVec("\tMy Pos (m)", myState); printVec("\tMy Vel (m/s)", (myState + 3)); printVec("\tMy Att (unitvec)", (myState + 6)); printVec("\tMy AngVel (rad/s)", (myState + 9)); printVec("\tOther Pos (m)", otherState); printVec("\tOther Vel (m/s)", (otherState + 3)); printVec("\tOther Att (unitvec)", (otherState + 6)); printVec("\tOther AngVel (rad/s)", (otherState + 9)); #endif //Game Logic if (time < 4) { api.setVelocityTarget(makeVec(floatZero, floatZero, 0.0095f)); } if (!time) { game.startObstacle(); return; } if (time == 1) { game.stopObstacle(); } if (!game.haveObject(0)) { if (!game.haveObject(1) && !game.otherHasObject(1)) getOne; else getZero; } else { vec temp = {(red ? 0.15f : -0.15f), floatZero, myState[2]};/* if (!obsDetected && ((red && myState[0] > -0.05f) || (!red && myState[0] < 0.05f))) { int res = game.extendView(); if (printDebug) { DEBUG(("Extending View: %d\n", res)); } }*/ float tryy[7] = {(otherRush ? myState[2] : 0.38f), 0.11f, 0.22f, 0.34f, 0.45f, 0.55f, 0.68f}; obsDetected = game.getIdentifiedObstacles(obstacles); bool shr = false; for (int i = 0; i < 7; i ++) { if (printDebug) DEBUG(("\tTrying %.3f\n", tryy[i])); bool good = true; temp[2] = tryy[i]; for (int j = 0; j < obsDetected; j ++) { temp[1] = obstacles[j].loc[1]; if (printDebug) { DEBUG(("\t\tID %d, rad %.3f\n", obstacles[j].ID, obstacles[j].size)); printVec("\t\tLocation", obstacles[j].loc); DEBUG(("\t\tDis %.3f\n", disBetweenPts(obstacles[j].loc, temp))); } if (disBetweenPts(obstacles[j].loc, temp) < obstacles[j].size + 0.058f) { good = false; break; } if (!shr && obstacles[j].visible) { DEBUG(("\t\tShrinking\n")); shr = true; game.shrinkObstacle(obstacles[j].ID); } } if (good) { if (printDebug) DEBUG(("Decided %.3f\n", tryy[i])); temp[2] = tryy[i]; break; } } temp[1] = floatZero; if ((red && myState[0] < floatZero) || ((!red && myState[0] > floatZero))) { goStraight(temp, 1, -0.024f); } else if (myState[1] > -0.66f) { goStraight(temp, 1, (myState[1] > -0.48f && fabs(myState[2] - temp[2]) < 0.058f ? -0.0475f : -0.0235f)); } else { if (!alreadySet) { alreadySet = true; top = myState[2] > floatZero; } temp[1] = -0.71f; goStraight(temp, 2, top ? -0.055f : 0.055f); } } }