Finals Event Info

 

Finals Results

Due to hardware issues with the SPHERES and in order to make sure that every state's code was run on the ISS, the state's code was run against a standard player developed by the MIT UROP team specifically for the ISS Finals.

 

MS 2016 ISS Finals Code - Converted From Graphical to Text Editor

The text editor versions of the final "player" code competed on the satellites aboard the ISS are shown below in alphabetical order.

Each code has also been added as a "Standard Player" in the "SpySPHERES MS 2D" game mode.

Region (Alphabetical)

Code

  
float redsideenergy[3];
float redstart[3];
float bluesidescore[3];
float preredenergyspot[3];
float bluesideenergy[3];
float startredenergy[3];
float othersat[3];
float possition[3];
float starblueenergy[3];
int counter;
float redmirror[3];
float redsidescore[3];
float bluemirror[3];
float originscore[3];

//Begin page init
void init() {
  counter = 0;
  possition[0] = 0;
  possition[1] = 0;
  possition[2] = 0;
  redstart[0] = -0.25;
  redstart[1] = -0.4;
  redstart[2] = 0;
  othersat[0] = 0;
  othersat[1] = 0;
  othersat[2] = 0;
  bluemirror[0] = 0.6;
  bluemirror[1] = -0.7;
  bluemirror[2] = 0;
  redmirror[0] = -0.6;
  redmirror[1] = -0.7;
  redmirror[2] = 0;
  starblueenergy[0] = 0.25;
  starblueenergy[1] = -0.4;
  starblueenergy[2] = 0;
  startredenergy[0] = -0.25;
  startredenergy[1] = -0.4;
  startredenergy[2] = 0;
  bluesideenergy[0] = 0.25;
  bluesideenergy[1] = 0.4;
  bluesideenergy[2] = 0;
  redsideenergy[0] = -0.25;
  redsideenergy[1] = 0.4;
  redsideenergy[2] = 0;
  bluesidescore[0] = 0.4;
  bluesidescore[1] = 0.6;
  bluesidescore[2] = 0;
  originscore[0] = 0;
  originscore[1] = 0.6;
  originscore[2] = 0;
  redsidescore[0] = -0.4;
  redsidescore[1] = 0.6;
  redsidescore[2] = 0;
  preredenergyspot[0] = -0.25;
  preredenergyspot[1] = 0.3;
  preredenergyspot[2] = 0;
}
//End page init

//Begin page main
void loop() {
  game.getAttToOther(othersat);
  api.setAttitudeTarget(othersat);
  if (game.checkInLightOther()) {
    if (game.checkHaveItemOther(8) ? !game.takePic() : game.getEnergy() > 2.6 ? game.takePic() : !game.takePic()) {
      DEBUG(( "PICTURE TEST COMPLETE" ));
    }
  }
  if (counter >= 0) {
    api.setPositionTarget(bluemirror);
  }
  if (counter >= 17) {
    api.setPositionTarget(bluesidescore);
  }
  if (counter >= 50) {
    api.setPositionTarget(bluesideenergy);
  }
  if (counter >= 58) {
    game.useMirror();
  }
  if (counter >= 68) {
    api.setPositionTarget(starblueenergy);
  }
  if (counter >= 95) {
    if (game.checkHaveItemNoOne(4)) {
      game.getItemLoc(possition, 4);
      api.setPositionTarget(possition);
    }
  }
  if (counter >= 126) {
    if (game.checkHaveItemNoOne(6)) {
      game.getItemLoc(possition, 6);
      api.setPositionTarget(possition);
    }
  }
  if (counter >= 140) {
    api.setPositionTarget(redsideenergy);
  }
  counter = counter + 1;
}
//End page main



  
float energy[3];
float pos4[3];
float pos2[3];
float attitude2[3];
float attitude3[3];
float pos5[3];
float attitude4[3];
float attitude[3];
float shield[3];
float pos3[3];
float time;


//Begin page init
void init() {
  attitude[0] = -0.6;
  attitude[1] = -0.7;
  attitude[2] = 0;
  energy[0] = 0.25;
  energy[1] = 0.4;
  energy[2] = 0;
  shield[0] = 0.6;
  shield[1] = -0.7;
  shield[2] = 0;
  pos2[0] = 0.64;
  pos2[1] = 0;
  pos2[2] = 0;
  pos3[0] = 0;
  pos3[1] = 0.6;
  pos3[2] = 0;
  attitude2[0] = -0.25;
  attitude2[1] = 0.4;
  attitude2[2] = 0;
  pos4[0] = 0.4;
  pos4[1] = 0.6;
  pos4[2] = 0;
  attitude3[0] = -0.4;
  attitude3[1] = 0.6;
  attitude3[2] = 0;
  pos5[0] = 0.4;
  pos5[1] = -0.6;
  pos5[2] = 0;
  attitude4[0] = 0;
  attitude4[1] = 0;
  attitude4[2] = 0;
  time = 0;
}
//End page init

//Begin page main
void loop() {
  api.setAttitudeTarget(attitude);
  api.setPositionTarget(shield);
  if (game.isFacingOther()) {
    game.takePic();
  }
  if (time >= 20) {
    api.setPositionTarget(pos2);
    api.setAttitudeTarget(attitude2);
  }
  if (time >= 30) {
    api.setPositionTarget(pos3);
    api.setAttitudeTarget(attitude3);
  }
  if (time >= 60) {
    api.setPositionTarget(pos4);
    game.useMirror();
  }
  if (time >= 85) {
    api.setPositionTarget(pos5);
    api.setAttitudeTarget(attitude4);
  }
  time = time + 1;
}
//End page main



  
int w;
float TestArray[3];
float NewPos;
float turn[3];
float ChargeChargeLoc[3];
float NRG;
bool LORDU;
float point[3];
float BattleOfHogwarts[3];
int recharge;
bool LORDO;
int ChargeCharge;
bool Mirror;

//Begin page Camera
int Camera(bool LORDO, bool LORDU, float NRG) {
  game.getAttToOther(turn);
  api.setAttitudeTarget(turn);
  if (LORDU == false && LORDO == true && game.getNumMirrorsHeld() == 1 && api.getTime() >= 35) {
    game.useMirror();
    ChargeCharge = 0;
  } else if (LORDU == false && LORDO == true && game.getNumMirrorsHeld() == 0) {
    api.setPositionTarget(BattleOfHogwarts);
    ChargeCharge = 0;
  }
  if (NRG < 0.79) {
    ChargeCharge = 1;
  } else if (LORDO == false) {
    game.takePic();
    ChargeCharge = 0;
  }
  return ChargeCharge;
}
//End page Camera

