void ZRUser(float myState[12], float otherState[12], float time) { if (time < 150) { //TODO: move to center of panel initialization circle, instead of //assuming that position from the start float attitude[3] = {0, 1, 0}; ZRSetAttitudeTarget(attitude); //TODO: rotate around the circle to find the panel; in this case, //panel angle is 0 so we automatically see it after the attitude change if (isPanelFound() && time > 20) { float velocity[3] = {0, 0.01, 0}; ZRSetVelocityTarget(velocity); } if (iHavePanel() && time > 70 && time < 75) { float stop[3] = {0, 0, 0}; ZRSetVelocityTarget(stop); } if (iHavePanel() && time > 75 && time < 150) { float station[3] = {-.7, 0, 0}; ZRSetPositionTarget(station); } } if (iHavePanel() && time == 150) { float searchStation[3] = {0, 0.1, 0}; ZRSetTorques(searchStation); } if (isStationInSync() && time > 150) { float stop[3] = {0, 0, 0}; float velocity[3] = {0, 0, .01}; ZRSetTorques(stop); ZRSetVelocityTarget(velocity); } }
void HistDump(float * myState, float * otherState, int time) { float pos[3] = {0,0,0}; int k; for (k=0; k<3; k++) { pos[k] = myState[k]; } for (k=0; k<12; k++) { history[35*time+k] = myState[k]; history[35*time+12+k] = otherState[k]; } history[35*time+24] = iHavePanel(); history[35*time+25] = otherHasPanel(); history[35*time+26] = isPanelFound(); history[35*time+27] = isPanelInSync(); history[35*time+28] = isStationInSync(); history[35*time+29] = getCurrentScore(); history[35*time+30] = getOtherCurrentScore(); history[35*time+31] = getPercentChargeRemaining(); history[35*time+32] = getPercentFuelRemaining(); history[35*time+33] = otherRepelling(); history[35*time+34] = outsideBoundary(pos); }
void ZRUser(float* myState, float* otherState, float time) { float target[3]; float station[4]; float baseAngle; float angleDiff; float baseRadius; float to_opponent[3]; float sun[3] = {0,0,0}; float tolerance=.02; float a1, a2; float s1 = 0; float s2 = 0; //s1 = score 1 second ago. s2 = current score DEBUG(("time: %4.0f, state: %d\n", time, state)); switch (state) { case 0: //Code to initialize the sphere, then search for the panel... state = 1; break; case 1: //Code to move towards panel initialization circle... if (fabs(myState[0] - (getPanelSide() * 0.7)) < 0.1) state = 2; baseAngle = atan2f(myState[2], myState[1]); target_pos[0] = (getPanelSide() * 0.7); target_pos[1] = cosf(baseAngle) * 0.7; target_pos[2] = sinf(baseAngle) * 0.7; ZRSetPositionTarget(target_pos); Vfunc(9, (sun), (myState), (target_att), 0); ZRSetAttitudeTarget(target_att); //Code to find tangent lines... baseAngle = atan2f(-target_pos[2], -target_pos[1]); angleDiff = asinf(0.5 / sqrtf(mathSquare(target_pos[1]) + mathSquare(target_pos[2]))); tangentPoints[0] = baseAngle - angleDiff; tangentPoints[1] = baseAngle + angleDiff; tangentPoints[2] = tangentPoints[0]; break; case 2: if (getPercentChargeRemaining() >= 95) { state = 3; break; } else { // calc vector from current position back toward sun Vfunc(9, (sun), (myState), (target_att), 0); ZRSetPositionTarget(target_pos); ZRSetAttitudeTarget(target_att); } break; case 3: //Code to wait for the opponent to get into their panel's plane Vfunc(9, (myState), (otherState), (to_opponent), 0); if(fabs(otherState[0] - (getPanelSide() * -0.7) > .10)){ state = 5; break; } else { ZRSetAttitudeTarget(to_opponent); if(fabs(otherState[0] - (getPanelSide() * -0.7)) < .005){ state = 4; break; } } break; case 4: ZRSetPositionTarget(target_pos); Vfunc(9, (myState), (otherState), (to_opponent), 0); if (Vfunc(8, (to_opponent), (myState+6), NULL, 0) < 5 && getPercentChargeRemaining() > 0 && fabs(otherState[0]) > .68 && fabs(otherState[0]) < .81) { DEBUG(("time: %4.0f, (BLUE): ZAPPING ++++++++++++++++++++\n",time)); ZRRepel(); } else { if (getPercentChargeRemaining() < 1) { state = 5; break; } Vfunc(9, (myState), (otherState), (to_opponent), 0); DEBUG(("time: %4.0f, (BLUE): angle to opponent: %f\n",time,Vfunc(8, (to_opponent), (myState+3), NULL, 0))); ZRSetAttitudeTarget(to_opponent); } break; case 5: //Code to search for panel... //Check if panel was found. if (isPanelFound()) { getPanelState(panelState); panelState[4] = panelState[0]; baseAngle = atan2f(panelState[2], panelState[1]); baseRadius = sqrtf(mathSquare(panelState[1]) + mathSquare(panelState[2])) - 0.03; panelState[5] = cosf(baseAngle) * baseRadius; panelState[6] = sinf(baseAngle) * baseRadius; state = 6; break; } //Code to find tangent lines... baseAngle = atan2f(-myState[2], -myState[1]); angleDiff = asinf(0.5 / sqrtf(mathSquare(myState[1]) + mathSquare(myState[2]))); tangentPoints[0] = baseAngle - angleDiff; tangentPoints[1] = baseAngle + angleDiff; //Point in the direction of tangentPoints[2] target_att[0] = 0; target_att[1] = cosf(tangentPoints[2]); target_att[2] = sinf(tangentPoints[2]); ZRSetAttitudeTarget(target_att); if(fabs(otherState[0] - (getPanelSide() * -0.7) < .05 && getPercentChargeRemaining() > 0)){ state = 3; break; } tangentPoints[2] += scanTarget * 0.1; if ((scanTarget == 1) && (tangentPoints[2] >= tangentPoints[1])) scanTarget = -1; else if ((scanTarget == -1) && (tangentPoints[2] <= tangentPoints[0])) scanTarget = 1; target_pos[0] = getPanelSide() * 0.7; target_pos[1] = myState[1]; target_pos[2] = myState[2]; ZRSetPositionTarget(target_pos); break; case 6: //Code to move to panel... if (iHavePanel()) { state = 7; scanTarget = 0; break; } ZRSetPositionTarget(&panelState[4]); Vfunc(7, (panelState), NULL, (target_pos), 0); target_pos[0] = 0; Vfunc(3, (target_pos), NULL, (target_pos), 0); ZRSetAttitudeTarget(target_pos); break; case 7: //Code to beeline towards the station... if (s2 - s1 == 0 && s2 > 0){ state = 8; break; } else { s1 = s2; s2 = getOtherCurrentScore(); getStationState(station); Vfunc(7, (station), NULL, (target_att), 0); target_att[1] += cosf(station[3]) * 0.03; target_att[2] += sinf(station[3]) * 0.03; CoastToTarget(myState, target_att); target_att[0] = 0; target_att[1] = cosf(station[3]); target_att[2] = sinf(station[3]); ZRSetAttitudeTarget(target_att); } break; case 8: //Code to beeline towards the station... target[0] = (getPanelSide() * 0.7); target[1] = 0; target[2] = 0; CoastToTarget(myState, target); break; } }
//User01: blakeelias Team: Stuy-Naught Project: Kill-Retreat void ZRUser01(float *myState, float *otherState, float time) { #define position procvar #define attitude (procvar+3) #define panel_location (procvar+6) memcpy(vOtherPrev, vOther, sizeof(float)*3); //original value copied to previous value memcpy(vOther, otherState+3, sizeof(float)*3); // this is set to the current value // Wait for them to run out of fuel (constant velocity) if ((Vfunc(6, vOther, vOtherPrev, NULL, 0)) <= 0.01) counter++; else counter = 0; DEBUG(("time: %3.0f, SPH%d: state %i\n", time, getPanelSide() == 1 ? 1 : 2, state)); if (state == 1) { //Zapping // Get between the opponent and the sun memcpy(position, otherState, sizeof(float)*3); mathVecNormalize(position, 3); Vfunc(4, position, NULL, position, 0.1); CoastToTarget(myState, position, 0.04); // Face the opponent Vfunc(9, myState, otherState, attitude, 0); ZRSetAttitudeTarget(attitude); // Zap once we see them if (fabs (Vfunc(8, myState+6, attitude, NULL, 0)) < 6.0) { ZRRepel(); } //DEBUG(("Counter = %i \n", counter)); if(iHavePanel()) { if (counter >= 15 || getPercentFuelRemaining() < 10) state = 6; } else { if (counter >= 15 || time > 100) state = 2; else if (getPercentFuelRemaining() < 20) state = 3; } } if (state == 2) { //Moving to panel circle, they're dead if (isPanelFound()) state = 5; else { attitude[0] = 0; attitude[1] = 1*getPanelSide(); attitude[2] = 0; position[0] = .7*getPanelSide(); position[1] = 0; position[2] = 0; CoastToTarget(myState, position, 0.04); ZRSetAttitudeTarget(attitude); if (Vfunc(6, myState, position, NULL, 0) < 0.03) state = 4; } } if (state == 3) { // Retreating to panel, they are alive if (isPanelFound()) state = 5; else { position[0] = .7*getPanelSide(); position[1] = 0; position[2] = 0; CoastToTarget(myState, position, 0.04); } if (Vfunc(6, position, myState, NULL, 0) < 0.03) state = 4; } if (state == 4) { //Finding panel RotateTarget(myState, position); if (isPanelFound()) state = 5; if (iHavePanel()) state = 6; } if (state == 5) { //Get the panel getPanelState(position); attitude[0] = 0.7*getPanelSide(); attitude[1] = attitude[2] = 0; Vfunc(9, attitude, position, attitude, 0); ZRSetAttitudeTarget(attitude); CoastToTarget(myState, position, 0.04); if (iHavePanel()) state++; } if (state == 6) { //Stop if (counter < 15) state = 1; position[0] = position[1] = position[2] = 0; ZRSetVelocityTarget(position); } }