//Begin page GetNextPoint
void GetNextPoint() {
  if (game.checkHaveItemNoOne(7) == true) {
    GetNextPointTransfer(0);
  } else if (game.checkHaveItemNoOne(4) == true) {
    GetNextPointTransfer(1);
  } else if (game.checkHaveItemNoOne(5) == true) {
    GetNextPointTransfer(2);
  } else if (game.checkHaveItemNoOne(2) == true) {
    GetNextPointTransfer(3);
  } else if (game.checkHaveItemNoOne(3) == true) {
    GetNextPointTransfer(4);
  } else if (game.checkHaveItemNoOne(6) == true) {
    GetNextPointTransfer(5);
  } else if (game.checkHaveItemNoOne(0) == true) {
    GetNextPointTransfer(6);
  } else {
    GetNextPointTransfer(7);
  }
}
//End page GetNextPoint

//Begin page GetNextPointTransfer
void GetNextPointTransfer(int w) {
  if (w == 0) {
    game.getItemLoc(point, 7);
  } else if (w == 1) {
    game.getItemLoc(point, 4);
  } else if (w == 2) {
    game.getItemLoc(point, 5);
  } else if (w == 3) {
    game.getItemLoc(point, 2);
  } else if (w == 4) {
    game.getItemLoc(point, 3);
  } else if (w == 5) {
    game.getItemLoc(point, 6);
  } else if (w == 6) {
    game.getItemLoc(point, 0);
  } else if (w == 7) {
    point[0] = BattleOfHogwarts[0];
    point[1] = BattleOfHogwarts[1];
    point[2] = BattleOfHogwarts[2];
  }
}
//End page GetNextPointTransfer

//Begin page Move
void Move() {
  api.setPositionTarget(point);
}
//End page Move

//Begin page OfficalCamera
int OfficalCamera(bool LORDO, bool LORDU, float NRG) {
  if (LORDU == false && LORDO == true && game.getNumMirrorsHeld() == 1) {
    game.useMirror();
    ChargeCharge = 0;
  }
  if (NRG < 0.5) {
    ChargeCharge = 1;
  } else if (LORDO == false) {
    game.takePic();
    ChargeCharge = 0;
  }
  return ChargeCharge;
}
//End page OfficalCamera

//Begin page Return
int Return() {
  if (Camera(game.checkInDarkOther(), game.checkInDark(), game.getEnergy()) == 1 && game.checkHaveItem(6) == true) {
    NewPos = 21;
  } else if (Camera(game.checkInDarkOther(), game.checkInDark(), game.getEnergy()) == 1 && game.checkHaveItem(6) == false) {
    NewPos = 6;
  } else if (game.checkHaveItemNoOne(7) == true) {
    NewPos = 7;
  } else if (game.checkHaveItemNoOne(4) == true) {
    NewPos = 4;
  } else if (game.checkHaveItemNoOne(5) == true) {
    NewPos = 5;
  } else if (game.checkHaveItemNoOne(2) == true) {
    NewPos = 2;
  } else if (game.checkHaveItemNoOne(3) == true) {
    NewPos = 3;
  } else if (game.checkHaveItemNoOne(6) == true) {
    NewPos = 6;
  } else if (game.checkHaveItemNoOne(0) == true) {
    NewPos = 0;
  } else {
    NewPos = 42;
  }
  return NewPos;
}
//End page Return

//Begin page init
void init() {
  TestArray[0] = 0;
  TestArray[1] = 0;
  TestArray[2] = 0;
  ChargeChargeLoc[0] = 0.5;
  ChargeChargeLoc[1] = -0.1;
  ChargeChargeLoc[2] = 0;
  point[0] = 0;
  point[1] = 0;
  point[2] = 0;
  BattleOfHogwarts[0] = 0.5;
  BattleOfHogwarts[1] = 0.2;
  BattleOfHogwarts[2] = 0;
  turn[0] = 0;
  turn[1] = 0;
  turn[2] = 0;
  NewPos = 0;
  LORDO = 0;
  LORDU = 0;
  NRG = 0;
  Mirror = 0;
  ChargeCharge = 0;
  recharge = 0;
  w = 0;
}
//End page init

//Begin page main
void loop() {
  recharge = Camera(game.checkInDarkOther(), game.checkInDark(), game.getEnergy());
  if (recharge == 1) {
    point[0] = ChargeChargeLoc[0];
    point[1] = ChargeChargeLoc[1];
    point[2] = ChargeChargeLoc[2];
  } else {
    GetNextPoint();
  }
  Move();
  DEBUG(( "Finished Loop" ));
}
//End page main



  
int pickup;
float position[3];
int switchtime;
unsigned int gametime;
float myZRState[12];
float positionC[3];
int step;
float positionA[3];
float target[3];
float attitude[3];

//Begin page init
void init() {
  positionA[0] = 1;
  positionA[1] = 0;
  positionA[2] = 0;
  positionC[0] = 0;
  positionC[1] = 1;
  positionC[2] = 0;
  target[0] = 0;
  target[1] = 0;
  target[2] = 0;
  myZRState[0] = 0;
  myZRState[1] = 0;
  myZRState[2] = 0;
  myZRState[3] = 0;
  myZRState[4] = 0;
  myZRState[5] = 0;
  myZRState[6] = 0;
  myZRState[7] = 0;
  myZRState[8] = 0;
  myZRState[9] = 0;
  myZRState[10] = 0;
  myZRState[11] = 0;
  attitude[0] = 0;
  attitude[1] = 0;
  attitude[2] = 0;
  position[0] = 0;
  position[1] = 0;
  position[2] = 0;
  switchtime = 0;
  gametime = 0;
  pickup = 0;
  step = 0;
}
//End page init

//Begin page main
void loop() {
  game.getAttToOther(attitude);
  api.setAttitudeTarget(attitude);
  if (game.isCameraOn() && game.isFacingOther()) {
    game.takePic();
  }
  switchtime = game.getLightSwitchTime();
  pickup = game.getItemType(5);
  DEBUG(( "switchtime in %d",switchtime ));
  if (game.getItemType(5) < game.getFuelRemaining()) {
    position[0] = 0;
    position[0] = 0;
    position[0] = 0;
    api.setPositionTarget(position);
  }
  if (game.checkHaveItem(5)) {
    DEBUG(( "Item 0 picked up" ));
  }
  gametime = api.getTime();
  DEBUG(( "gametime =%u", gametime ));
}
//End page main



  
//Declare any variables shared between functions here
float alarmE03[3];
float datapoint5[3];
float picpoint[3];
float othermirror[3];
float other_State[12];
float inbetween[3];
float energypack0[3];
float energypack3[3];
float mymirror[3];
float alarmE02[3];
float my_State[12];
float Will_iD[3];
float alarmE06[3];
float mayaspoint[3];
float alarmE05[3];
float Should_iD[3];
float alarmE01[3];
float datapoint4[3];
float energypack1[3];
float alarmE08[3];
float datapoint6[3];
float alarmE07[3];
float wherIwantogo[3];
float opp_att[3];
float energypack2[3];
float alarmE04[3];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void CollectStuffs() {
  if (game.checkHaveItemNoOne(2) == true) {
    api.setPositionTarget(energypack2);
  } else if (game.checkHaveItemOther(2) == true && game.checkHaveItemNoOne(3) == true) {
    api.setPositionTarget(energypack3);
  } else if ((game.checkHaveItem(2) || game.checkHaveItem(3)) == true && game.checkHaveItemNoOne(4) == true) {
    api.setPositionTarget(datapoint4);
  }
  if (game.checkHaveItemNoOne(5) == true) {
    api.setPositionTarget(datapoint5);
  } else if (game.checkHaveItemOther(5) == true && game.checkHaveItemNoOne(2) == true) {
    api.setPositionTarget(energypack2);
  }
}

void ShadowDeath() {
  if (api.getTime() >= 116 && game.checkHaveItemNoOne(4) && Should_iD[0] <= Will_iD[0]) {
    api.setPositionTarget(datapoint4);
    TakePic();
  } else if (api.getTime() >= 116 && game.checkHaveItemNoOne(3)) {
    api.setPositionTarget(energypack3);
    TakePic();
  } else if (api.getTime() >= 116 && (game.checkHaveItemOther(4) || game.checkHaveItem(4)) && (game.checkHaveItem(3) || game.checkHaveItemOther(3))) {
    api.setPositionTarget(datapoint6);
    TakePic();
  }
  api.getMyZRState(my_State);
  api.getOtherZRState(other_State);
  for (int index1 = 0; index1 <= 2; index1++) {
    Should_iD[index1] = (other_State[index1] + datapoint4[index1]) / 2;
  }
  for (int index1 = 0; index1 <= 2; index1++) {
    Will_iD[index1] = (my_State[index1] + datapoint4[index1]) / 2;
  }
}

void ShadowLife() {
  if (api.getTime() >= 48.3) {
    api.setPositionTarget(energypack0);
    api.getOtherZRState(other_State);
    if (other_State[0] == (alarmE01[0] || alarmE02[0] || alarmE03[0] || alarmE04[0] || alarmE05[0] || alarmE06[0] || alarmE07[0] || alarmE08[0])) {
      api.setPositionTarget(othermirror);
    } else {
      TakePic();
    }
  } else {
    TakePic();
  }
}

void ShieldGrab() {
  if (game.checkHaveItemNoOne(7) && api.getTime() >= 80 && game.getEnergy() >= 1.203601) {
    api.setPositionTarget(mymirror);
  } else if ((game.checkHaveItemOther(7) || game.checkHaveItem(0) == true) && game.getEnergy() < 1.203601) {
    api.setPositionTarget(energypack2);
    TakePic();
  }
}

void ShieldsUp() {
  if (game.checkInLight() == true && game.getNumMirrorsHeld() >= 1 && api.getTime() >= 116) {
    game.useMirror();
  }
}

void TakePic() {
  game.getAttToOther(opp_att);
  api.setAttitudeTarget(opp_att);
  if (game.checkInLightOther() && game.isFacingOther()) {
    game.takePic();
  }
}

void init(){
	//This function is called once when your code is first loaded.
  opp_att[0] = 0;
  opp_att[1] = 0;
  opp_att[2] = 0;
  other_State[0] = 0;
  other_State[1] = 0;
  other_State[2] = 0;
  other_State[3] = 0;
  other_State[4] = 0;
  other_State[5] = 0;
  other_State[6] = 0;
  other_State[7] = 0;
  other_State[8] = 0;
  other_State[9] = 0;
  other_State[10] = 0;
  other_State[11] = 0;
  my_State[0] = 0;
  my_State[1] = 0;
  my_State[2] = 0;
  my_State[3] = 0;
  my_State[4] = 0;
  my_State[5] = 0;
  my_State[6] = 0;
  my_State[7] = 0;
  my_State[8] = 0;
  my_State[9] = 0;
  my_State[10] = 0;
  my_State[11] = 0;
  wherIwantogo[0] = 0;
  wherIwantogo[1] = 0;
  wherIwantogo[2] = 0;
  picpoint[0] = 0;
  picpoint[1] = 0;
  picpoint[2] = 0;
  datapoint6[0] = 0;
  datapoint6[1] = 0;
  datapoint6[2] = 0;
  datapoint4[0] = 0;
  datapoint4[1] = 0;
  datapoint4[2] = 0;
  datapoint5[0] = 0;
  datapoint5[1] = 0;
  datapoint5[2] = 0;
  energypack0[0] = 0;
  energypack0[1] = 0;
  energypack0[2] = 0;
  energypack1[0] = 0;
  energypack1[1] = 0;
  energypack1[2] = 0;
  energypack2[0] = 0;
  energypack2[1] = 0;
  energypack2[2] = 0;
  energypack3[0] = 0;
  energypack3[1] = 0;
  energypack3[2] = 0;
  mymirror[0] = 0;
  mymirror[1] = 0;
  mymirror[2] = 0;
  Will_iD[0] = 0;
  Will_iD[1] = 0;
  Will_iD[2] = 0;
  Should_iD[0] = 0;
  Should_iD[1] = 0;
  Should_iD[2] = 0;
  mayaspoint[0] = 0;
  mayaspoint[1] = 0;
  mayaspoint[2] = 0;
  inbetween[0] = 0;
  inbetween[1] = -0.4;
  inbetween[2] = 0;
  othermirror[0] = 0;
  othermirror[1] = 0;
  othermirror[2] = 0;
  alarmE01[0] = 0.34;
  alarmE01[1] = -0.4;
  alarmE01[2] = 0;
  alarmE02[0] = 0.32;
  alarmE02[1] = -0.46;
  alarmE02[2] = 0;
  alarmE03[0] = 0.24;
  alarmE03[1] = -0.3;
  alarmE03[2] = 0;
  alarmE04[0] = 0.18;
  alarmE04[1] = -0.46;
  alarmE04[2] = 0;
  alarmE05[0] = 0.16;
  alarmE05[1] = -0.4;
  alarmE05[2] = 0;
  alarmE06[0] = 0.18;
  alarmE06[1] = -0.54;
  alarmE06[2] = 0;
  alarmE07[0] = 0.24;
  alarmE07[1] = -0.5;
  alarmE07[2] = 0;
  alarmE08[0] = 0.32;
  alarmE08[1] = -0.54;
  alarmE08[2] = 0;
  game.getItemLoc(datapoint6, 6);
  game.getItemLoc(datapoint4, 4);
  game.getItemLoc(datapoint5, 5);
  game.getItemLoc(energypack0, 0);
  game.getItemLoc(energypack1, 1);
  game.getItemLoc(energypack2, 2);
  game.getItemLoc(energypack3, 3);
  game.getItemLoc(mymirror, 7);
  game.getItemLoc(othermirror, 8);
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  if (api.getTime() >= 45) {
    ShadowLife();
    ShieldGrab();
  } else if (api.getTime() <= 49) {
    CollectStuffs();
  } else {
    TakePic();
  }
  if (api.getTime() >= 116) {
    ShieldsUp();
    ShadowDeath();
  } else {
    TakePic();
  }
}

  
//Declare any variables shared between functions here
float distanceScore2;
int counter;
float myEnergy;
float attother[3];
float score1[3];
float score2[3];
float score3[3];
float mirror1[3];
float energy3[3];
float energy2[3];
float energy0[3];
float position1[3];
float myZRstate[12];
float otherZRstate[12];
bool item7;
bool item5;
bool item2;
bool item4;
bool item6;
bool item3;
bool oppScore2;
void init(){
	//This function is called once when your code is first loaded.
  for (int index=0; index<=11; index++)
    {
        otherZRstate[index]=0;
        myZRstate[index]=0;
    }
    counter=0;
	attother[0]=0;
	attother[1]=0;
	attother[2]=0;
	score1[0]=0.4;
	score1[1]=0.6;
	score1[2]=0;
	score2[0]=0;
	score2[1]=0.6;
	score2[2]=0;
	score3[0]=-0.4;
	score3[1]=0.6;
	score3[2]=0;
	mirror1[0]=0;
	mirror1[1]=0;
	mirror1[2]=0;
	energy2[0]=0;
	energy2[1]=0;
	energy2[2]=0;
	energy3[0]=0;
	energy3[1]=0;
	energy3[2]=0;
	energy0[0]=0;
	energy0[1]=0;
	energy0[2]=0;
	position1[0]=0.475;
	position1[1]=0;
	position1[2]=0;
	item7=TRUE;
	item5=TRUE;
	item2=TRUE;
	item4=TRUE;
	item6=TRUE;
	item3=TRUE;
	oppScore2=0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
	myEnergy=game.getEnergy();
    
    distanceScore2 = sqrtf(powf(score2[0] - otherZRstate[0], 2) + powf(score2[1] - otherZRstate[1], 2));
    DEBUG (("D= %f", distanceScore2));
    
    itemAvailable();
    game.getAttToOther(attother);
    api.setAttitudeTarget(attother);
    api.getOtherZRState(otherZRstate);
    
    if (game.checkInLightOther() && myEnergy>=2.75){
        game.takePic();}
    else if(!game.checkInLight()&& myEnergy>=3.75){
        !game.takePic();}
    if (distanceScore2<=0.665 && counter>=5 && counter<=10){
        oppScore2=1;}
    if (oppScore2==1){
        PlanB();}
    else  
    {if (!game.checkHaveItem(4) && counter<50 && oppScore2==0){
        api.setPositionTarget(score2);}
    if ((game.checkHaveItem(4) && !game.checkHaveItemOther(2)) || (item4==FALSE && myEnergy<=1.5)){
        game.getItemLoc(energy2,2);
        api.setPositionTarget(energy2);}
    if (!game.checkHaveItem(7) && (counter>=49) && !game.checkHaveItemOther(0)&& game.checkHaveItem(2)){
        game.getItemLoc(energy0, 0);
        api.setPositionTarget(energy0);}
    if (game.checkHaveItem(0) && oppScore2==0){
        game.getItemLoc(mirror1,7);
        api.setPositionTarget(mirror1);}
    if (counter>=112 && oppScore2==0){
        api.setPositionTarget(score1);}
    if (counter>=125 && oppScore2==0){
        game.useMirror();}
    }
        
    counter = counter + 1;
}

void itemAvailable(){
    if (game.checkHaveItem(7) || game.checkHaveItemOther(7)){
        item7=FALSE;
    }
     if (game.checkHaveItem(5) || game.checkHaveItemOther(5)){
        item5=FALSE;
     }
     if (game.checkHaveItem(2) || game.checkHaveItemOther(2)){
        item2=FALSE;
     }
     if (game.checkHaveItem(4) || game.checkHaveItemOther(4)){
        item4=FALSE;
     }
     if (game.checkHaveItem(6) || game.checkHaveItemOther(6)){
        item6=FALSE;
     }
     if (game.checkHaveItem(3) || game.checkHaveItemOther(3)){
        item3=FALSE;
     }
}

void PlanB(){
    api.setPositionTarget(score1);
    if (game.checkHaveItem(5)){
        game.getItemLoc(energy2, 2);
        api.setPositionTarget(energy2);}
    if(!game.checkHaveItem(7)&& counter>=49 && !game.checkHaveItemOther(0) && game.checkHaveItem(2)){
        game.getItemLoc(energy0,0);
        api.setPositionTarget(energy0);}
    if (game.checkHaveItem(0)){
        game.getItemLoc(mirror1,7);
        api.setPositionTarget(mirror1);}
    if (counter>=112 && game.checkHaveItem(7)){
        api.setPositionTarget(score2);}
    if (counter>=125){
        game.useMirror();}
}

  
//Declare any variables shared between functions here
float counter;
float op[3];
float mz[12];
float energy;
float crossover[3];
float to[3];
float oz[12];
float waiting[3];
float solar[3];
float escape;

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void init(){
	//This function is called once when your code is first loaded.
  op[0] = 0;
  op[1] = 0;
  op[2] = 0;
  crossover[0] = 0;
  crossover[1] = 5.5;
  crossover[2] = 0;
  oz[0] = 0;
  oz[1] = 0;
  oz[2] = 0;
  oz[3] = 0;
  oz[4] = 0;
  oz[5] = 0;
  oz[6] = 0;
  oz[7] = 0;
  oz[8] = 0;
  oz[9] = 0;
  oz[10] = 0;
  oz[11] = 0;
  solar[0] = 0;
  solar[1] = 0.2;
  solar[2] = 0;
  mz[0] = 0;
  mz[1] = 0;
  mz[2] = 0;
  mz[3] = 0;
  mz[4] = 0;
  mz[5] = 0;
  mz[6] = 0;
  mz[7] = 0;
  mz[8] = 0;
  mz[9] = 0;
  mz[10] = 0;
  mz[11] = 0;
  to[0] = 0;
  to[1] = 0;
  to[2] = 0;
  waiting[0] = 0;
  waiting[1] = 0.25;
  waiting[2] = 0;
  counter = 0;
  energy = 0;
  escape = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  game.getAttToOther(op);
  api.setAttitudeTarget(op);
  api.getMyZRState(mz);
  api.getOtherZRState(oz);
  if ((game.checkInLight() && game.checkInLightOther()) == true || (game.checkInLightOther() && game.checkInDark()) == true) {
    game.takePic();
  }
  if (counter < 45) {
    if (game.checkHaveItemNoOne(2)) {
      game.getItemLoc(to, 2);
      api.setPositionTarget(to);
    } else if (game.checkHaveItemNoOne(5)) {
      game.getItemLoc(to, 5);
      api.setPositionTarget(to);
    }
  } else if (counter < 93) {
    if (game.checkHaveItemNoOne(0)) {
      game.getItemLoc(to, 0);
      api.setPositionTarget(to);
    } else if (game.checkHaveItemNoOne(7)) {
      game.getItemLoc(to, 7);
      api.setPositionTarget(to);
    }
  } else if (counter < 180) {
    if (game.checkHaveItemNoOne(6)) {
      game.getItemLoc(to, 6);
      api.setPositionTarget(to);
    } else if (game.checkHaveItemNoOne(4)) {
      game.getItemLoc(to, 4);
      api.setPositionTarget(to);
    } else {
      api.setPositionTarget(waiting);
    }
  }
  if ((game.checkInLight() && game.checkInDarkOther()) == true || (oz[3] && oz[4] && oz[5]) == (mz[0] && mz[1] && mz[2]) && (game.checkInLight() && game.checkInLightOther() || game.checkInLight() && game.checkInDarkOther()) || counter >= 106) {
    game.useMirror();
  }
  energy = game.getEnergy();
  counter += 1;
}

  
//Declare any variables shared between functions here
float nrg1[3];
float nrg2[3];
float enemyatt[3];
float at1[3];
float my_state[12];
float attitude[3];
float point3[3];
int counter;
float nrg4[3];
float other_state[12];
float point2[3];
float point1[3];
float mirror2[3];
float nrg3[3];
float mirror1[3];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void AI() {
  api.getOtherZRState(other_state);
  api.getMyZRState(my_state);
  game.getAttToOther(attitude);
  api.setAttitudeTarget(attitude);
  game.getItemLoc(mirror1, 7);
  if (game.checkHaveItemNoOne(7)) {
    api.setPositionTarget(mirror1);
  }
  if (game.checkHaveItem(7)) {
    if (game.getScore() - game.getOtherScore() < 6.9) {
      if (game.getScore() - game.getOtherScore() > 2) {
        game.useMirror();
        points();
      } else {
        points();
      }
    } else {
      points();
    }
  }
  if (game.isFacingOther() && game.checkInLightOther() && game.getMirrorTimeRemaining() == 0 && powf(powf(my_state[0] - other_state[0], 2) + powf(my_state[1] - other_state[1], 2), 0.5) >= 0.5) {
    if (game.isCameraOn()) {
      if (game.checkInLightOther()) {
        if (game.isFacingOther()) {
          game.takePic();
        }
      }
    }
  }
}
//End page AI

//Begin page Darkness
void Darkness() {
  api.getMyZRState(my_state);
  if (game.checkHaveItem(7)) {
    if (api.getTime() >= 100 && api.getTime() < 150) {
      setPos(my_state[0], -0.03, 0);
    }
    if (api.getTime() < 181 && api.getTime() >= 150) {
      setPos(my_state[0], 0.03, 0);
    }
  }
}
//End page Darkness

//Begin page energy
void energy() {
}

void init(){
	//This function is called once when your code is first loaded.
  counter = 0;
  my_state[0] = 0;
  my_state[1] = 0;
  my_state[2] = 0;
  my_state[3] = 0;
  my_state[4] = 0;
  my_state[5] = 0;
  my_state[6] = 0;
  my_state[7] = 0;
  my_state[8] = 0;
  my_state[9] = 0;
  my_state[10] = 0;
  my_state[11] = 0;
  other_state[0] = 0;
  other_state[1] = 0;
  other_state[2] = 0;
  other_state[3] = 0;
  other_state[4] = 0;
  other_state[5] = 0;
  other_state[6] = 0;
  other_state[7] = 0;
  other_state[8] = 0;
  other_state[9] = 0;
  other_state[10] = 0;
  other_state[11] = 0;
  attitude[0] = 0;
  attitude[1] = 0;
  attitude[2] = 0;
  at1[0] = 0;
  at1[1] = 0;
  at1[2] = 0;
  enemyatt[0] = 0;
  enemyatt[1] = 0;
  enemyatt[2] = 0;
  nrg1[0] = 0;
  nrg1[1] = 0;
  nrg1[2] = 0;
  nrg2[0] = 0;
  nrg2[1] = 0;
  nrg2[2] = 0;
  nrg3[0] = 0;
  nrg3[1] = 0;
  nrg3[2] = 0;
  nrg4[0] = 0;
  nrg4[1] = 0;
  nrg4[2] = 0;
  point1[0] = 0;
  point1[1] = 0;
  point1[2] = 0;
  point2[0] = 0;
  point2[1] = 0;
  point2[2] = 0;
  point3[0] = 0;
  point3[1] = 0;
  point3[2] = 0;
  mirror1[0] = 0;
  mirror1[1] = 0;
  mirror1[2] = 0;
  mirror2[0] = 0;
  mirror2[1] = 0;
  mirror2[2] = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  AI();
  Darkness();
}

void points() {
  game.getItemLoc(point1, 5);
  game.getItemLoc(point2, 4);
  game.getItemLoc(point3, 6);
  if (game.checkHaveItemNoOne(6)) {
    api.setPositionTarget(point3);
  } else if (game.checkHaveItemNoOne(4)) {
    api.setPositionTarget(point2);
  } else if (game.checkHaveItemNoOne(5)) {
    api.setPositionTarget(point1);
  }
  if (api.getTime() > 150 && api.getTime() < 60) {
    if (game.getEnergy() <= 2) {
      if (game.checkHaveItemNoOne(3)) {
        game.getItemLoc(nrg3, 3);
        api.setPositionTarget(nrg3);
      } else if (game.checkHaveItemNoOne(2)) {
        game.getItemLoc(nrg2, 2);
        api.setPositionTarget(nrg2);
      }
    }
  } else {
    if (game.getEnergy() <= 2 && game.checkHaveItemNoOne(0)) {
      game.getItemLoc(nrg1, 0);
      api.setPositionTarget(nrg1);
    }
  }
}

          
//Declare any variables shared between functions here
bool energyLeft;
unsigned short phaseOfGame;
float Y;
bool skip;
float itemPosition[3];
bool mirrorsLeft;
float currentTime;
float faceOther[3];
float distance;
bool gameOver;
float X;
bool itemsLeft;
float oZRState[12];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void init(){
	//This function is called once when your code is first loaded.
  Y = 0;
  X = 0;
  distance = 0;
  faceOther[0] = 0;
  faceOther[1] = 0;
  faceOther[2] = 0;
  itemPosition[0] = 0;
  itemPosition[1] = 0;
  itemPosition[2] = 0;
  oZRState[0] = 0;
  oZRState[1] = 0;
  oZRState[2] = 0;
  oZRState[3] = 0;
  oZRState[4] = 0;
  oZRState[5] = 0;
  oZRState[6] = 0;
  oZRState[7] = 0;
  oZRState[8] = 0;
  oZRState[9] = 0;
  oZRState[10] = 0;
  oZRState[11] = 0;
  energyLeft = 1;
  mirrorsLeft = 1;
  itemsLeft = 1;
  phaseOfGame = 0;
  currentTime = 0;
  skip = 0;
  gameOver = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  currentTime = api.getTime();
  if (currentTime <= 60) {
    phaseOfGame = 0;
  } else if (currentTime > 60 && currentTime <= 150) {
    phaseOfGame = 1;
  } else if (currentTime > 150) {
    phaseOfGame = 2;
  }
  if (phaseOfGame == 0) {
    if (game.getEnergy() < 0.5) {
      pickEnergy();
    }
    if (game.checkHaveItemNoOne(5) && currentTime <= 31) {
      game.getItemLoc(itemPosition, 5);
      api.setPositionTarget(itemPosition);
    } else if (game.checkHaveItemNoOne(2) && (!game.checkHaveItemNoOne(5) || currentTime <= 50)) {
      game.getItemLoc(itemPosition, 2);
      api.setPositionTarget(itemPosition);
    } else if (!game.checkHaveItemNoOne(2) || currentTime > 50) {
      pickEnergy();
    }
  }
  game.getAttToOther(faceOther);
  api.setAttitudeTarget(faceOther);
  if (game.getEnergy() > 2 && game.checkInLightOther() && game.isFacingOther() && game.isCameraOn()) {
    if (phaseOfGame != 2) {
      if (game.getPicPoints() > 0.01) {
        game.takePic();
      }
    } else {
      game.takePic();
    }
  }
  if (phaseOfGame == 1) {
    if (game.checkInDark() && currentTime > 140) {
      setPos(0, -0.05, 0);
      game.useMirror();
      if (!itemsLeft) {
        gameOver = 1;
      }
    }
    if (energyLeft) {
      pickEnergy();
    } else if (mirrorsLeft && (game.checkHaveItem(0) || game.checkHaveItem(1))) {
      pickMirrors();
    } else {
      setPos(0, -0.05, 0);
    }
    if (game.checkInDark() && currentTime > 148) {
      game.useMirror();
    }
    if (game.checkInLight() && game.getOtherEnergy() > 0.9) {
      game.useMirror();
    }
    if (!mirrorsLeft && !energyLeft && game.getNumMirrorsHeld() >= 1 && game.getEnergy() >= 1) {
      pickItems();
    } else {
      if (!energyLeft && !mirrorsLeft) {
        setPos(0, -0.05, 0);
        if (game.checkInLightOther()) {
          pickItems();
        }
      }
    }
    if (game.getNumMirrorsHeld() == 0 && (game.checkHaveItem(7) || game.checkHaveItem(8))) {
      pickItems();
    }
  }
  if (phaseOfGame == 2) {
    if (game.getOtherEnergy() > 0.9 && game.checkInLight()) {
      game.useMirror();
    }
    if (itemsLeft) {
      pickItems();
    } else if (game.checkHaveItemNoOne(3)) {
      game.getItemLoc(itemPosition, 3);
      api.setPositionTarget(itemPosition);
    }
    if (gameOver || game.getEnergy() < 0.5) {
      setPos(-0.05, 0.05, 0);
    }
  }
}

void pickEnergy() {
  if (energyLeft) {
    if (!skip && game.checkHaveItemNoOne(0)) {
      game.getItemLoc(itemPosition, 0);
      api.getOtherZRState(oZRState);
      X = itemPosition[0] - oZRState[0];
      Y = itemPosition[1] - oZRState[1];
      distance = sqrtf(X * X + Y * Y);
      if (distance < 0.38) {
        skip = 1;
      } else {
        api.setPositionTarget(itemPosition);
      }
    }
    if (skip || !game.checkHaveItemNoOne(0) && game.checkHaveItemNoOne(1)) {
      game.getItemLoc(itemPosition, 1);
      api.setPositionTarget(itemPosition);
    }
    if (!game.checkHaveItemNoOne(0) && !game.checkHaveItemNoOne(1)) {
      energyLeft = 0;
      skip = 0;
    }
  }
}
//End page pickEnergy

//Begin page pickItems
void pickItems() {
  if (itemsLeft == 1) {
    if (game.checkHaveItemNoOne(4)) {
      game.getItemLoc(itemPosition, 4);
    } else if (game.checkHaveItemNoOne(5)) {
      game.getItemLoc(itemPosition, 5);
    } else if (game.checkHaveItemNoOne(6)) {
      game.getItemLoc(itemPosition, 6);
    } else {
      itemsLeft = 0;
    }
    api.setPositionTarget(itemPosition);
  }
}
//End page pickItems

//Begin page pickMirrors
void pickMirrors() {
  if (game.getEnergy() > 0.5 && mirrorsLeft && game.checkInDark()) {
    if (game.checkHaveItemNoOne(8)) {
      if (game.checkHaveItem(1)) {
        game.getItemLoc(itemPosition, 8);
        api.setPositionTarget(itemPosition);
      } else if (game.checkHaveItem(0)) {
        if (!game.checkHaveItemNoOne(7)) {
          game.getItemLoc(itemPosition, 8);
          api.setPositionTarget(itemPosition);
        }
      }
    }
    if (game.checkHaveItemNoOne(7)) {
      if (game.checkHaveItem(0)) {
        game.getItemLoc(itemPosition, 7);
        api.setPositionTarget(itemPosition);
      } else if (game.checkHaveItem(1)) {
        if (!game.checkHaveItemNoOne(8)) {
          game.getItemLoc(itemPosition, 7);
          api.setPositionTarget(itemPosition);
        }
      }
    }
    if (!game.checkHaveItemNoOne(7) && !game.checkHaveItemNoOne(8)) {
      mirrorsLeft = 0;
    }
  }
}

  
float enemy[3];
float score2[3];
float current[3];
float score1[3];
float energy3[3];
float energy1[3];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

//Begin page init
void init() {
  enemy[0] = 0;
  enemy[1] = 0;
  enemy[2] = 0;
  energy1[0] = 0.25;
  energy1[1] = -0.4;
  energy1[2] = 0;
  energy3[0] = 0.25;
  energy3[1] = 0.4;
  energy3[2] = 0;
  score1[0] = 0;
  score1[1] = 0.6;
  score1[2] = 0;
  score2[0] = 0.4;
  score2[1] = 0.6;
  score2[2] = 0;
  current[0] = 0;
  current[1] = 0;
  current[2] = 0;
}
//End page init

//Begin page main
void loop() {
  game.getAttToOther(enemy);
  api.setAttitudeTarget(enemy);
  if (game.getEnergy() >= 2 && game.checkInLightOther()) {
    game.takePic();
  }
  if (api.getTime() >= 0 && api.getTime() <= 28) {
    api.setPositionTarget(energy3);
  }
  if (api.getTime() >= 29 && api.getTime() <= 48) {
    api.setPositionTarget(score2);
  }
  if (api.getTime() >= 49 && api.getTime() <= 141) {
    api.setPositionTarget(energy1);
  }
  if (api.getTime() >= 142 && api.getTime() <= 180) {
    api.setPositionTarget(score1);
  }
}
//End page main

  
//Declare any variables shared between functions here
int Counter;
float Other[3];
float Energy3[3];
float PositionB[3];
float Score[3];
float PositionA[3];
float Energy2[3];
float Energy[3];
float Energy1[3];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void init(){
	//This function is called once when your code is first loaded.
  Energy1[0] = -0.25;
  Energy1[1] = 0.37;
  Energy1[2] = 0;
  Other[0] = 0;
  Other[1] = 0;
  Other[2] = 0;
  PositionA[0] = 0.4;
  PositionA[1] = 0.6;
  PositionA[2] = 0;
  PositionB[0] = -0.4;
  PositionB[1] = -0.6;
  PositionB[2] = 0;
  Energy2[0] = 0.24;
  Energy2[1] = 0.38;
  Energy2[2] = 0;
  Energy[0] = 0.25;
  Energy[1] = -0.38;
  Energy[2] = 0;
  Score[0] = 0.4;
  Score[1] = 0.6;
  Score[2] = 0;
  Energy3[0] = 0.25;
  Energy3[1] = -0.4;
  Energy3[2] = 0;
  Counter = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  if (Counter < 60 && game.checkHaveItem(5) == false) {
    api.setPositionTarget(PositionA);
  } else if (Counter < 48 && game.checkHaveItem(5) == true) {
    api.setPositionTarget(Energy2);
  } else if (Counter < 100 && Counter > 48) {
    game.getItemLoc(Energy, 1);
    api.setPositionTarget(Energy);
  } else if (Counter > 138 && game.checkHaveItemOther(3) == false) {
    api.setPositionTarget(Energy1);
  } else {
    if (Counter > 138 && game.checkHaveItemOther(3) == true) {
      api.setPositionTarget(Energy1);
    }
  }
  if (game.checkInLightOther() == false && Counter < 60 && game.checkHaveItem(5) == true) {
    if (game.checkHaveItemOther(2) == false && game.checkHaveItem(2) == false) {
      api.setPositionTarget(Energy2);
    }
  }
  game.getAttToOther(Other);
  api.setAttitudeTarget(Other);
  if (game.getEnergy() >= 2) {
    if (game.isFacingOther() == true && game.checkInLightOther() == true) {
      for (int count = 0; count < 1; count++) {
        game.takePic();
        while (game.getPicPoints()) {
        }
      }
    }
  }
  Counter = Counter + 1;
}

  
//Declare any variables shared between functions here
float Mirror8[3];
float PostMirrorFS[3];
float OtherState[12];
bool Blue;
float Opponent[3];
int Counter;
float Energy2[3];
int time;
float Energy0[3];
float Scoring6[3];
float Energy3[3];
float PreMirror[3];
float MyState[12];
float Mirror7[3];
float Scoring5[3];
float Energy1[3];
float Scoring4[3];
float Middle[3];
int Step;

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

//Begin page Energy
void Energy() {
  if (time >= 90 && game.checkHaveItemOther(0) && game.checkHaveItem(7)) {
    api.setPositionTarget(PreMirror);
    Step = 6;
  }
}
//End page Energy

//Begin page Mid
void Mid() {
  if (Step == 7 && (game.checkHaveItem(6) || game.checkHaveItemOther(6)) == true) {
    Step = 8;
  }
}
//End page Mid

//Begin page MiddleObject
void MiddleObject() {
  if (time <= 55 && OtherState[6] == Scoring4[0]) {
    api.setPositionTarget(Scoring5);
  }
}
//End page MiddleObject

//Begin page Mirror
void Mirror() {
  if (game.getScore() >= game.getOtherScore() && time == 127) {
    game.useMirror();
  }
}
//End page Mirror

//Begin page TakingPIC
void TakingPIC() {
  api.getOtherZRState(OtherState);
  api.setAttitudeTarget(OtherState);
  if (time >= 50 && (game.getEnergy() > 3 || Step == 8)) {
    if (game.isFacingOther() && game.checkInLightOther() == true) {
      if (game.getPicPoints() > 2) {
        game.takePic();
      }
    } else {
      api.getOtherZRState(OtherState);
      api.setAttitudeTarget(OtherState);
    }
  } else if (time <= 50 && game.getEnergy() > 4) {
    if (game.getPicPoints() > 2) {
      game.takePic();
    }
  }
}
//End page TakingPIC

//Begin page Time
void Time() {
  time = time + 1;
}
//End page Time

void init(){
	//This function is called once when your code is first loaded.
  Energy0[0] = 0.25;
  Energy0[1] = -0.4;
  Energy0[2] = 0;
  Energy1[0] = -0.25;
  Energy1[1] = -0.4;
  Energy1[2] = 0;
  Energy2[0] = 0.25;
  Energy2[1] = 0.4;
  Energy2[2] = 0;
  Energy3[0] = -0.25;
  Energy3[1] = 0.4;
  Energy3[2] = 0;
  Scoring4[0] = 0;
  Scoring4[1] = 0.6;
  Scoring4[2] = 0;
  Scoring5[0] = 0.4;
  Scoring5[1] = 0.6;
  Scoring5[2] = 0;
  Scoring6[0] = -0.4;
  Scoring6[1] = 0.6;
  Scoring6[2] = 0;
  Mirror7[0] = 0.6;
  Mirror7[1] = -0.7;
  Mirror7[2] = 0;
  Mirror8[0] = -0.6;
  Mirror8[1] = -0.7;
  Mirror8[2] = 0;
  Opponent[0] = 0;
  Opponent[1] = 0;
  Opponent[2] = 0;
  MyState[0] = 0;
  MyState[1] = 0;
  MyState[2] = 0;
  MyState[3] = 0;
  MyState[4] = 0;
  MyState[5] = 0;
  MyState[6] = 0;
  MyState[7] = 0;
  MyState[8] = 0;
  MyState[9] = 0;
  MyState[10] = 0;
  MyState[11] = 0;
  OtherState[0] = 0;
  OtherState[1] = 0;
  OtherState[2] = 0;
  OtherState[3] = 0;
  OtherState[4] = 0;
  OtherState[5] = 0;
  OtherState[6] = 0;
  OtherState[7] = 0;
  OtherState[8] = 0;
  OtherState[9] = 0;
  OtherState[10] = 0;
  OtherState[11] = 0;
  PreMirror[0] = 0.6;
  PreMirror[1] = -0.025;
  PreMirror[2] = 0;
  Middle[0] = 0;
  Middle[1] = 0.01;
  Middle[2] = 0;
  PostMirrorFS[0] = 0.25;
  PostMirrorFS[1] = -0.1;
  PostMirrorFS[2] = 0;
  Step = 0;
  Counter = 0;
  Blue = 0;
  time = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  Mid();
  Time();
  Mirror();
  Energy();
  TakingPIC();
  MiddleObject();
  api.getMyZRState(MyState);
  api.getOtherZRState(OtherState);
  api.setAttitudeTarget(Opponent);
  if (Step == 0) {
    api.getMyZRState(MyState);
    if (MyState[0] == 0.6) {
      Blue = true;
    } else {
      Blue = false;
    }
    Step = 1;
  }
  if (Step == 1) {
    setPos(-0.1, 0.86, 0);
    if (MyState[1] >= 0.3) {
      api.setPositionTarget(Scoring4);
      if (game.checkHaveItem(4) || game.checkHaveItemOther(4)) {
        DEBUG(( "Item 4 Taken" ));
        Step = 2;
      }
    }
  }
  if (Step == 2) {
    if (game.checkHaveItem(4)) {
      api.setPositionTarget(Energy2);
      if (game.checkHaveItem(2) || game.checkHaveItemOther(2)) {
        Step = 3;
      }
    }
  }
  if (Step == 3) {
    api.setPositionTarget(Energy0);
    if (game.checkHaveItem(0) || game.checkHaveItemOther(0)) {
      Step = 4;
    }
  }
  if (Step == 4) {
    api.setPositionTarget(Mirror7);
    if ((game.checkHaveItem(7) || game.checkHaveItemOther(7)) == true) {
      Step = 5;
      DEBUG(( "I have item 7" ));
    }
  }
  if (Step == 5) {
    api.setPositionTarget(PreMirror);
    DEBUG(( "Going To PreMirror" ));
    if (time >= 127) {
      Step = 6;
      DEBUG(( "Step Is Equal To Six" ));
    }
  }
  if (time >= 127 && (game.checkHaveItem(5) || game.checkHaveItemOther(5)) == false && Step == 6) {
    api.setPositionTarget(Scoring5);
  }
  if (Step == 6 && (game.checkHaveItem(5) || game.checkHaveItemOther(5)) == true) {
    Step = 7;
    DEBUG(( "Step 7" ));
  }
  if (Step == 7) {
    if (game.checkInLightOther() && (game.checkHaveItemOther(3) && game.checkHaveItem(3)) == false) {
      api.setPositionTarget(Energy3);
      if (game.checkHaveItem(3) == true) {
        Step = 8;
      }
    } else {
      Step = 8;
    }
  }
  if (Step == 8 && (game.checkHaveItemOther(6) && game.checkHaveItem(6)) == false) {
    api.setPositionTarget(Scoring6);
    if (game.checkHaveItem(6) == true) {
      Step = 9;
    }
  }
}

  
//Declare any variables shared between functions here
float my_state[12];
int get_item[12];
bool att_other;
float att[3];
float target_y[12];
bool canphoto;
int stage;
float pos[3];
float target_x[12];

void setPos(float x, float y, float z) {
	float pos[3];
	pos[0] = x; pos[1] = y; pos[2] = z;
	api.setPositionTarget(pos);
}

void init(){
	//This function is called once when your code is first loaded.
  stage = 0;
  pos[0] = 0;
  pos[1] = 0;
  pos[2] = 0;
  my_state[0] = 0;
  my_state[1] = 0;
  my_state[2] = 0;
  my_state[3] = 0;
  my_state[4] = 0;
  my_state[5] = 0;
  my_state[6] = 0;
  my_state[7] = 0;
  my_state[8] = 0;
  my_state[9] = 0;
  my_state[10] = 0;
  my_state[11] = 0;
  att[0] = 0;
  att[1] = 0;
  att[2] = 0;
  target_x[0] = 0.4;
  target_x[1] = 0.25;
  target_x[2] = 0.25;
  target_x[3] = 0.25;
  target_x[4] = 0.6;
  target_x[5] = 0;
  target_x[6] = 0;
  target_x[7] = -0.25;
  target_x[8] = -0.4;
  target_x[9] = 0;
  target_x[10] = 0;
  target_x[11] = 0;
  target_y[0] = 0.6;
  target_y[1] = 0.4;
  target_y[2] = -0.2;
  target_y[3] = -0.4;
  target_y[4] = -0.7;
  target_y[5] = -0.05;
  target_y[6] = 0.6;
  target_y[7] = 0.4;
  target_y[8] = 0.6;
  target_y[9] = 0;
  target_y[10] = 0;
  target_y[11] = 0;
  get_item[0] = 0;
  get_item[1] = 0;
  get_item[2] = 0;
  get_item[3] = 0;
  get_item[4] = 0;
  get_item[5] = 0;
  get_item[6] = 0;
  get_item[7] = 0;
  get_item[8] = 0;
  get_item[9] = 0;
  get_item[10] = 0;
  get_item[11] = 0;
  att_other = 0;
  canphoto = 0;
	//IMPORTANT: make sure to set any variables that need an initial value.
	//Do not assume variables will be set to 0 automatically!
}

void loop(){
	//This function is called once per second.  Use it to control the satellite.
  api.getMyZRState(my_state);
  photo();
  get_item[0] = !game.checkHaveItemNoOne(5) || api.getTime() >= 30;
  get_item[1] = !game.checkHaveItemNoOne(2) || api.getTime() >= 47;
  get_item[2] = api.getTime() == 59;
  get_item[3] = !game.checkHaveItemNoOne(0) || api.getTime() >= 83;
  get_item[4] = !game.checkHaveItemNoOne(7) || api.getTime() >= 104;
  get_item[5] = api.getTime() == 125;
  get_item[6] = !game.checkHaveItemNoOne(4) || api.getTime() >= 149;
  get_item[7] = !game.checkHaveItemNoOne(3) || api.getTime() >= 167;
  get_item[8] = !game.checkHaveItemNoOne(6);
  get_item[9] = my_state[1] > 0;
  if (stage == 5 && !game.checkHaveItemNoOne(4)) {
    target_x[stage] = -0.4;
  }
  if (stage > 5 && !game.checkHaveItemNoOne(4) && !game.checkHaveItemNoOne(3) && !game.checkHaveItemNoOne(6)) {
    stage = 9;
    target_x[stage] = my_state[0];
    target_y[stage] = 0.1;
  }
  if (stage < 10) {
    if (get_item[stage] == 1) {
      stage += 1;
    }
    if (stage < 10) {
      pos[0] = target_x[stage];
      pos[1] = target_y[stage];
    }
    api.setPositionTarget(pos);
  }
}

void photo() {
  if (game.isFacingOther()) {
    att_other = true;
  }
  game.getAttToOther(att);
  api.setAttitudeTarget(att);
  if (api.getTime() >= 170 || game.getEnergy() < 1 || game.checkInLight() || game.checkInLightOther() && game.getEnergy() >= 3) {
    game.takePic();
  }
  if (api.getTime() > 100 && game.checkInLight()) {
    game.useMirror();
  }
}