Tune in to the Galactic Greenhouse Finals Livestream and follow the live bracket!
Zero Robotics 2026

Galactic Garden Finals

February 21, 2026 · Bartos Theater, MIT Media Lab

2 Alliance 2 — The Circuit Alliance1st Place

“Build to connect, build to conquer.”

806 Orbiters Frogs of the Future NMS Robotics Team Team 404 Not Found
</> View Source Code
//Begin page main
int times[7];
int cropAtPlot[7];
int numPlanted[7];
int bonus[3];
int basePoints[7];
int plotState[7];
int best;
int cur_bonus;
int polarity; // for loitering purposes
float lastWatered[7]; //tracks the time interval each plant was watered
bool regret;
int side;
void init() {
    //our goal is to plant 21 crops
    // Tomato: 6, 4.5, 3.4
    // Cabbage: 7, 5.3, 3.9, 3
    // Strawberry: 5, 3.8, 2.8
    // Melon: 11, 8.3, 6.2, 4.6, 3.5 //2.6
    // Blueberry: 3,2.3
    // Potato: 8, 6, 4.5, 3.4
    times[0] = 4; // Melon
    times[1] = 6; // Potato
    times[2] = 2; // Cabbage
    times[3] = 1; // Tomato
    times[4] = 3; // Strawberry
    times[5] = 5; // Blueberry
    basePoints[1] = 6; // Tomato
    basePoints[2] = 7; // Cabbage
    basePoints[3] = 5; // Strawberry
    basePoints[4] = 11; // Melon
    basePoints[5] = 3; // Blueberry
    basePoints[6] = 8; // Potato
    cur_bonus = 0;
    best = 0;
    regret = false;
    if (game.GetRobotID() == 1) {
        side = -1;
    } else {
        side = 1;
    }
    // Unknown bonuses right now
    for (int i = 0; i< 3; i++) {
        bonus[i] = 0;
    }
    for (int i = 1; i< 7; i++) {
        numPlanted[i] = 0;
        cropAtPlot[i] = 0;
        plotState[i] = 0;
        lastWatered[i-1] = 0.0;
    }
    polarity = 1;
}
void water(int plotID)
{
    if(plotState[plotID] == 0) // planted but not watered
    {
        game.WaterCrop(plotID);
        lastWatered[plotID] = game.GetTime();
        plotState[plotID] = 1; 
    }
    else if(plotState[plotID] == 1)
    {
        int crop = cropAtPlot[plotID];
        float wait = lastWatered[plotID] + game.GetCropWaitTime(crop)-game.GetTime();
        if(wait>0)
        {
           game.SetWait(wait); 
        }
        game.WaterCrop(plotID);
        lastWatered[plotID] = game.GetTime();
        plotState[plotID] = 2;
    }
    else
    {
        DEBUG(("Error: invalid plot state(2)"));
    }
}
void harvest(int plotID)
{
    if(plotState[plotID] != 2)
    {
        DEBUG(("Invalid plot state HarvestCrop"));
        return;
    }
    int crop = cropAtPlot[plotID];
    float wait = lastWatered[plotID] + game.GetCropWaitTime(crop)-game.GetTime();
    DEBUG(("Wait time: %f", wait));
    if(wait>0)
    {
        game.SetWait(wait);
    }
    game.HarvestCrop(plotID);
    lastWatered[plotID] = 0;
    plotState[plotID] = 0;
    cropAtPlot[plotID] = 0;
}
int getBestCrop() {
    //constantly calculate 
    // based on current planted inventory, return the ID of the crop with
    // biggest points unless flagged by priority
    int id = 0;
    float points = 0.0;
    for (int i = 1; i < 7; i++)
    {
      if (i == 4 && game.GetTime() > 205) {
        continue;
      }
      int c = numPlanted[i];
      float p = pow(0.75, c) * basePoints[i];
      if (p > points) // simple sort
      {
        id = i;
        points = p;
      }
    }
    return id;
}
void getWater()
{
        // try to get water until you're full (in case opponent is there)
    if (game.OpponentAtWatering())
    {
        game.SetWait(1);
    }
    while (game.GetWaterUnits() < 6)
    {
        // to prevent overflow, we must wait
        if (game.OpponentAtWatering())
        {
            game.SetWait(1);
        }
        game.MoveWatering();
        game.FillWateringCan();
    }
}
void goAstronaut()
{
    if (game.OpponentAtAstronaut())
    {
        game.SetWait(1);    
    }
    DEBUG(("%d", cur_bonus));
    while (cur_bonus == 0) //returns 0 if not at astronaut
    {
        if (game.OpponentAtAstronaut())
        {
            game.SetWait(1); 
        }        
        game.MoveAstronaut();
        cur_bonus = game.GetBonusCrop();
        DEBUG(("%d", cur_bonus));
    }
}
void loiterPlot2()
{
    // robot moves back and forth to gain movement bonus when there's extra time
    game.MoveToVoid(0.35, 0.60 + 0.08 * polarity, 0.2*side);
    // turn around
    polarity = -polarity;
    game.SetWait(1);
    // this whole action should only take around 1 second
    // it's safe to use near the end
}
void threeWateringLoop(){
    //watering loop
    game.MovePlot(1);
    water(1);
    game.MovePlot(3);
    water(3);
    if (!regret){
        game.MovePlot(6);
        water(6);
    }
}
void harvestAndPlant(int plotID, int cropID) {
    game.MovePlot(plotID);
    if (cropAtPlot[plotID] == cur_bonus) {
        cur_bonus = 0;
    }
    harvest(plotID);
    game.PlantCrop(plotID,cropID);
    water(plotID);
    numPlanted[cropID]++;
    cropAtPlot[plotID] = cropID;
}
void simplePlant(int plotID, int cropID) {
    game.MovePlot(plotID);
    game.PlantCrop(plotID,cropID);
    water(plotID);
    numPlanted[cropID]++;
    cropAtPlot[plotID] = cropID;
}
void simpleWater(int plotID){
    game.MovePlot(plotID); water(plotID);  
}
void simpleHarvest(int plotID){
    game.MovePlot(plotID);  harvest(plotID);
}
void loop() {
    simplePlant(1,4); simplePlant(3,4);
    game.MovePlot(4);
    goAstronaut();
    bonus[0] = cur_bonus;
    game.MovePlot(5);
    if (bonus[0] == cropAtPlot[1] || bonus[0] == cropAtPlot[3]) {
        simplePlant(6,6);
    } else {
        simplePlant(6,bonus[0]);
    }
    threeWateringLoop(); getWater();
    harvestAndPlant(1,4); harvestAndPlant(3,4);
    if (cur_bonus != 0) {
        game.MovePlot(6);
        harvest(6);
        cur_bonus = 0;
        goAstronaut();
        bonus[1] = cur_bonus;
        if (bonus[1] == cropAtPlot[1] || bonus[1] == cropAtPlot[3]) {
            simplePlant(6,2);
        } else {
            simplePlant(6,bonus[1]);
        }
    } else {
        goAstronaut();
        bonus[1] = cur_bonus;
        if (bonus[1] == 4) {
            harvestAndPlant(6,2);
        } else {
            harvestAndPlant(6,bonus[1]);
        }
    }
    threeWateringLoop(); getWater();
    harvestAndPlant(1,4); harvestAndPlant(3,6);
    if (cur_bonus != 0) {
        game.MovePlot(6);
        harvest(6);
        cur_bonus = 0;
        goAstronaut();
        bonus[2] = cur_bonus;
        if (bonus[2] == cropAtPlot[1] || bonus[2] == cropAtPlot[3]) {
            simplePlant(6,1);
        } else {
            simplePlant(6,bonus[2]);
        }
    } else {
        goAstronaut();
        bonus[2] = cur_bonus;
        if (bonus[2] == cropAtPlot[1] || bonus[2] == cropAtPlot[3]) {
            harvestAndPlant(6,1);
        } else {
            harvestAndPlant(6,bonus[2]);
        }
    }
    threeWateringLoop(); getWater();
    best = getBestCrop(); harvestAndPlant(1,best);
    best = getBestCrop(); harvestAndPlant(3,best);
    best = getBestCrop(); harvestAndPlant(6,best);
    threeWateringLoop(); getWater();
    best = getBestCrop(); harvestAndPlant(1,best);
    best = getBestCrop(); harvestAndPlant(3,best);
    best = getBestCrop(); harvestAndPlant(6,best);
    threeWateringLoop(); getWater();
    best = getBestCrop(); harvestAndPlant(1,best);
    best = getBestCrop(); harvestAndPlant(3,best);
    best = getBestCrop(); harvestAndPlant(6,best);
    threeWateringLoop(); 
    if (game.GetTime()<211) {
        getWater();
        if (game.GetTime() < 205) {
            DEBUG(("planting three"));
            best = getBestCrop(); harvestAndPlant(1,best);
            best = getBestCrop(); harvestAndPlant(3,best);
            if (game.GetTime() > 220) { regret = true; }
            if (!regret){ best = getBestCrop();harvestAndPlant(6,best); }
            threeWateringLoop();
            if (game.GetTime() > 227) {regret = true;}
            simpleHarvest(1); simpleHarvest(3);
            if (!regret){
                simpleHarvest(6);
            }
        } else if (game.GetTime() < 211){
            DEBUG(("planting two"));
            best = getBestCrop(); harvestAndPlant(1,best);
            simpleHarvest(3);
            best = getBestCrop(); harvestAndPlant(6,best);
            simpleWater(1); simpleWater(6);  
            simpleHarvest(1); simpleHarvest(6);  
        } else {
            DEBUG(("planting one"));
            best = getBestCrop();
            harvestAndPlant(1,best);
            simpleHarvest(3); simpleWater(1);
            simpleHarvest(6); simpleHarvest(1);
        }
    } else{ 
        DEBUG(("planting none"));
        if (game.GetTime() < 230) {
            simpleHarvest(1);
            if (game.GetTime() < 230){
                simpleHarvest(3);
                if (game.GetTime() < 230){
                    simpleHarvest(6);
                }
            }
        }
    }
    game.MovePlot(2);
    if (game.GetTime() < 225) {
        getWater();
        simplePlant(2,5);
        game.MoveTo(0.35,0.60,side*(0.1));
        simpleWater(2);
        game.MoveTo(0.35,0.60,side*(0.1));
        simpleHarvest(2);
    }
    while (game.GetTime() < 237) {
        loiterPlot2();
    }
    game.EndGame();
}
//End page main
6 Alliance 6 — The Franco-Cheesian Empire2nd Place

“French strategy meets the strong work ethic of our Wisconsin team.”

AsterLovers523 Hillsborough High School Rochambotics The Cosmic Cougars

No video or presentation submitted

</> View Source Code
//Begin page main
//When the plot was last watered
double waterTimes[6];
//Plant time for the certain plot
double PT[6];
//Holds the plant's grow time
double PlantTime[6];
//Contains the amount of times watered on a plot used to determine whether to plant, water, or harvest
int charge[6];
//The current value of crops in correct id order
double cropValue[6];
// variable to check which plot of the cycle in loop I am checking.
int count;
// How many times I have visited Astronaut
int astro;
// stores the crop id of the bonus crop, set to 0 if no bonus crop
int bonus;
bool needastro;
int stopper;
void init(){
    // initializers to appropriate values.
    bonus = 0;
    astro = 0;
    waterTimes[0] = 0.0;
    waterTimes[1] = 0.0;
    waterTimes[2] = 0.0;
    waterTimes[3] = 0.0;
    waterTimes[4] = 0.0;
    waterTimes[5] = 0.0;
    PT[0] = 0.0;
    PT[1] = 0.0;
    PT[2] = 0.0;
    PT[3] = 0.0;
    PT[4] = 0.0;
    PT[5] = 0.0;
    PlantTime[0] = 6.0;
    PlantTime[1] = 8.0;
    PlantTime[2] = 5.0;
    PlantTime[3] = 12.0;
    PlantTime[4] = 3.0;
    PlantTime[5] = 9.0;
    charge[0] = 0;
    charge[1] = 0;
    charge[2] = 0;
    charge[3] = 0;
    charge[4] = 0;
    charge[5] = 0;
    cropValue[0] = 6.0;
    cropValue[1] = 7.0;
    cropValue[2] = 5.0;
    cropValue[3] = 11.0;
    cropValue[4] = 3.0;
    cropValue[5] = 8.0; 
    count = 0;
    needastro = true;
    stopper = 0;
}
void forceWater() {
    while (game.GetWaterUnits() == 0) {
        game.MoveWatering(); 
        game.FillWateringCan();
        if (game.OpponentAtWatering()) {
            game.MoveTo(0, 0, 0);
        }
    }
}
void wCrop(int plotNum, int cropNum) {
    forceWater();
    //moves to plot
    game.MovePlot(plotNum);
    if (game.GetTime() > 240) return;
    //plants the crop given in the 
    game.PlantCrop(plotNum, cropNum);
    waterTimes[plotNum-1] = game.GetTime();
    charge[plotNum-1] = 1;
    PT[plotNum-1] = cropNum == 1 ? 6.0 : cropNum == 2 ? 8.0 : cropNum == 3 ? 5.0 : cropNum == 4 ? 12.0 : cropNum == 5 ? 3.0 : 9.0;
    game.WaterCrop(plotNum);
    cropValue[cropNum-1] = cropValue[cropNum-1] * 0.75;
    if (cropNum == bonus) {bonus = 0; needastro = false;}
}
void WaterCrop(int plotNum) {
    forceWater();
    game.MovePlot(plotNum);
    if (game.GetTime() > 240) return;
    game.WaterCrop(plotNum);
    waterTimes[plotNum-1] = game.GetTime();
    charge[plotNum-1] = 2;
    // DEBUG(("Plot: %d", plotNum));
    // DEBUG(("Charge: %d", charge[plotNum-1]));
    // DEBUG(("%.2f", charge[plotNum-1]));
    // if (240-game.GetTime() > 20 && game.GetWaterUnits() == 0) {
    //     game.MoveWatering(); 
    //     game.FillWateringCan();
    // }
}
void HarvestCrop(int plotNum) {
    int astronumprior = game.GetCurrentBonusIndex();
    int harvestScorePrior = game.GetHarvestScore();
    game.MovePlot(plotNum);
    if (game.GetTime() > 240) return;
    game.HarvestCrop(plotNum);
    int astronumafter = game.GetCurrentBonusIndex();
    int harvestScoreAfter = game.GetHarvestScore();
    if (harvestScorePrior != harvestScoreAfter) {
        if (astronumafter > astronumprior && astronumafter != 3) {
            astro = astronumafter;
            game.MoveAstronaut();
            bonus = game.GetBonusCrop();
            // int placeholder = game.GetCurrentBonusIndex();
            // DEBUG(("place %d", placeholder));
            if (bonus == 0) needastro = true;
            else needastro = false;
        }
        charge[plotNum-1] = 0;
        waterTimes[plotNum-1] = 0;
        PT[plotNum-1] = 0;
        // helper(plotNum);
    }
    // DEBUG(("%d", charge[plotNum-1]));
}
void helper(int pn) {
    if (240-game.GetTime() > 20 && game.GetWaterUnits() == 0) {
        forceWater();
    }
    if (needastro && game.GetPlotsExplored() >= 4 && bonus == 0) {
        game.MoveAstronaut();
        bonus = game.GetBonusCrop();
        if (bonus == 0) needastro = true;
        else needastro = false;
    }
    float Time = game.GetTime();
    int bestcrop = 1;
    for (int i = 0; i < 6; i++) {
        if (Time - waterTimes[i] > 60 && waterTimes[i] != 0) charge[i] = 3;
        bestcrop = cropValue[i] > cropValue[bestcrop-1] ? i+1 : bestcrop;
    }
    if (bonus != 0) bestcrop = bonus;
    if (240-Time < 16) {
        if (Time-waterTimes[pn-1] > PT[pn-1] && charge[pn-1] == 2) {
            HarvestCrop(pn);
            if (Time < 230) {
                if (240-Time > 2.5*PlantTime[bestcrop-1]) wCrop(pn, bestcrop);
                else wCrop(pn, 5);
            }
            if (game.GetWaterUnits() == 0 && Time < 232) {
                game.MoveWatering(); 
                game.FillWateringCan();
            }
        }
         else if (charge[pn-1] == 1 && 240-Time > PT[pn-1] && Time-waterTimes[pn-1] > PT[pn-1] && Time < 230) {
            WaterCrop(pn);
            if (game.GetWaterUnits() == 0 && Time < 232) {
                game.MoveWatering(); 
                game.FillWateringCan();
            }
            bool someelsebetter = false;
            for (int i = 0; i < 6; i++) {
                if (PT[i] + waterTimes[i] < PT[pn-1]+waterTimes[pn-1] && PT[i] != 0) someelsebetter = true;
            }
            if (!someelsebetter) {
                game.SetWait(PT[pn-1]);
                HarvestCrop(pn);
            }
        }
    } else {
        if (game.GetTime() == 0) {wCrop(pn, bestcrop);charge[pn-1] = 1;}
        if (Time-waterTimes[pn-1] > PT[pn-1]-2 || !(charge[pn-1] == 0 || charge[pn-1] == 1 || charge[pn-1] == 2)) {
            // DEBUG(("Plot: %d", pn));
            if (charge[pn-1] == 2) {
                HarvestCrop(pn);
                helper(pn);
            }
            else if (charge[pn-1] == 1) {WaterCrop(pn);charge[pn-1] = 2;}
            else if (charge[pn-1] == 0) {wCrop(pn, bestcrop);charge[pn-1] = 1;}
        }
    }
}
void dohelp(int pn) {
    if (game.GetTime()-waterTimes[pn-1] > PT[pn-1] && charge[pn-1] == 2) {
        HarvestCrop(pn);
    }
    else if (charge[pn-1] == 1 && game.GetTime()-waterTimes[pn-1] > PT[pn-1]) {
        WaterCrop(pn);
    }
}
void wCropFinal40(int plotNum, int cropNum) {
    // Function to move to a plot, plant a specific crop, and set time data for the crop
    game.MovePlot(plotNum);
    game.PlantCrop(plotNum, cropNum);
    waterTimes[plotNum-1] = game.GetTime();
    charge[plotNum-1] = 1;
    // Determines what the crop's plant time is and sets the PT times based on the crop number
    PT[plotNum-1] = cropNum == 1 ? 6.0 : cropNum == 2 ? 8.0 : cropNum == 3 ? 5.0 : cropNum == 4 ? 12.0 : cropNum == 5 ? 3.0 : 9.0;
    game.WaterCrop(plotNum);
    // Crop value depreciation
    cropValue[cropNum-1] = cropValue[cropNum-1] * 0.75;
    // If the crop being planted is the bonus crop, set the bonus crop variable to zero to show that a new bonus crop can be generated
    if (cropNum == bonus) bonus = 0;
}
// FINAL 40 CODE IS BELOW
void helperFinal40(int pn) {
    float Time = game.GetTime();
    // helper determines if robot is able to do something with the plot
    int bestcrop = 1;
    for (int i = 0; i < 6; i++) {
        if (Time - waterTimes[i] > 60 && waterTimes[i] != 0) {
            charge[i] = 3;
            // DEBUG(("Charge: %.2f", charge[i]));
        }
        if (240-game.GetTime() < 2.5*PlantTime[i]) cropValue[i] = 0;
        bestcrop = cropValue[i] > cropValue[bestcrop-1] ? i+1 : bestcrop;
    }
    // DEBUG(("Crop Value: %.2f", cropValue[bestcrop-1]));
    // DEBUG(("%.2f", cropValue[bestcrop-1]));
    // if (game.GetTime()-waterTimes[pn-1] > PT[pn-1]-2) {
    //     // DEBUG(("%d", charge[pn-1]));
    //     if (charge[pn-1] == 2) {
    //         HarvestCrop(pn);
    //     }
    //     else if (charge[pn-1] == 1) {WaterCrop(pn);charge[pn-1] = 2;}
    //     else {wCropFinal40(pn, bestcrop);charge[pn-1] = 1;}
    // }
    if (240-Time < 16) {
        if (Time-waterTimes[pn-1] > PT[pn-1]-4 && charge[pn-1] == 2) {
            HarvestCrop(pn);
        }
         else if (charge[pn-1] == 1 && 240-Time > PT[pn-1]-1 && Time-waterTimes[pn-1] > PT[pn-1]-3 && game.GetWaterUnits() > 0) {
            // WaterCrop(pn);
            bool someelsebetter = false;
            for (int i = 0; i < 6; i++) {
                if (charge[i] == 2 || PT[i] < PT[pn-1]) someelsebetter = true;
            }
            if (!someelsebetter) {
                WaterCrop(pn);
                game.SetWait(PT[pn-1]);
                HarvestCrop(pn);
            } else if (Time < 230) {
                WaterCrop(pn);
            }
        } else if (charge[pn-1] == 0) {
            bool someelsebetter = false;
            for (int i = 0; i < 6; i++) {
                if (charge[i] == 2 || charge[i] == 1) someelsebetter = true;
            }
            if (!someelsebetter) {
                wCrop(pn, 5);
                game.SetWait(3.1);
                WaterCrop(pn);
                game.SetWait(3.1);
                HarvestCrop(pn);
            }
        }
    } else {
        if (Time-waterTimes[pn-1] > PT[pn-1]-2 || !(charge[pn-1] == 0 || charge[pn-1] == 1 || charge[pn-1] == 2)) {
            if (charge[pn-1] == 2) {
                HarvestCrop(pn);
                helperFinal40(pn);
            }
            else if (charge[pn-1] == 1) {WaterCrop(pn);charge[pn-1] = 2;}
            else {wCrop(pn, bestcrop);charge[pn-1] = 1;}
        }
    }
}
void final40() {
    // Assume that bonus crops have been obtained
    // id 5, 3, 1
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // DEBUG(("hidhfishdofsaijpfnwojfniuadbvijsdanovjabsihprfuiognrjv"));
    // cropValue[1] = cropValue[4];
    int f = 0; // Variable to simulate for loop within while loop; traverse through list of plots;
    // After watering, i will reset to zero so the loop can continue if possible
    int plotTravel[4] = {1, 3, 6, 2}; // Desired path
    while (game.GetTime() < 240) { // Runnable because at this point we are just running code until time runs out
        if (stopper %3 == 0) {
            // DEBUG(("ojgewipniuevoeaniughriutgheiuorgiuprnviurniucvbriugqeiugniouwernviouernviuoqbwriufbiwrghiuoenvioucnsuicnwiuorfgtr"));
        }
        if (game.GetWaterUnits() > 0 || game.GetTime() > 220) {
            helperFinal40(plotTravel[f]);
            f++;
            if (f == 1 ){
                dohelp(4);
                dohelp(5);
            }
            if (f == 4) {f = 0; stopper ++;}
        } else {
            forceWater();
        }
    }
}
void loop() {
    if (count == 0) {
        cropValue[0] = 6.0;
        cropValue[1] = 7.0;
        cropValue[2] = 5.0;
        cropValue[3] = 11.0;
        cropValue[4] = 3.0;
        cropValue[5] = 8.0; 
        // DEBUG(("%.2f", cropValue[0]));
        // wCrop(1,2);
        helper(1);
        //     wCrop(3,4);
        helper(3);
        helper(4);
        game.MoveAstronaut();
        bonus = game.GetBonusCrop();
        helper(5);
        //     wCrop(6,6);
        helper(6);
        //     wCrop(5,1);
        //     wCrop(4,bonus);
        //     WaterCrop(3);
        helper(2);
        game.MoveWatering(); 
        game.FillWateringCan();
        game.GetWaterUnits();
        count = 1;
    } else if (game.GetCurrentBonusIndex() < 3) {
        // if (count == 1) {
        //     helper(1);
        //     count = 3;
        // }
        // if (count == 2) {
        //     helper(2);
        //     if (game.GetTime() < 220) {
        //         game.MoveWatering(); 
        //         game.FillWateringCan();
        //     }
        //     count = 1;
        // }
        // if (count == 3) {
        //     helper(3);
        //     count = 4;
        // }
        // if (count == 4) {
        //     helper(4);
        //     helper(5);
        //     count = 6;
        // }
        // if (count == 6) {
        //     helper(6);
        //     count = 2;
        // }
        if (count == 1) {
            helper(1);
            // if (game.GetWaterUnits() <= 1 && !(game.OpponentAtWatering() || game.OpponentGoingToWatering())) {
            //     game.MoveWatering(); 
            //     game.FillWateringCan();
            // }
            count = 3;
        }
        if (count == 2) {
            helper(2);
            if (game.GetWaterUnits() <= 1 && !(game.OpponentAtWatering() || game.OpponentGoingToWatering())) {
                game.MoveWatering(); 
                game.FillWateringCan();
            }
            // DEBUG(("BROTHER"));
            count = 1;
        }
        if (count == 3) {
            helper(3);
            dohelp(4);
            dohelp(5);
            count = 6;
        }  
        if (count == 6) {
            helper(6);
            count = 2;
        }
        // DEBUG(("ASTRO: %d", astro));
        // stopper++;
        // if (stopper == 8) return;
    } else {
        // return;
        // if (count == 1) {
        //     helper(1);
        //     count = 3;
        // }
        // if (count == 2) {
        //     helper(2);
        //     DEBUG(("BROTHER"));
        //     if (game.GetTime() < 220) {
        //         game.MoveWatering(); 
        //         game.FillWateringCan();
        //     }
        //     count = 1;
        // }
        // if (count == 3) {
        //     helper(3);
        //     dohelp(4);
        //     dohelp(5);
        //     count = 6;
        // }  
        // if (count == 6) {
        //     helper(6);
        //     count = 2;
        // }
        final40();
    }
    if (game.GetTime() < 240) loop();
    else {
        // game.GetDistanceTraveled(); game.GetPlotsExplored(); game.GetCurrentBonusIndex();
        for (int i = 0; i < 6; i++) {
            DEBUG(("Crop Value: %.2f", cropValue[i]));
            DEBUG(("Charge: %d", charge[i]));
        }
        // game.GetBattery();
        game.EndGame();
    }
}
//End page main
10 Alliance 103rd Place
Compiler’s Collective Madison Highland Prep SPACE SCIENCE CLUB Wicked Robotics 2026 HS

No video or presentation submitted

</> View Source Code
float OpponentAstronaut;
float BonusCrop1;
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() {
  BonusCrop1 = 1;
  OpponentAstronaut = 0;
}
//End page init
//Begin page main
void loop() {
  game.MovePlot(1);
  game.PlantCrop(1, 4);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.PlantCrop(3, 4);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.PlantCrop(4, 6);
  game.WaterCrop(4);
  game.MoveAstronaut();
  BonusCrop1 = game.GetBonusCrop();
  while (BonusCrop1 == 0) {
    game.MoveAstronaut();
    BonusCrop1 = game.GetBonusCrop();
  }
  game.MovePlot(5);
  game.PlantCrop(5, BonusCrop1);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.PlantCrop(6, 4);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.PlantCrop(2, 1);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.PlantCrop(1, 6);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.PlantCrop(3, 2);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.PlantCrop(4, 3);
  game.WaterCrop(4);
  game.MoveAstronaut();
  BonusCrop1 = game.GetBonusCrop();
  while (BonusCrop1 == 0) {
    game.MoveAstronaut();
    BonusCrop1 = game.GetBonusCrop();
  }
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.PlantCrop(5, BonusCrop1);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.PlantCrop(6, 1);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.PlantCrop(2, 6);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.PlantCrop(1, 2);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.PlantCrop(3, 3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.PlantCrop(4, 4);
  game.WaterCrop(4);
  game.MoveAstronaut();
  BonusCrop1 = game.GetBonusCrop();
  while (BonusCrop1 == 0) {
    game.MoveAstronaut();
    BonusCrop1 = game.GetBonusCrop();
  }
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.PlantCrop(5, BonusCrop1);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.PlantCrop(6, 6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.PlantCrop(2, 5);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.PlantCrop(1, 2);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.PlantCrop(3, 3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.PlantCrop(4, 4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.PlantCrop(5, 1);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.PlantCrop(6, 6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.PlantCrop(2, 5);
  game.WaterCrop(2);
  game.MoveWatering();
  game.FillWateringCan();
  while (game.GetWaterUnits() == 0) {
    game.MoveWatering();
    game.FillWateringCan();
  }
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.MoveAstronaut();
  game.MoveToHome();
  game.MoveAstronaut();
}
//End page main
1 Alliance 1 — AstroEaglesRunner UpMost Readable Code

“An alliance of passionate high school students who rely on innovation and teamwork to overcome challenging coding problems.”

#include<Dillmann> First State Tech Wizards New Albany High School STEM in Space
</> View Source Code
//Begin page main
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef ROUTE_MAX
#define ROUTE_MAX 4096
#endif
//The high-level design for the program is outlined below:
//1). The location task list will be maintained throughout the program that will
// contain location number, crop number, crop status and last action time. 
// The crop status will be P when crop is planted and watered once, and 'W' when the crop has been watered for the second time, and it will be 'N' when location is empty and has nothing to perform.
//2). Then we will get the must include and must exclude locations that need to be considered while Astrobee is traveling across the locations. The must include location list will have the following priorities:-
//   a). First priority will be given to the crops with the status P and least action time based on the available water.
//   b). Second priority will be given to the bonus crop.
//   c). Third priority will be given to the crops that are ready to harvest and are available in the crop list. The crop list will contain bonus crops until bonus completion is not done, and after that it will contain all the crops. 
//   d). Fourth priority will consider all the locations with the status W, and not considered in the above 3 priorities. This will only consider the crops of same type that are ready to harvest and are present for more than once.
//The must exclude location list will include all the locations with the status P or W, and are not included in the must include location list given above.
//3). Based on the must include and exclude location list from the above steps,
// the best route will be calculated that the Astrobee will travel using the best route function.
//4). After getting the best route, we will get the route task list that will contain 
// the tasks that the astrobee needs to perform while travelling the route. 
// The task will be to water the crop if the previous status is 'P', to harvest the 
// crop if the previous status is 'W', to plant the crop if the previous status is 'N'. 
// Then for the locations with new task assigned as harvesting or planting , new crop 
// will be assigned based on it's growth time and maximum points that we will earn from
// planting this crop next time.
//5). Then, for the final route task list that we have got from the above step,
// the Astrobee will travel across the route performing the assigned tasks for the remaining time.
//====================================Determining Best Route Function=====================================
//========================================================================================================
//structures for storing data
typedef struct {
    int id;
    double x, y, z;
} Location;
typedef struct {
    int ok;                
    const char *msg;       
    int route_len;         
    double total_distance;
} RouteResult;
typedef struct {
    int cropID;
    int growthTime;
    int numTimesCropPlanted;
    int numPointNext;
} CropList;
typedef struct {
    int location_id;
    int crop_id;
    char status;
    int latest_time;
} TaskList;
// function to find distance between 2 points in 3d space (3d pythagorean theorem)
static inline double dist3(const Location *a, const Location *b) {
    double dx = a->x - b->x;
    double dy = a->y - b->y;
    double dz = a->z - b->z;
    return sqrt(dx*dx + dy*dy + dz*dz);
}
static int find_index_by_id(const Location *locs, int n, int id) {
    for (int i = 0; i < n; i++) {
        if (locs[i].id == id) return i;
    }
    return -1;
}
// function to subract 3 dimensional vectors
static void vec3_sub(const Location *a, const Location *b, double *ox, double *oy, double *oz) {
    *ox = a->x - b->x;
    *oy = a->y - b->y;
    *oz = a->z - b->z;
}
static double dot3(double ax, double ay, double az, double bx, double by, double bz) {
    return ax*bx + ay*by + az*bz;
}
static double projection_t_on_line(const Location *p, const Location *start, const Location *end) {
    double vx, vy, vz;
    vec3_sub(end, start, &vx, &vy, &vz);
    double wx, wy, wz;
    vec3_sub(p, start, &wx, &wy, &wz);
    double denom = dot3(vx,vy,vz, vx,vy,vz);
    if (denom <= 0.0) return 0.0;
    return dot3(wx,wy,wz, vx,vy,vz) / denom;
}
//function to check if an element is in a list by looping through it
static int is_in_list(const int *arr, int len, int id) {
    for (int i = 0; i < len; i++) if (arr[i] == id) return 1;
    return 0;
}
// function to confirm if a route has a certain location in it
static int route_contains_idx(const int *route_idx, int route_len, int idx) {
    for (int i = 0; i < route_len; i++) if (route_idx[i] == idx) return 1;
    return 0;
}
//function to insert a location into the route (route_idx)
static void route_insert_idx(int *route_idx, int *route_len, int insert_pos, int idx) {
    for (int i = *route_len; i > insert_pos; i--) {
        route_idx[i] = route_idx[i-1];
    }
    route_idx[insert_pos] = idx;
    (*route_len)++;
}
// generates fail message based on function below
static RouteResult fail(const char *msg) {
    RouteResult r;
    r.ok = 0;
    r.msg = msg;
    r.route_len = 0;
    r.total_distance = 0.0;
    return r;
}
static void enforce_start_neighbor_prefer_1(
    int *route_idx, int route_len,
    const Location *locs,
    int start_id
){
    if (!(start_id == 7 || start_id == 8)) return;
    if (route_len < 4) return; // need at least start, one stop, one stop, end
    // Route is [start ... end], and in your test start_id == end_id
    int next_id = locs[route_idx[1]].id;
    int prev_id = locs[route_idx[route_len - 2]].id; // node before final end/start
    // If start's two neighbors are 2 (next) and 1 (prev), flip the tour direction.
    // This keeps the same cycle, just reverses the visit order so next becomes 1.
    if (next_id == 2 && prev_id == 1) {
        int L = 1, R = route_len - 2; // reverse everything between the endpoints
        while (L < R) {
            int tmp = route_idx[L];
            route_idx[L] = route_idx[R];
            route_idx[R] = tmp;
            L++; R--;
        }
    }
}
//function to actually find the best route
RouteResult find_best_route(
    const Location *locs, int n_locs,
    int start_id,
    int end_id,
    int k_stops,
    const int *must_go_ids, int must_go_len,
    const int *exclude_ids, int exclude_len,
    int *out_route_ids, int out_route_capacity,
    double *out_leg_dist, int out_leg_capacity
) {
    if (!locs || n_locs <= 0) return fail("locs is empty");
    if (k_stops < 0) return fail("k_stops must be >= 0");
    if (!out_route_ids || out_route_capacity < (k_stops + 2)) return fail("out_route_ids capacity too small");
    if (!out_leg_dist || out_leg_capacity < (k_stops + 2)) return fail("out_leg_dist capacity too small");
    int start_idx = find_index_by_id(locs, n_locs, start_id);
    int end_idx   = find_index_by_id(locs, n_locs, end_id);
    if (start_idx < 0) return fail("start_id not found in locations");
    if (end_idx < 0) return fail("end_id not found in locations");
    if (is_in_list(exclude_ids, exclude_len, start_id)) return fail("start_id is in exclude list");
    if (is_in_list(exclude_ids, exclude_len, end_id))   return fail("end_id is in exclude list");
    if (must_go_len > k_stops) return fail("must_go_len > k_stops (impossible)");
    if ((k_stops + 2) > ROUTE_MAX) return fail("ROUTE_MAX too small for requested route length");
    uint8_t *blocked = (uint8_t*)calloc((size_t)n_locs, sizeof(uint8_t));
    if (!blocked) return fail("calloc failed for blocked");
    blocked[start_idx] = 1;
    blocked[end_idx] = 1;
    for (int i = 0; i < exclude_len; i++) {
        int ex_idx = find_index_by_id(locs, n_locs, exclude_ids[i]);
        if (ex_idx >= 0) blocked[ex_idx] = 1; // ignore unknown exclude ids
    }
    // Convert must-go IDs to indices + validate
    int *must_idx = NULL;
    if (must_go_len > 0) {
        must_idx = (int*)malloc((size_t)must_go_len * sizeof(int));
        if (!must_idx) { free(blocked); return fail("malloc failed for must_idx"); }
    }
    for (int i = 0; i < must_go_len; i++) {
        int id = must_go_ids[i];
        if (id == start_id || id == end_id) {
            free(blocked); free(must_idx);
            return fail("must_go list cannot include start_id or end_id");
        }
        if (is_in_list(exclude_ids, exclude_len, id)) {
            free(blocked); free(must_idx);
            return fail("must_go list contains an excluded location");
        }
        int idx = find_index_by_id(locs, n_locs, id);
        if (idx < 0) {
            free(blocked); free(must_idx);
            return fail("must_go id not found in locations");
        }
        // checking duplicates in must go list
        for (int j = 0; j < i; j++) {
            if (must_idx[j] == idx) {
                free(blocked); free(must_idx);
                return fail("must_go list contains duplicates");
            }
        }
        must_idx[i] = idx;
    }
    // Start route = [start, end]
    int route_idx[ROUTE_MAX];
    int route_len = 0;
    route_idx[route_len++] = start_idx;
    route_idx[route_len++] = end_idx;
    int current_stops = 0;
    // ---- Step 1: we insert must include locations with cheapest insertion (order not fixed) ----
    uint8_t *must_used = NULL;
    if (must_go_len > 0) {
        must_used = (uint8_t*)calloc((size_t)must_go_len, sizeof(uint8_t));
        if (!must_used) { free(blocked); free(must_idx); return fail("calloc failed for must_used"); }
    }
    for (int placed = 0; placed < must_go_len; placed++) {
        double best_delta = DBL_MAX;
        int best_m = -1;
        int best_pos = -1;
        for (int m = 0; m < must_go_len; m++) {
            if (must_used[m]) continue;
            int cand = must_idx[m];
            if (blocked[cand]) continue;
            double cand_best_delta = DBL_MAX;
            int cand_best_pos = -1;
            for (int i = 0; i < route_len - 1; i++) {
                const Location *A = &locs[route_idx[i]];
                const Location *B = &locs[route_idx[i+1]];
                const Location *C = &locs[cand];
                double delta = dist3(A, C) + dist3(C, B) - dist3(A, B);
                if (delta < cand_best_delta) {
                    cand_best_delta = delta;
                    cand_best_pos = i + 1;
                }
            }
            if (cand_best_delta < best_delta) {
                best_delta = cand_best_delta;
                best_m = m;
                best_pos = cand_best_pos;
            }
        }
        if (best_m < 0 || best_pos < 0) {
            free(blocked); free(must_idx); free(must_used);
            return fail("could not place all must-go nodes");
        }
        int chosen = must_idx[best_m];
        route_insert_idx(route_idx, &route_len, best_pos, chosen);
        blocked[chosen] = 1;
        must_used[best_m] = 1;
        current_stops++;
    }
    // ---- Step 2: fill remaining stops up to num stops with cheapest insertion ----
    while (current_stops < k_stops) {
        double best_delta = DBL_MAX;
        int best_cand = -1;
        int best_pos = -1;
        for (int cand = 0; cand < n_locs; cand++) {
            if (blocked[cand]) continue;
            if (route_contains_idx(route_idx, route_len, cand)) continue;
            double cand_best_delta = DBL_MAX;
            int cand_best_pos = -1;
            for (int i = 0; i < route_len - 1; i++) {
                const Location *A = &locs[route_idx[i]];
                const Location *B = &locs[route_idx[i+1]];
                const Location *C = &locs[cand];
                double delta = dist3(A, C) + dist3(C, B) - dist3(A, B);
                if (delta < cand_best_delta) {
                    cand_best_delta = delta;
                    cand_best_pos = i + 1;
                }
            }
            if (cand_best_delta < best_delta) {
                best_delta = cand_best_delta;
                best_cand = cand;
                best_pos = cand_best_pos;
            }
        }
        if (best_cand < 0 || best_pos < 0) {
            free(blocked); free(must_idx); free(must_used);
            return fail("not enough valid candidates to reach k_stops");
        }
        route_insert_idx(route_idx, &route_len, best_pos, best_cand);
        blocked[best_cand] = 1;
        current_stops++;
    }
    int improved = 1;
    while (improved) {
        improved = 0;
        // We don't swap the start (0) or end (route_len-1)
        for (int i = 1; i < route_len - 2; i++) {
            for (int j = i + 1; j < route_len - 1; j++) {
                // Current edges: (i-1 to i) and (j to j+1)
                const Location *A = &locs[route_idx[i-1]];
                const Location *B = &locs[route_idx[i]];
                const Location *C = &locs[route_idx[j]];
                const Location *D = &locs[route_idx[j+1]];
                double current_dist = dist3(A, B) + dist3(C, D);
                double new_dist     = dist3(A, C) + dist3(B, D);
                if (new_dist < current_dist - 1e-6) { // Small epsilon for float safety
                    // Reverse the segment from i to j
                    int left = i, right = j;
                    while (left < right) {
                        int temp = route_idx[left];
                        route_idx[left] = route_idx[right];
                        route_idx[right] = temp;
                        left++;
                        right--;
                    }
                    improved = 1;
                }
            }
        }
    }
    enforce_start_neighbor_prefer_1(route_idx, route_len, locs, start_id);
    // outputs
    double total = 0.0;
    for (int i = 0; i < route_len; i++) {
        out_route_ids[i] = locs[route_idx[i]].id;
        if (i == 0) out_leg_dist[i] = 0.0;
        else {
            double leg = dist3(&locs[route_idx[i-1]], &locs[route_idx[i]]);
            out_leg_dist[i] = leg;
            total += leg;
        }
    }
    free(blocked);
    free(must_idx);
    free(must_used);
    RouteResult ok;
    ok.ok = 1;
    ok.msg = "ok";
    ok.route_len = route_len;
    ok.total_distance = total;
    return ok;
}
//===========================Must Include and Must Exclude List Creation============================
//==================================================================================================
typedef struct {
    int location_id;
    int crop_id;
    char old_status;   // from task list: 'P' or 'W'
    char new_status;   // 'W' if old status is 'P', 'H' if old status is 'W'
    int latest_time;
} IncludeTask;
typedef struct {
    int ok;                // 1 success, 0 failure
    const char *msg;
    int include_len;
    int exclude_len;
    int water_left;
    int water_buffer_bonus_crop;
    int bonus_crop_location;
} MustListResult;
static MustListResult ml_fail(const char *msg) {
    MustListResult r;
    r.ok = 0; r.msg = msg;
    r.include_len = 0; r.exclude_len = 0;
    r.water_left = 0;
    r.water_buffer_bonus_crop = 0;
    return r;
}
static int contains_int_safe(const int *arr, int len, int v) {
    if (!arr || len <= 0) return 0;
    for (int i = 0; i < len; i++) if (arr[i] == v) return 1;
    return 0;
}
static void add_unique_int(int *arr, int *len, int cap, int v) {
    if (*len >= cap) return;
    if (!contains_int_safe(arr, *len, v)) arr[(*len)++] = v;
}
static int find_task_index_by_location(const TaskList *tasks, int task_count, int location_id) {
    for (int i = 0; i < task_count; i++) {
        if (tasks[i].location_id == location_id) return i;
    }
    return -1;
}
static int cost_w(int end_is_astro_zone) { return end_is_astro_zone ? 2 : 1; }
static int cost_p(void) { return 1; }
static void clamp_water_nonneg(int *w) {
    if (*w < 0) *w = 0;
}
static int pick_min_time_task(
    const TaskList *tasks, int task_count,
    const int *must_include_ids, int include_len,
    const int *exclude_in_ids, int exclude_in_len,
    char status_filter,              // 'P' or 'W' or 0 for any
    int crop_id_filter,              // specific crop id or -1 for any
    const int *bonus_crop_list, int bonus_crop_len, // membership constraint or NULL/0
    const int *w_dup_crop_ids, int w_dup_len         // membership constraint or NULL/0
){
    int best = -1;
    for (int i = 0; i < task_count; i++) {
        int loc = tasks[i].location_id;
        if (contains_int_safe(exclude_in_ids, exclude_in_len, loc)) continue;
        if (contains_int_safe(must_include_ids, include_len, loc)) continue;
        if (status_filter != 0 && tasks[i].status != status_filter) continue;
        if (crop_id_filter != -1 && tasks[i].crop_id != crop_id_filter) continue;
        if (bonus_crop_list && bonus_crop_len > 0) {
            if (!contains_int_safe(bonus_crop_list, bonus_crop_len, tasks[i].crop_id)) continue;
        }
        if (w_dup_crop_ids && w_dup_len > 0) {
            if (!contains_int_safe(w_dup_crop_ids, w_dup_len, tasks[i].crop_id)) continue;
        }
        if (best < 0 || tasks[i].latest_time < tasks[best].latest_time) best = i;
    }
    return best;
}
// build a list of cropIDs that appear >1 times with status 'W'
static int build_w_duplicate_crop_list(
    const TaskList *tasks, int task_count,
    int *out_crop_ids, int out_cap
){
    int out_len = 0;
    for (int i = 0; i < task_count; i++) {
        if (tasks[i].status != 'W') continue;
        int cid = tasks[i].crop_id;
        if (cid == 0) continue;
        // count occurrences
        int cnt = 0;
        for (int j = 0; j < task_count; j++) {
            if (tasks[j].status == 'W' && tasks[j].crop_id == cid) cnt++;
        }
        if (cnt > 1) add_unique_int(out_crop_ids, &out_len, out_cap, cid);
    }
    return out_len;
}
static int find_keep_w_idx_for_crop(const TaskList *tasks, int task_count, int crop_id) {
    int keep = -1;
    for (int i = 0; i < task_count; i++) {
        if (tasks[i].status != 'W') continue;
        if (tasks[i].crop_id != crop_id) continue;
        if (keep < 0 || tasks[i].latest_time > tasks[keep].latest_time) keep = i;
    }
    return keep;
}
MustListResult get_must_incl_excl_loc_lists(
    const TaskList *tasks, int task_count,
    int water_units,
    int current_bonus_crop_id,
    const int *exclude_in_ids, int exclude_in_len,
    const int *bonus_crop_list, int bonus_crop_len,
    int bonus_completion,
    const int *exclude_plantation_ids, int exclude_plantation_len,
    int end_is_astro_zone,
    int *must_include_ids, int include_capacity,
    int *must_exclude_ids, int exclude_capacity,
    IncludeTask *must_include_tasks, int include_task_capacity
){
    if (!tasks || task_count < 0) return ml_fail("tasks invalid");
    if (!must_include_ids || include_capacity < task_count) return ml_fail("include buffer too small");
    if (!must_include_tasks || include_task_capacity < task_count) return ml_fail("include task buffer too small");
    if (!must_exclude_ids || exclude_capacity < (task_count + exclude_in_len + exclude_plantation_len))
        return ml_fail("exclude buffer too small");
    int include_len = 0;
    int exclude_len = 0;
    int bonus_crop_location = -1;
    int water_buffer_bonus_crop = 0;
    // =========================
    // PRIORITY 1: current bonus crop
    // =========================
    if (current_bonus_crop_id != -1) {
        int bonus_count = 0;
        int only_idx = -1;
        // collect best W (least time) and best P (least time)
        int best_w = -1;
        int best_p = -1;
        for (int i = 0; i < task_count; i++) {
            if (tasks[i].crop_id != current_bonus_crop_id) continue;
            bonus_count++;
            only_idx = i;
            if (tasks[i].status == 'W') {
                if (best_w < 0 || tasks[i].latest_time < tasks[best_w].latest_time) best_w = i;
            } else if (tasks[i].status == 'P') {
                if (best_p < 0 || tasks[i].latest_time < tasks[best_p].latest_time) best_p = i;
            }
        }
        if (bonus_count == 0) {
            // if not in task list then set buffer cost & subtract from water
            water_buffer_bonus_crop = end_is_astro_zone ? 2 : 1;
            water_units -= water_buffer_bonus_crop;
            clamp_water_nonneg(&water_units);
        } else if (bonus_count == 1) {
            int loc = tasks[only_idx].location_id;
            if (!contains_int_safe(exclude_in_ids, exclude_in_len, loc)) {
                add_unique_int(must_include_ids, &include_len, include_capacity, loc);
                bonus_crop_location = loc;
                // If status P then subtract 1
                // If status W then subtract 2 if astro-zone end else 1
                if (tasks[only_idx].status == 'P') water_units -= cost_p();
                else if (tasks[only_idx].status == 'W') water_units -= cost_w(end_is_astro_zone);
                clamp_water_nonneg(&water_units);
            }
        } else {
            // multiple: prefer W least time or else P least time
            int chosen = (best_w >= 0) ? best_w : best_p;
            if (chosen >= 0) {
                int loc = tasks[chosen].location_id;
                if (!contains_int_safe(exclude_in_ids, exclude_in_len, loc)) {
                    add_unique_int(must_include_ids, &include_len, include_capacity, loc);
                    bonus_crop_location = loc;
                    if (tasks[chosen].status == 'W') water_units -= cost_w(end_is_astro_zone);
                    else if (tasks[chosen].status == 'P') water_units -= cost_p();
                    clamp_water_nonneg(&water_units);
                }
            }
        }
    }
    // =========================
    // PRIORITY 2: remaining P locations by least latest_time, each costs 1 water
    // =========================
    while (water_units >= 1) {
        int idx = pick_min_time_task(
            tasks, task_count,
            must_include_ids, include_len,
            exclude_in_ids, exclude_in_len,
            'P',
            -1,
            NULL, 0,
            NULL, 0
        );
        if (idx < 0) break;
        add_unique_int(must_include_ids, &include_len, include_capacity, tasks[idx].location_id);
        water_units -= cost_p();
        clamp_water_nonneg(&water_units);
    }
    // =========================
    // PRIORITY 3: remaining W where crop_id in bonus_crop_list, each costs (2 if astro end else 1)
    // =========================
    while (1) {
        int idx = pick_min_time_task(
            tasks, task_count,
            must_include_ids, include_len,
            exclude_in_ids, exclude_in_len,
            'W',
            -1,
            bonus_crop_list, bonus_crop_len,
            NULL, 0
        );
        if (idx < 0) break; // no more eligible W+bonusCrop candidates
        int loc = tasks[idx].location_id;
        int cost = 0;
        if (!contains_int_safe(exclude_plantation_ids, exclude_plantation_len, loc)) {
            cost = cost_w(end_is_astro_zone); // 2 if astro-zone end else 1
        } 
        if (cost > 0 && water_units < cost) break;
        add_unique_int(must_include_ids, &include_len, include_capacity, loc);
        water_units -= cost;
        clamp_water_nonneg(&water_units);
    }
    // ========================
    // PRIORITY 4: include duplicate-W crops, but leave ONE W per crop
    // ========================
    if (water_units > 0) {
        int cost = end_is_astro_zone ? 2 : 1;
        // We will repeatedly pick the most urgent eligible duplicate-W location
        // (smallest latest_time), while leaving one W per crop (the "keep" idx).
        while (water_units >= cost) {
            int best_idx = -1;
            int best_time = 0;
            for (int i = 0; i < task_count; i++) {
                if (tasks[i].status != 'W') continue;
                int loc = tasks[i].location_id;
                int crop = tasks[i].crop_id;
                if (contains_int_safe(exclude_in_ids, exclude_in_len, loc)) continue;
                if (contains_int_safe(must_include_ids, include_len, loc)) continue;
                // count how many W exist for this crop
                int w_count = 0;
                for (int j = 0; j < task_count; j++) {
                    if (tasks[j].status == 'W' && tasks[j].crop_id == crop) w_count++;
                }
                if (w_count <= 1) continue; // not a duplicate-W crop
                // we determine which W index we must keep for this crop (max latest_time)
                int keep_idx = find_keep_w_idx_for_crop(tasks, task_count, crop);
                if (keep_idx == i) continue; // skip the one we want to leave as W
                // candidate: pick the most urgent (smallest latest_time)
                if (best_idx < 0 || tasks[i].latest_time < best_time) {
                    best_idx = i;
                    best_time = tasks[i].latest_time;
                }
            }
            if (best_idx < 0) break; // no more eligible duplicate-W locations to include
            add_unique_int(must_include_ids, &include_len, include_capacity, tasks[best_idx].location_id);
            water_units -= cost;
        }
    }
    // =========================
    // MUST EXCLUDE criteria:
    // 1) all P/W not included
    // 2) if bonus_completion true: all N locations that are present in exclude_plantation_list
    // 3) append exclude_in_ids
    // =========================
    for (int i = 0; i < task_count; i++) {
        if (tasks[i].status != 'P' && tasks[i].status != 'W') continue;
        int loc = tasks[i].location_id;
        if (!contains_int_safe(must_include_ids, include_len, loc)) {
            add_unique_int(must_exclude_ids, &exclude_len, exclude_capacity, loc);
        }
    }
    for (int i = 0; i < task_count; i++) {
        if (tasks[i].status != 'N') continue;
        int loc = tasks[i].location_id;
        if (contains_int_safe(exclude_plantation_ids, exclude_plantation_len, loc)) {
            add_unique_int(must_exclude_ids, &exclude_len, exclude_capacity, loc);
        }
    }
    for (int i = 0; i < exclude_in_len; i++) {
        add_unique_int(must_exclude_ids, &exclude_len, exclude_capacity, exclude_in_ids[i]);
    }
    // =========================
    // MUST INCLUDE TASK LIST (add new status)
    // old P -> new W
    // old W -> new H
    // =========================
    int include_task_len = 0;
    for (int k = 0; k < include_len; k++) {
        int loc = must_include_ids[k];
        int ti = find_task_index_by_location(tasks, task_count, loc);
        if (ti < 0) return ml_fail("included location not found in task list");
        char olds = tasks[ti].status;
        char news;
        if (olds == 'P') news = 'W';
        else if (olds == 'W') news = 'H';
        else return ml_fail("included location has non P/W status");
        if (include_task_len >= include_task_capacity) return ml_fail("include task buffer too small");
        must_include_tasks[include_task_len].location_id = loc;
        must_include_tasks[include_task_len].crop_id = tasks[ti].crop_id;
        must_include_tasks[include_task_len].old_status = olds;
        must_include_tasks[include_task_len].new_status = news;
        must_include_tasks[include_task_len].latest_time = tasks[ti].latest_time;
        include_task_len++;
    }
    MustListResult out;
    out.ok = 1;
    out.msg = "ok";
    out.include_len = include_len;
    out.exclude_len = exclude_len;
    out.water_left = water_units;
    out.water_buffer_bonus_crop = water_buffer_bonus_crop;
    out.bonus_crop_location = bonus_crop_location;
    return out;
}
//==================================Determine Crops to Grow Function ==================================
//=====================================================================================================
typedef struct {
    int location_id;
    int crop_id;
    char old_status;     // 'N' for route-only entries
    char new_status;     // 'P' default, or 'W'/'H' if overwritten by include list
    int new_crop_id;     // chosen cropID to plant (or 0 if none)
    int growth_time;     // growthTime corresponding to old_crop_id
    int latest_time;
} FinalRouteTask;
typedef struct {
    int ok;
    const char *msg;
    int out_len;
} FinalRouteResult;
static FinalRouteResult fr_fail(const char *msg) {
    FinalRouteResult r; r.ok = 0; r.msg = msg; r.out_len = 0; return r;
}
static int fr2_contains_int(const int *arr, int len, int v) {
    if (!arr || len <= 0) return 0;
    for (int i = 0; i < len; i++) if (arr[i] == v) return 1;
    return 0;
}
static int fr2_find_crop_index(const CropList *crops, int crop_count, int crop_id) {
    for (int i = 0; i < crop_count; i++) if (crops[i].cropID == crop_id) return i;
    return -1;
}
static int fr2_find_task_index_by_location(const TaskList *tasks, int task_count, int loc) {
    for (int i = 0; i < task_count; i++) if (tasks[i].location_id == loc) return i;
    return -1;
}
// uses ROUTE position (pos in route_ids), not filtered list
static int fr2_available_time_from_route_pos(int pos, int route_len) {
    int before_stops = pos;
    int after_stops  = (route_len - 1 - pos);
    int before_time = before_stops * 8 + 1;
    int after_time  = after_stops  * 8 + 1;
    return (before_time < after_time) ? before_time : after_time;
}
static double fr2_decayed_points(int base_points, int effective_times_already) {
    // first time => effective_times_already == 0 => multiplier 1.0
    return (double)base_points * pow(0.75, (double)effective_times_already);
}
/*
Priority after bonus:
  Tier 0: effectiveTimes == 0
  Tier 1: effectiveTimes >= 1
Within best tier that fits available_time:
  maximize decayed points (basePoints * 0.75^effectiveTimes)
  tie-break: smaller growthTime, then smaller effectiveTimes, then smaller cropID
*/
static int fr2_choose_best_crop(
    const CropList *crops, int crop_count,
    const int *selected_count_local,  // per crop index
    int available_time,
    int *out_growth_time
){
    int best_crop_id = 0;
    int best_growth  = 0;
    double best_score = -1.0;
    int best_tier = 999;
    int best_eff  = 0;
    for (int i = 0; i < crop_count; i++) {
        int gt = crops[i].growthTime;
        if (gt > available_time) continue;
        int eff = crops[i].numTimesCropPlanted + selected_count_local[i];
        int tier = (eff == 0) ? 0 : 1;
        double score = fr2_decayed_points(crops[i].numPointNext, eff);
        if (tier < best_tier) {
            best_tier = tier;
            best_score = score;
            best_crop_id = crops[i].cropID;
            best_growth  = gt;
            best_eff     = eff;
        } else if (tier == best_tier) {
            if (score > best_score) {
                best_score = score;
                best_crop_id = crops[i].cropID;
                best_growth  = gt;
                best_eff     = eff;
            } else if (score == best_score && best_score >= 0.0) {
                if (gt < best_growth) {
                    best_crop_id = crops[i].cropID;
                    best_growth  = gt;
                    best_eff     = eff;
                } else if (gt == best_growth) {
                    if (eff < best_eff) {
                        best_crop_id = crops[i].cropID;
                        best_growth  = gt;
                        best_eff     = eff;
                    } else if (eff == best_eff) {
                        if (crops[i].cropID < best_crop_id) {
                            best_crop_id = crops[i].cropID;
                            best_growth  = gt;
                            best_eff     = eff;
                        }
                    }
                }
            }
        }
    }
    if (out_growth_time) *out_growth_time = (best_crop_id == 0) ? 0 : best_growth;
    return best_crop_id;
}
static char fr2_transform_status(char old_status) {
    // N->P, P->W, W->H
    if (old_status == 'N') return 'P';
    if (old_status == 'P') return 'W';
    if (old_status == 'W') return 'H';
    // if weird input, treat like empty
    return 'P';
}
static int fr2_route_has_crop_id(const FinalRouteTask *out_tasks, int out_len, int crop_id) {
    if (!out_tasks || out_len <= 0) return 0;
    for (int i = 0; i < out_len; i++) {
        if (out_tasks[i].crop_id == crop_id) return 1;   // checks crop_id column (OLD crop)
    }
    return 0;
}
FinalRouteResult build_best_route_task_list(
    const TaskList *tasks, int task_count,
    const int *route_ids, int route_len,
    const CropList *crops, int crop_count,
    const int *exclude_ids, int exclude_len,
    const int *exclude_plantation_ids, int exclude_plantation_len,
    int current_bonus_crop_id,
    FinalRouteTask *out_tasks, int out_capacity
){
    if (!out_tasks || out_capacity <= 0) return fr_fail("out buffer invalid");
    if (!route_ids || route_len <= 0) return fr_fail("route invalid");
    if (!crops || crop_count <= 0) return fr_fail("crop list invalid");
    if (!tasks || task_count < 0) return fr_fail("task list invalid");
    // We need route positions for time calculation (pos in original route list).
    // Store them alongside out_tasks indices.
    int out_route_pos[256];
    if (out_capacity > 256) return fr_fail("out_capacity too large for fixed route_pos buffer");
    // ---------------- Step A: Build final list from ROUTE ORDER excluding exclude_ids ----------------
    int out_len = 0;
    for (int rp = 0; rp < route_len; rp++) {
        int loc = route_ids[rp];
        if (fr2_contains_int(exclude_ids, exclude_len, loc)) continue;
        if (out_len >= out_capacity) return fr_fail("out_capacity too small");
        out_tasks[out_len].location_id = loc;
        out_tasks[out_len].crop_id = 0;
        out_tasks[out_len].old_status = 'N';
        out_tasks[out_len].new_status = 'P';
        out_tasks[out_len].new_crop_id = 0;
        out_tasks[out_len].growth_time = 0;
        out_tasks[out_len].latest_time = 0;
        out_route_pos[out_len] = rp; // IMPORTANT: time is based on route list
        out_len++;
    }
    // ---------------- Step B: Update from TASK LIST (not include list) ----------------
    for (int i = 0; i < out_len; i++) {
        int loc = out_tasks[i].location_id;
        int ti = fr2_find_task_index_by_location(tasks, task_count, loc);
        if (ti >= 0) {
            out_tasks[i].crop_id = tasks[ti].crop_id;
            out_tasks[i].old_status = tasks[ti].status;     // N / P / W
            out_tasks[i].latest_time = tasks[ti].latest_time;
            // growth time initially from OLD crop_id (task list crop)
            int ci_old = fr2_find_crop_index(crops, crop_count, out_tasks[i].crop_id);
            out_tasks[i].growth_time = (ci_old >= 0) ? crops[ci_old].growthTime : 0;
            // new status transform rule
            out_tasks[i].new_status = fr2_transform_status(out_tasks[i].old_status);
            // new_crop_id starts at 0 by design
            out_tasks[i].new_crop_id = 0;
        } else {
            // not in task list => treat as empty
            out_tasks[i].crop_id = 0;
            out_tasks[i].old_status = 'N';
            out_tasks[i].new_status = 'P';
            out_tasks[i].new_crop_id = 0;
            out_tasks[i].growth_time = 0;
            out_tasks[i].latest_time = 0;
        }
    }
    // Track local selections so “effective times planted” changes each pick
    int selected_count_local[128];
    if (crop_count > 128) return fr_fail("crop_count too large");
    for (int i = 0; i < crop_count; i++) selected_count_local[i] = 0;
    // Eligible planting spots:
    // new_status == 'P'
    // OR (new_status == 'H' AND loc NOT in exclude_plantation_ids)
    // ---------------- Phase 1: Bonus crop MUST be planted once ----------------
    if (current_bonus_crop_id != -1 && !fr2_route_has_crop_id(out_tasks, out_len, current_bonus_crop_id)) {
        int bonus_ci = fr2_find_crop_index(crops, crop_count, current_bonus_crop_id);
        int bonus_growth = (bonus_ci >= 0) ? crops[bonus_ci].growthTime : -1;
        int best_fit_idx = -1;
        int best_slack = 0;
        int any_eligible_idx = -1;
        for (int i = 0; i < out_len; i++) {
            char ns = out_tasks[i].new_status;
            int eligible =
                (ns == 'P') ||
                (ns == 'H' && !fr2_contains_int(exclude_plantation_ids, exclude_plantation_len,
                                            out_tasks[i].location_id));
            if (!eligible) continue;
            if (any_eligible_idx < 0) any_eligible_idx = i;
            // If we know growth time, try to fit it “best”
            if (bonus_growth >= 0) {
                int avail = fr2_available_time_from_route_pos(out_route_pos[i], route_len);
                if (avail < bonus_growth) continue;
                int slack = avail - bonus_growth;
                if (best_fit_idx < 0 || slack < best_slack) {
                    best_fit_idx = i;
                    best_slack = slack;
                }
            }
        }
        int chosen = (best_fit_idx >= 0) ? best_fit_idx : any_eligible_idx;
        if (chosen >= 0) {
            out_tasks[chosen].new_crop_id = current_bonus_crop_id;
            // increment local count if it’s a known crop id
            if (bonus_ci >= 0) selected_count_local[bonus_ci] += 1;
        }
        // If there are zero eligible positions, we can’t plant; but we do NOT fail.
    }
    // ---------------- Phase 2: Fill remaining eligible spots ----------------
    for (int i = 0; i < out_len; i++) {
        char ns = out_tasks[i].new_status;
        int eligible =
                (ns == 'P') ||
                (ns == 'H' && !fr2_contains_int(exclude_plantation_ids, exclude_plantation_len,
                                            out_tasks[i].location_id));
        if (!eligible) continue;
        if (out_tasks[i].new_crop_id != 0) continue; // already used by bonus
        int avail = fr2_available_time_from_route_pos(out_route_pos[i], route_len);
        int chosen_growth = 0;
        int chosen_id = fr2_choose_best_crop(
            crops, crop_count,
            selected_count_local,
            avail,
            &chosen_growth
        );
        out_tasks[i].new_crop_id = chosen_id;
        if (chosen_id != 0) {
            int ci = fr2_find_crop_index(crops, crop_count, chosen_id);
            if (ci >= 0) selected_count_local[ci] += 1; // IMPORTANT: changes future effective times
        }
    }
    FinalRouteResult ok;
    ok.ok = 1;
    ok.msg = "ok";
    ok.out_len = out_len;
    return ok;
}
//===============================Refill Watering and Move Back to Original Position===============================
//================================================================================================================
static void Get_Water_Refill(int currentLocationID, bool moveToLocation, Location locations[]){
    /**if (game.OpponentGoingToWatering() || game.OpponentAtWatering()){ 
        game.MoveToHome(); // moving to home because by then opponent will be done, and we will get water quickly
    }**/
    //int waterZone = 7;
    if (game.OpponentAtWatering()){
        game.MoveToVoid(0,0.2,0);
    }
    for (int i = 0; i < 5; i++){ // see if it should be 5 or 10
        if (game.OpponentAtWatering()){
            debugPrintf("Waiting for Opponent to leave Watering Zone");
            game.SetWait(1);
        }
    }
    //bool moved5 = game.MoveTo(locations[waterZone-1].x, locations[waterZone-1].y, game.GetRobotPositionZ());
    game.MoveWatering();
    game.FillWateringCan();
    if (moveToLocation == true){
        //bool moved7 = game.MoveTo(locations[currentLocationID-1].x,locations[currentLocationID-1].y,game.GetRobotPositionZ());
        game.MovePlot(currentLocationID);
    }
}
//=========================================Removed Failed Crop Function===========================================
//================================================================================================================
static int remove_failed_crop(int location_id, CropList crops[]){
    if (location_id < 1 || location_id > 6 || crops == NULL) {
        return 0;
    }
    // Physically clear failed crop with shovel and return to the plot.
    game.MoveToHome();
    game.GrabShovel();
    game.MovePlot(location_id);
    game.RemoveCrop(location_id);
    game.MoveToHome();
    game.DropShovel();
    game.MovePlot(location_id);
    // Pick a replant crop only if there is enough match time to realistically score it.
    int time_left = 240 - game.GetTime();
    int harvest_buffer = 12;
    int best_crop_id = 0;
    int best_growth = 0;
    int best_score = -1;
    for (int i = 0; i < 6; i++) {
        int gt = crops[i].growthTime;
        int points = crops[i].numPointNext;
        if (gt <= 0 || points <= 0) continue;
        if ((gt + harvest_buffer) > time_left) continue;
        // Favor high point value while still preferring faster growers.
        int score = (points * 100) / (gt + 2);
        if (score > best_score || (score == best_score && gt < best_growth)) {
            best_score = score;
            best_crop_id = crops[i].cropID;
            best_growth = gt;
        }
    }
    return best_crop_id;
}
void init(){
    //This function is called once when your code is first loaded.
    //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.
    //====================================Initialize Variables=======================================
    //===============================================================================================
    int robotID = game.GetRobotID();
    Location locations[] = {
        { 1, -0.35, 0.60, 0.20 },
        { 2,  0.35, 0.60, 0.20 },
        { 3, -0.15, 1.00, 0.30 },
        { 4, -0.35, 1.40, 0.25 },
        { 5,  0.35, 1.40, 0.25 },
        { 6,  0.15, 1.00, 0.30 },
        { 7,  0.00, 0.00,  0.00 },
        { 8,  0.00, 0.00, 0.25 },
        { 9,  0.00, 1.50,  0.00 }
    };
    CropList crops[] = {
        {1, 6, 0, 6},
        {2, 8, 0, 7},
        {3, 5, 0, 5},
        {4, 12, 0, 11},
        {5, 3, 0, 3},
        {6, 9, 0, 8}
    };
    TaskList tasks[] = {
        {1, 0, 'N', 0},
        {2, 0, 'N', 0},
        {3, 0, 'N', 0},
        {4, 0, 'N', 0},
        {5, 0, 'N', 0},
        {6, 0, 'N', 0}
    };
    int include_crop_list[] = {1,2,3,4,5,6}; // this crop list will be used in the must include exclude function to consider all crops for harvesting once the bonus assignment is complete
    int exclude_route_location_list[] = {7,8,9}; // This will be used for the final route task list, when making final route task list, should not include these locations as there is no task for plantation and harvesting in these locations.
    int exclude_plantation_ids[] = {-1,-1,-1}; // exclude the far away plantation when bonus assignments are done
    int locationNearAstronaut[] = {4,5,6}; // stores locations that are near the astronaut
    double timeLeft = 240; // Will store time left
    //Zone Definitions
    int homeZone = 8;
    int waterZone = 7;
    int astroZone = 9;
    // Variables storing route details
    int startLocation = homeZone;
    int endLocation = astroZone;
    int num_stops;
    int currentLocation = homeZone;
    //Stores bonus crop data
    int currentBonusCropID = -1; // this will contain the current bonus crop that needs to be planted. Once harvested, it will be set back to -1.
    int bonusCrop1 = -1;
    int bonusCrop2 = -1;
    int bonusCrop3 = -1;// this crop list will be used in the must include exclude function to consider the given crops for harvesting until the bonus assignment is not complete
    int currentBonusCropLocation = -1;
    int bonusCropList[] = {bonusCrop1, bonusCrop2, bonusCrop3};
    bool bonusCompletion = false;
    bool bonusCropHarvested = false;
    int bonusCropCount = 0; // this will have the count for bonus crops received from astronaut so far
    int harvestRouteList[] = {1,3,4,5,6,2};
    //Stores water data
    int waterUnits = 0;
    int bufferWaterUnits = 0; // this buffer is maintained in case the opponent is at water location or astronaut location, and also to make sure astrobee isn't running out of water at last moment
    int availableWaterUnits; // this will exclude the buffer water units that will be available for route calculations and for watering options
    //Stores exclude location data
    int excludeLocation1 = 0;
    int excludeLocation2 = 0;
    int excludeLocation3 = 0;
    int numExclude = 0;
    int excludeArraySize = 0;
    int totalWaitTime = 0;
    //Flips location coordinates if controlled robot is different
    if (game.GetRobotID() == 1) {
        for (int i = 0; i < 9; i++) {
            locations[i].z *= -1;
        }
    }
    //We assume the game starts from the home zone. To avoid error, we will move robot to home zone
    game.MoveToHome();
    startLocation = homeZone;
    timeLeft = timeLeft - game.GetTime();
    bool waterFilled = false;
    //=======================================Main Code Begins======================================
    //=============================================================================================
    while (timeLeft > 5){
        waterUnits = game.GetWaterUnits();
        if (waterUnits > 1) {
            availableWaterUnits = waterUnits - bufferWaterUnits;
            waterFilled = true;
        } else {
            waterFilled = false;
        }
        if (waterFilled == false) { // in this code, it will consider if by any chance the opponent is at watering zone, but we are also low on water.
            Get_Water_Refill(startLocation, false, locations);
            waterFilled = true; 
            startLocation = waterZone;
            if (bonusCompletion == false){
                endLocation = astroZone;
            }
            waterUnits = game.GetWaterUnits();
            availableWaterUnits = waterUnits - bufferWaterUnits;
        }
        //===============================Build Exclusion Array for Input=================================
        //===============================================================================================
        numExclude = 0;
        if ((startLocation != homeZone) && (endLocation != homeZone)){
            excludeLocation1 = homeZone;
            numExclude += 1;
        } else {
            excludeLocation1 = 0;
        }
        if ((startLocation != waterZone) && (endLocation != waterZone)){
            excludeLocation2 = waterZone;
            numExclude += 1;
        } else {
            excludeLocation2 = 0;
        }
        if ((startLocation != astroZone) && (endLocation != astroZone)) {
            excludeLocation3 = astroZone;
            numExclude += 1;
        } else {
            excludeLocation3 = 0;
        }
        if (numExclude == 0){
            excludeArraySize = 1;
        } else {
            excludeArraySize = numExclude;
        }
        int exclude_in[excludeArraySize];
        int exclude_in_len = 0;
        if (numExclude > 0){
            int counter = 0;
            if (excludeLocation1 != 0){
                exclude_in[counter] = excludeLocation1;
                counter += 1;
            }
            if (excludeLocation2 != 0){
                exclude_in[counter] = excludeLocation2;
                counter += 1;
            }
            if (excludeLocation3 != 0){
                exclude_in[counter] = excludeLocation3;
                counter += 1;
            }
            exclude_in_len = numExclude;
        }
        //==========================Build Must Include and Must Exclude Location List====================
        //===============================================================================================
        int task_count = sizeof(tasks)/sizeof(tasks[0]);
        int must_include[6]; // contains the locations that must be included when finding best route
        int must_exclude[15]; // contains the locations that will be excluded when finding best route
        IncludeTask include_tasks[6]; // contains the tasks that have to be done at the must_include locs
        int cropListSize = 0;
        if (bonusCompletion == true) {
            cropListSize = 6;
        } else {
            cropListSize = 3;
        }
        int crop_list[cropListSize];
        if (bonusCompletion == true) {
            memcpy(crop_list, include_crop_list, sizeof(include_crop_list));
        } else {
            memcpy(crop_list, bonusCropList, sizeof(bonusCropList));
        }
        int bonus_crop_len = sizeof(bonusCropList)/sizeof(bonusCropList[0]);
        int exclude_plantation_len = sizeof(exclude_plantation_ids)/sizeof(exclude_plantation_ids[0]);
        int end_is_astro_zone = 0;
        if (endLocation == astroZone){
            end_is_astro_zone = 1;
        }
        timeLeft = 240-game.GetTime();
        debugPrintf("Time left before function call: %f
", game.GetTime());
        if (timeLeft < 50){
            memcpy(exclude_plantation_ids, locationNearAstronaut, sizeof(locationNearAstronaut));
        }
        MustListResult r = get_must_incl_excl_loc_lists(
            tasks, task_count,
            availableWaterUnits,
            currentBonusCropID,
            exclude_in, exclude_in_len,
            crop_list, cropListSize,
            bonusCompletion,
            exclude_plantation_ids, exclude_plantation_len,
            end_is_astro_zone,
            must_include, 6,
            must_exclude, 15,
            include_tasks, 6
        );
        if (!r.ok) {
            debugPrintf("ERR: %s
", r.msg);
            return;
        }
        if (r.bonus_crop_location != -1){
            currentBonusCropLocation = r.bonus_crop_location;
        }
        int must_include_compact[r.include_len];
        int must_exclude_compact[r.exclude_len];
        IncludeTask include_tasks_compact[r.include_len];
        for (int i = 0; i < r.include_len; i++){
            must_include_compact[i] = must_include[i];
        }
        for (int i = 0; i < r.exclude_len; i++){
            must_exclude_compact[i] = must_exclude[i];
        }
        for (int i = 0; i < r.include_len; i++){
            include_tasks_compact[i] = (IncludeTask){
                include_tasks[i].location_id, 
                include_tasks[i].crop_id, 
                include_tasks[i].old_status, 
                include_tasks[i].new_status, 
                include_tasks[i].latest_time
            };
        }
        int waterLeft_plot = 0;
        int excludePlotCount = 0;
        int plot_left = 0;
        for (int i = 0; i < r.exclude_len; i++){
            if (must_exclude_compact[i] == 1){
                excludePlotCount += 1;
            }
            if (must_exclude_compact[i] == 2){
                excludePlotCount += 1;
            }
            if (must_exclude_compact[i] == 3){
                excludePlotCount += 1;
            }
            if (must_exclude_compact[i] == 4){
                excludePlotCount += 1;
            }
            if (must_exclude_compact[i] == 5){
                excludePlotCount += 1;
            }
            if (must_exclude_compact[i] == 6){
                excludePlotCount += 1;
            }
        }
        plot_left = 6 - (r.include_len + excludePlotCount);
        if (endLocation == astroZone){
            waterLeft_plot = (r.water_left + r.water_buffer_bonus_crop) / 2;
        } else {
            waterLeft_plot = (r.water_left + r.water_buffer_bonus_crop);
        }
        if (plot_left < waterLeft_plot){
            num_stops = r.include_len + plot_left;
        } else {
            num_stops = r.include_len + waterLeft_plot;
        }
        //=====================================Find Best Route======================================
        //==========================================================================================
        int n_locs = sizeof(locations) / sizeof(locations[0]);
        int must_include_len = sizeof(must_include_compact) / sizeof(must_include_compact[0]);
        int must_exclude_len = sizeof(must_exclude_compact) / sizeof(must_exclude_compact[0]);
        int route_ids[8];
        double leg_dist[8];
        RouteResult x = find_best_route(
            locations, n_locs,
            startLocation,
            endLocation,
            num_stops,        
            must_include_compact, must_include_len,
            must_exclude_compact, must_exclude_len,
            route_ids, 8,
            leg_dist, 8
        );
        double total = x.total_distance;
        int len = x.route_len;
        //==========================Identifying the Crops to Grow on the Route=========================
        //=============================================================================================
        FinalRouteTask final_tasks[15];  // big enough: include_len + route_len
        int final_cap = 15;
        int exclude_len = sizeof(exclude_route_location_list) / sizeof(exclude_route_location_list[0]);
        //int exclude_plantation_len = sizeof(exclude_plantation_ids) / sizeof(exclude_plantation_ids[0]);
        int crop_count = sizeof(crops) / sizeof(crops[0]);
        int bonusCropID = -1;
        if (r.water_buffer_bonus_crop != 0){
            bonusCropID = currentBonusCropID;
        }
        int tasks_len = sizeof(tasks) / sizeof(tasks[0]);
        FinalRouteResult fr = build_best_route_task_list(
            tasks, tasks_len,
            route_ids, x.route_len,
            crops, crop_count,
            exclude_route_location_list, exclude_len,
            exclude_plantation_ids, exclude_plantation_len,
            bonusCropID,
            final_tasks, final_cap
        );
        if (!fr.ok) {
            debugPrintf("ERR: %s
", fr.msg);
            return;
        }
        int final_len = fr.out_len;
        FinalRouteTask final_tasks_compact[final_len];
        for (int i = 0; i < final_len; i++){
            final_tasks_compact[i] = (FinalRouteTask){
                final_tasks[i].location_id,
                final_tasks[i].crop_id,
                final_tasks[i].old_status,
                final_tasks[i].new_status,
                final_tasks[i].new_crop_id,
                final_tasks[i].growth_time,
                final_tasks[i].latest_time
            };
        }
        //=====================================Traveling the Route=====================================
        //=============================================================================================
        for (int i = 0; i < final_len; i++){
            timeLeft = 240-game.GetTime();
            if (timeLeft < 5){
                break;
            }
            int location_id = final_tasks[i].location_id;
            int crop_id = final_tasks[i].crop_id;
            int old_status = final_tasks[i].old_status;
            int new_status = final_tasks[i].new_status;
            int new_crop_id = final_tasks[i].new_crop_id;
            int growth_time = final_tasks[i].growth_time;
            int latest_time = final_tasks[i].latest_time;
            int lastActionTime = 0;
            int readyTime = 0;
            timeLeft = 240-game.GetTime();
            if ((new_status == 'P') && (timeLeft < 15)){
                continue;
            }
            double gradient = 0;
            gradient = (pow(locations[location_id-1].x-game.GetRobotPositionX(), 2))+(pow(locations[location_id-1].y-game.GetRobotPositionY(),2));
            gradient = pow(gradient, 0.5);
            gradient = gradient / (fabs((locations[location_id-1].z-game.GetRobotPositionZ()))+0.000000000001);
            if (gradient < 1.5){
                double move1X = (locations[location_id-1].x + game.GetRobotPositionX())/3;
                //double move1X = locations[location_id-1].x;
                double move1Y = locations[location_id-1].y;
                double move1Z = (locations[location_id-1].z + game.GetRobotPositionZ())/3;
                game.MoveToVoid(move1X, move1Y, move1Z);
                debugPrintf("x %f, y %f, z %f
", game.GetRobotPositionX(), game.GetRobotPositionY(), game.GetRobotPositionZ());
                bool moved20 = game.MoveTo(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                if (moved20 == false){
                    game.MovePlot(location_id);
                }
                //game.MoveToVoid(move1X, move1Y, move1Z);
            } else if (gradient < 1.75) {
                //game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, game.GetRobotPositionZ());
                //game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                //double move1X = (locations[location_id-1].x + game.GetRobotPositionX())/2;
                double move1X = (locations[location_id-1].x);
                //double move1X = locations[location_id-1].x;
                double move1Y = (locations[location_id-1].y - 0.2);
                double move1Z = (locations[location_id-1].z + game.GetRobotPositionZ())/2;
                game.MoveToVoid(move1X, move1Y, move1Z);
                debugPrintf("x %f, y %f, z %f
", game.GetRobotPositionX(), game.GetRobotPositionY(), game.GetRobotPositionZ());
                bool moved20 = game.MoveTo(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                if (moved20 == false){
                    game.MovePlot(location_id);
                }
                //game.MoveToVoid(move1X, move1Y, move1Z);
            } else if ((game.GetRobotPositionX() != locations[location_id-1].x) && (game.GetRobotPositionY() == locations[location_id-1].y) && (game.GetRobotPositionZ() == locations[location_id-1].z)){
                game.MoveToVoid(locations[location_id-1].x, game.GetRobotPositionY() - 0.2, locations[location_id-1].z);
                bool moved21 = game.MoveTo(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                if (moved21 == false){
                    game.MovePlot(location_id);
                }
            } else {
                game.MovePlot(location_id);
                /**if ((game.GetRobotPositionX() != locations[location_id-1].x) || (game.GetRobotPositionY() != locations[location_id-1].y) || (game.GetRobotPositionZ() != locations[location_id-1].z)){
                    game.MovePlot(location_id);
                }**/
                /**bool moved25 = game.MoveTo(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                if (moved25 == false){
                    game.MovePlot(location_id);
                }**/
                //game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
            }
            //game.MovePlot(location_id);
            currentLocation = location_id;
            if (new_status == 'P'){
                if (new_crop_id != 0){
                    game.PlantCrop(location_id, new_crop_id);
                    if (game.GetWaterUnits() == 0){
                        Get_Water_Refill(currentLocation, true, locations);
                    }
                    game.WaterCrop(location_id);
                    lastActionTime = game.GetTime();
                    if (new_crop_id == currentBonusCropID){
                        if (r.water_buffer_bonus_crop != 0){
                            currentBonusCropLocation = location_id;
                        }
                    }
                    crops[new_crop_id - 1].numTimesCropPlanted += 1;
                    crops[new_crop_id - 1].numPointNext *= 0.75;
                    tasks[location_id-1].crop_id = new_crop_id;
                    tasks[location_id-1].status = 'P';
                    tasks[location_id-1].latest_time = lastActionTime;   
                }
            } else if (new_status == 'W'){
                int cropTimeOut = game.GetTime() - latest_time;
                if ((cropTimeOut) > 60){
                    debugPrintf("Crop Has Failed");
                    new_crop_id = remove_failed_crop(location_id, crops);
                    new_crop_id = crop_id;
                    if (new_crop_id == 0){
                        tasks[location_id-1].crop_id = 0;
                        tasks[location_id-1].status = 'N';
                        tasks[location_id-1].latest_time = 0;
                    } else {
                        game.PlantCrop(location_id, new_crop_id);
                        if (game.GetWaterUnits() == 0){
                            Get_Water_Refill(currentLocation, true, locations);
                        }
                        game.WaterCrop(location_id);
                        lastActionTime = game.GetTime();
                        tasks[location_id-1].crop_id = new_crop_id;
                        tasks[location_id-1].status = 'P';
                        tasks[location_id-1].latest_time = lastActionTime;
                    }
                    continue;
                }
                if ((game.GetTime() - latest_time) < growth_time){
                    int waiting_time = growth_time - (game.GetTime() - latest_time);
                    totalWaitTime += waiting_time;
                    debugPrintf("Waiting for Crop to be ready for watering");
                    game.SetWait(waiting_time);
                }
                /**for (int i = 0; i < 12; i++){
                    if ((game.GetTime() - latest_time) < growth_time){
                        debugPrintf("Waiting for Crop to be ready for watering");
                        game.SetWait(1);
                    }   
                }**/
                if (game.GetWaterUnits() == 0){
                    Get_Water_Refill(currentLocation, true, locations);
                }
                game.WaterCrop(location_id);
                lastActionTime = game.GetTime();
                tasks[location_id-1].status = 'W';
                tasks[location_id-1].latest_time = lastActionTime;
            } else {
                if ((game.GetTime() - latest_time) < growth_time){
                    int waiting_time = growth_time - (game.GetTime() - latest_time);
                    totalWaitTime += waiting_time;
                    debugPrintf("Waiting for Crop to be ready for harvesting");
                    game.SetWait(waiting_time);
                }
                /**for (int i = 0; i < 12; i++){
                    if ((game.GetTime() - latest_time) < growth_time){
                        debugPrintf("Waiting for Crop to be ready for harvesting");
                        game.SetWait(1);
                    }   
                }**/
                game.HarvestCrop(location_id);
                if (bonusCropCount == 1){
                    if (crop_id == bonusCrop1){
                        bonusCropHarvested = true;
                        currentBonusCropID = -1;
                        currentBonusCropLocation = -1;
                    }
                }
                if (bonusCropCount == 2){
                    if (crop_id == bonusCrop2){
                        bonusCropHarvested = true;
                        currentBonusCropID = -1;
                        currentBonusCropLocation = -1;
                    }
                }
                if (bonusCropCount == 3){
                    if (crop_id == bonusCrop3){
                        bonusCropHarvested = true;
                        currentBonusCropID = -1;
                        currentBonusCropLocation = -1;
                    }
                }
                if (new_crop_id == 0){
                    tasks[location_id-1].crop_id = 0;
                    tasks[location_id-1].status = 'N';
                    tasks[location_id-1].latest_time = 0;   
                } else {
                    timeLeft = 240-game.GetTime();
                    if (timeLeft < 15){
                        tasks[location_id-1].crop_id = 0;
                        tasks[location_id-1].status = 'N';
                        tasks[location_id-1].latest_time = 0;
                        continue;
                    }
                    game.PlantCrop(location_id, new_crop_id);
                    if (game.GetWaterUnits() == 0){
                        Get_Water_Refill(currentLocation, true, locations);
                    }
                    game.WaterCrop(location_id);
                    lastActionTime = game.GetTime();
                    crops[new_crop_id - 1].numTimesCropPlanted += 1;
                    crops[new_crop_id - 1].numPointNext *= 0.75;
                    tasks[location_id-1].crop_id = new_crop_id;
                    tasks[location_id-1].status = 'P';
                    tasks[location_id-1].latest_time = lastActionTime;
                }
            }
        }
        timeLeft = 240-game.GetTime();
        if (timeLeft < 30){
            for (int i = 0; i < 6; i++){
                timeLeft = 240-game.GetTime();
                if (timeLeft < 5){
                    break;
                }
                int cropID = tasks[i].crop_id;
                if ((tasks[i].status == 'W') && (((game.GetTime() - tasks[i].latest_time) + (3)) >= crops[cropID-1].growthTime)){
                //if ((tasks[i].status == 'W') && (((game.GetTime() - tasks[i].latest_time)) >= crops[cropID-1].growthTime)){
                    game.MovePlot(harvestRouteList[i]);
                    game.HarvestCrop(harvestRouteList[i]);
                    tasks[i].status = 'N';
                    tasks[i].crop_id = 0;
                    tasks[i].latest_time = 0;
                }
            }   
        }
        if (endLocation == astroZone){
            if ((bonusCropHarvested == false) && (bonusCropCount != 0)){
                int idx = currentBonusCropLocation-1;
                int crop_idx = tasks[idx].crop_id - 1;
                if (currentBonusCropLocation != -1){
                    if ((tasks[idx].crop_id == currentBonusCropID) && (tasks[idx].status == 'W')){
                        game.MoveToVoid(locations[tasks[idx].location_id-1].x, locations[tasks[idx].location_id-1].y, game.GetRobotPositionZ());
                        game.MoveToVoid(locations[tasks[idx].location_id-1].x, locations[tasks[idx].location_id-1].y, locations[tasks[idx].location_id-1].z);
                        //game.MovePlot(tasks[idx].location_id);
                        if ((game.GetTime() - tasks[idx].latest_time) < crops[crop_idx].growthTime){
                            int waiting_time = crops[crop_idx].growthTime - (game.GetTime() - tasks[idx].latest_time);
                            totalWaitTime += waiting_time;
                            debugPrintf("Waiting for bonus crop to be ready for harvesting");
                            game.SetWait(waiting_time);
                        }
                        /**for (int i = 0; i < 12; i++){
                            if ((game.GetTime() - tasks[idx].latest_time) < crops[crop_idx].growthTime){
                                debugPrintf("Waiting for bonus crop to become ready to harvest");
                            }   
                        }**/
                        game.HarvestCrop(tasks[idx].location_id);
                        tasks[idx].crop_id = 0;
                        tasks[idx].status = 'N';
                        tasks[idx].latest_time = 0;
                        bonusCropHarvested = true;
                        currentBonusCropID = -1;
                        currentBonusCropLocation = -1;
                    }
                }
            }
            //if opponent is at astronaut, we will try to finish the work in the nearby locations
            if (game.OpponentAtAstronaut()){
                if (currentLocation == 4){
                    int location_id = 5;
                    if (tasks[location_id-1].status == 'P'){
                        game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, game.GetRobotPositionZ());
                        game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                        //game.MovePlot(location_id);
                        game.WaterCrop(location_id);
                        tasks[location_id-1].status = 'W';
                        tasks[location_id-1].latest_time = game.GetTime();
                    }
                }
                if (currentLocation == 5){
                    int location_id = 4;
                    if (tasks[location_id-1].status == 'P'){
                        game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, game.GetRobotPositionZ());
                        game.MoveToVoid(locations[location_id-1].x, locations[location_id-1].y, locations[location_id-1].z);
                        //game.MovePlot(location_id);
                        game.WaterCrop(location_id);
                        tasks[location_id-1].status = 'W';
                        tasks[location_id-1].latest_time = game.GetTime();
                    }
                }
            }
            for (int i = 0; i < 5; i++){
                if (game.OpponentAtAstronaut()){
                    debugPrintf("Waiting for Opponent to leave Astronaut");
                    game.SetWait(1);
                }
            }
            debugPrintf("BEFORE ASTRONAUT SCORE: %f
", game.GetScore());
            //bool moved8 = game.MoveTo(locations[astroZone-1].x, locations[astroZone-1].y, game.GetRobotPositionZ());
            game.MoveAstronaut();
            int astroBonusCrop;
            astroBonusCrop = game.GetBonusCrop();
            debugPrintf("AFTER ASTRONAUT SCORE: %f
", game.GetScore());
            if (astroBonusCrop == 0){
                astroBonusCrop = -1;
            }
            debugPrintf("ASTROBONUSCROP: %d
", astroBonusCrop);
            debugPrintf("CURRENTBONUSINDEX: %d
", game.GetCurrentBonusIndex());
            if ((game.GetCurrentBonusIndex() >= 1) && (astroBonusCrop == -1)){
                bonusCompletion = true;
            }
            if ((astroBonusCrop == bonusCrop1) || (astroBonusCrop == bonusCrop2) || (astroBonusCrop == bonusCrop3)){
                debugPrintf("Next bonus mission not received");
            } else {
                bonusCropHarvested = false; // resetting the variable
                currentBonusCropID = astroBonusCrop;
                bonusCropCount += 1;
                if (bonusCropCount == 1) {
                    bonusCrop1 = astroBonusCrop;
                    bonusCropList[0] = bonusCrop1;
                }
                if (bonusCropCount == 2){
                    bonusCrop2 = astroBonusCrop;
                    bonusCropList[1] = bonusCrop2;
                }
                if (bonusCropCount == 3){
                    bonusCrop3 = astroBonusCrop;
                    bonusCropList[2] = bonusCrop3;
                    bonusCompletion = true;
                    debugPrintf("BONUS COMPLETION TIME: %f
", game.GetTime());
                    debugPrintf("=== CROPS ===
");
                    int crop_count3 = sizeof(crops) / sizeof(crops[0]);
                    for (int i = 0; i < crop_count3; i++) {
                        debugPrintf(
                            "Crop[%d]: cropID=%d, growthTime=%d, numTimesPlanted=%d, numPointNext=%d
",
                            i,
                            crops[i].cropID,
                            crops[i].growthTime,
                            crops[i].numTimesCropPlanted,
                            crops[i].numPointNext
                        );
                    }
                }
            }
        }
        timeLeft = 240-game.GetTime();
        if ((endLocation == waterZone) && (timeLeft > 10)){
            Get_Water_Refill(currentLocation, false, locations);
        }
        if (endLocation == astroZone){
            startLocation = astroZone;
            endLocation = waterZone;
        } else {
            startLocation = waterZone;
            endLocation = astroZone;
            if ((bonusCompletion == true)){
                if (game.GetAstronautVisits() < 4){
                    endLocation = astroZone;
                } else {
                    endLocation = waterZone;
                }
            }
        }
        timeLeft = 240 - game.GetTime();
        debugPrintf("TIMELEFT: %f
", timeLeft);
    }
    debugPrintf("Final score: %f
", game.GetScore());
    int crop_count2 = sizeof(crops) / sizeof(crops[0]);
    debugPrintf("=== CROPS ===
");
    for (int i = 0; i < crop_count2; i++) {
        debugPrintf(
            "Crop[%d]: cropID=%d, growthTime=%d, numTimesPlanted=%d, numPointNext=%d
",
            i,
            crops[i].cropID,
            crops[i].growthTime,
            crops[i].numTimesCropPlanted,
            crops[i].numPointNext
        );
    }
    int task_count2 = sizeof(tasks) / sizeof(tasks[0]);
    debugPrintf("=== TASKS ===
");
    for (int i = 0; i < task_count2; i++) {
        debugPrintf(
            "Task[%d]: location_id=%d, crop_id=%d, status=%c, latest_time=%d
",
            i,
            tasks[i].location_id,
            tasks[i].crop_id,
            tasks[i].status,
            tasks[i].latest_time
        );
    }
    debugPrintf("Total wait time: %d
", totalWaitTime);
}
//End page main
4 Alliance 4 — Kühl-Quark-Cyber-AlexRunner Up

“Four teams that work together to plant crops in outer space.”

Cyber Synthesis Alexandria STEM School Quark Charm 1 Team Kuhlschrank 2026 HS
</> View Source Code
//Begin page main
#include <time.h>
#include <math.h>
time_t start, end;
time_t plotTime[6];
int bonus;
int waits[6];
int timesPlanted[6];
int ids[6];
int smallest;
int plotStatus[6];
int plotWait[6];
int plotDist[6];
int plotCrop[6];
bool isBlue;
typedef struct location {
    double x;
    double y;
    double z;
} location;
location plot[6];
void findSmallest() {
    int x = timesPlanted[0];
    int y = 0;
    for (int i = 1; i < 6; i++) {
        if (timesPlanted[i] < x) {
            x = timesPlanted[i];
            y = i;
        }
    }
    smallest = y;
}
void plantingCycle(int plot, int crop) {
    game.MovePlot(plot);
    game.PlantCrop(plot, crop);
    game.WaterCrop(plot);
    plotTime[plot - 1] = clock();
    plotStatus[plot - 1] = 1;
    plotWait[plot - 1] = waits[crop - 1];
    plotCrop[plot - 1] = crop;
    timesPlanted[crop - 1]++;
    // Find the crop with the least times planted
    findSmallest();
}
void wateringCycle(int totalPlots) {
    for (int i = 0; i < totalPlots;) {
        end = clock();
        for (int j = 0; j < totalPlots; j++) {
            if (difftime(end, plotTime[j]) >= plotWait[j] && plotStatus[j] == 1) {
                game.MovePlot(j + 1);
                game.WaterCrop(j + 1);
                plotTime[j] = clock();
                plotStatus[j] = 2;
                i++;
            } else if (j == totalPlots - 1) {
                game.SetWait(1);
            }
        }
    }
}
void harvestingCycle(int totalPlots) {
    for (int i = 0; i < totalPlots;) {
        end = clock();
        for (int j = 0; j < totalPlots; j++) {
            if (difftime(end, plotTime[j]) >= plotWait[j] && plotStatus[j] == 2) {
                game.MovePlot(j + 1);
                game.HarvestCrop(j + 1);
                plotTime[j] = clock();
                plotStatus[j] = 0;
                i++;
            }
        }
    }
}
void wateringCan() {
    for (int i = 0; i < 1;) {
        double x = game.GetRobotPositionX();
        double y = game.GetRobotPositionY();
        double z = game.GetRobotPositionZ();
        if (!game.OpponentAtWatering() && !game.OpponentGoingToWatering()) {
            game.MoveWatering();
            if (x == 0 && y == 0 && z == 0) {
                game.FillWateringCan();
                i++;
            } else {
                game.MoveWatering();
            }
        } else {
            game.MoveTo(0.25,0,0);
            game.MoveTo(-0.25,0,0);
        }
    }
}
void bonusCrop() {
    int x = 0;
    for (int i = 0; i < 1;)   {
        if (!game.OpponentAtAstronaut()) {
            game.MoveAstronaut();
            x = game.GetBonusCrop();
            bonus = (x == -1) ? ids[smallest] : x;
            i++;
        } else {
            game.MoveTo(0.25,1.5,0);
            game.MoveTo(-0.25,1.5,0);
        }
    }
}
//TODO: optimize time used
//Sometimes goes over time constraints by a few seconds
//TODO: finsih making closest finding
//TODO: fix7
void init(){
    waits[0] = 6;
    waits[1] = 8;
    waits[2] = 5;
    waits[3] = 12;
    waits[4] = 3;
    waits[5] = 9;
    ids[0] = 1;
    ids[1] = 2;
    ids[2] = 3;
    ids[3] = 4;
    ids[4] = 5;
    ids[5] = 6;
    isBlue = (game.GetRobotID() == 0) ? true : false;
    for (int i = 0; i < 6; i++) {
        timesPlanted[i] = 0;
        plotStatus[i] = 0;
        plotWait[i] = 0;
        plotTime[i] = 0;
    }
    if (isBlue) {
        plot[0] = {-0.35, 0.60, 0.20};
        plot[1] = {0.35, 0.60, 0.20};
        plot[2] = {-0.15, 1.00, 0.30};
        plot[3] = {-0.35, 1.40, 0.25};
        plot[4] = {0.35, 1.40, 0.25};
        plot[5] = {0.15, 1.00, 0.30};
    } else {
        plot[0] = {-0.35, 0.60, -0.20};
        plot[1] = {0.35, 0.60, -0.20};
        plot[2] = {-0.15, 1.00, -0.30};
        plot[3] = {-0.35, 1.40, -0.25};
        plot[4] = {0.35, 1.40, -0.25};
        plot[5] = {0.15, 1.00, -0.30};
    }
    start = clock();
}
void loop(){
    /* plant IDs for ease of coding
    Tomato = 1, wait = 6s
    Cabbage = 2, wait = 8s
    Strawberry = 3, wait = 5s
    Melon = 4, wait = 12s
    Blueberry = 5, wait = 3s
    Potato = 6, wait = 9s */
    // Harvesting order
    // 1,3,4,5,6,2
    // CYCLE ONE
    // Get Bonus Crop
    bonusCrop();
    // Plant plots 1-6
    plantingCycle(1, bonus);
    plantingCycle(3, ids[smallest]);
    plantingCycle(4, ids[smallest]);
    plantingCycle(5, ids[smallest]);
    plantingCycle(6, ids[smallest]);
    plantingCycle(2, ids[smallest]);
    // Fill Watering Can
    wateringCan();
    // Water plots 1-6 again
    wateringCycle(6);
    // Harvest bonus crop
    game.MovePlot(1);
    game.HarvestCrop(1);
    plotStatus[0] = 0;
    plotCrop[0] = 0;
    // Get second bonus crop
    bonusCrop();
    // Harvest second bonus crop
    for (int i = 0; i < 6; i++) {
        if (plotCrop[i] == bonus) {
            game.MovePlot(i + 1);
            game.HarvestCrop(i + 1);
            plotStatus[i] = 0;
            plotCrop[i] = 0;
        }
    }
    // Get third bonus crop
    bonusCrop();
    // Harvest third bonus crop
    for (int i = 0; i < 6; i++) {
        if (plotCrop[i] == bonus) {
            game.MovePlot(i + 1);
            game.HarvestCrop(i + 1);
            plotStatus[i] = 0;
            plotCrop[i] = 0;
        }
    }
    // Harvest the rest of the plots
    for (int i = 0; i < 6; i++) {
        if (plotStatus[i] == 2) {
            game.MovePlot(i + 1);
            game.HarvestCrop(i + 1);
            plotStatus[i] = 0;
            plotCrop[i] = 0;
        }
    }
    // Fill Watering Can
    wateringCan();
    // CYCLE TWO
    // Plant plots 1-6 - Cycle 2
    plantingCycle(1, ids[smallest]);
    plantingCycle(3, ids[smallest]);
    plantingCycle(4, ids[smallest]);
    plantingCycle(5, ids[smallest]);
    plantingCycle(6, ids[smallest]);
    plantingCycle(2, ids[smallest]);
    // Fill Watering Can - Cycle 2
    wateringCan();
    // Water plots 1-6 again - Cycle 2
    wateringCycle(6);
    // Harvest plots 1-6 - Cycle 2
    harvestingCycle(6);
    // Fill Watering Can - Cycle 2
    wateringCan();
    // CYCLE THREE
    if (game.GetTime() <= 214) {
        if (!ids[smallest] == 4 || !ids[smallest] == 6) {
            plantingCycle(1, ids[smallest]);
            plantingCycle(2, ids[smallest]);
        } else {
            plantingCycle(1, ids[smallest - 1]);
            if (!ids[smallest] == 4 || !ids[smallest] == 6) {
                plantingCycle(2, ids[smallest]);
            } else {
                plantingCycle(2, ids[smallest - 1]);
            }
        }
        wateringCycle(2);
        harvestingCycle(2);
    } else if (game.GetTime() <= 225) {
        if (!ids[smallest] == 4 || !ids[smallest] == 6) {
            plantingCycle(1, ids[smallest]);
        } else {
            if (timesPlanted[3] <= timesPlanted[5]) {
                plantingCycle(1, 3);
            } else {
                plantingCycle(1, 5);
            }
        }
        wateringCycle(1);
        harvestingCycle(1);
    }
}
//End page main
3 Alliance 3 — Internal Compiling ErrorMost Organized Code

“A global alliance spanning San Antonio, Austin, San Jose, and Delhi.”

Aeroknots GyroPlanters Piedmont Hills Team Byte
</> View Source Code
//Begin page main
// Declare any variables shared between functions here
#include <math.h>
int bonusInHand; //How many bonus crops robot can still plant
int bonusPlanted; //How many bonus crops were planted
int astronautVisits; //How many times robot visited astronaut
int bonusCropID; //The ID of the bonus recieved
void init() {
    bonusInHand = 0;
    bonusPlanted = 0;
    astronautVisits = 0;
    bonusCropID = 0;
}
void loop() {
    fullCycle(false, false);
    if(game.GetTime() > 220) {
        game.EndGame();
        return; 
    }
    fullCycle(true, false);
    if(game.GetTime() > 220) {
        game.EndGame();
        return; 
    }
    fullCycle(false, true);
    if(game.GetTime() > 210) {
        game.EndGame();
        return; 
    }
}
bool shouldVisitAstronaut() {
    return (astronautVisits < 3 && bonusInHand == 0 && game.GetTime() < 205); 
}
void getBonus() {
    if(!shouldVisitAstronaut()) return;
    int start = game.GetTime();
    while (game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut()) {
        if (game.GetTime() - start > 10) return;
        game.SetWait(1);
    }
    game.MoveAstronaut();
    bonusCropID = game.GetBonusCrop();
    bonusInHand++;
    astronautVisits++;
}
// Decide whether to plant our Plant or Astronaut
void PlantCropPorA(int plotID, int cropID){
    if (bonusInHand > 0 && bonusCropID == cropID) {
        game.PlantCrop(plotID, bonusCropID);
        bonusInHand--;
        bonusPlanted++;
    } else {
       game.PlantCrop(plotID, cropID);
    }
}
// Returns the plot which is the "pair" on the opposite side
int getPairPlots(int plotID) {
     switch(plotID) {
        case 1: return 2;
        case 2: return 1;
        case 3: return 6;
        case 6: return 3;
        case 4: return 5;
        case 5: return 4;
        default: return -1; // Error possibility
    }
}
// Translate strings to numbers for crop names because I am annoyed at relating numbers to cropID
int getCropID(const char* cropName) {
    if(strcmp(cropName, "Tomato") == 0) return 1;
    if(strcmp(cropName, "Cabbage") == 0) return 2;
    if(strcmp(cropName, "Strawberry") == 0) return 3;
    if(strcmp(cropName, "Melon") == 0) return 4;
    if(strcmp(cropName, "Blueberry") == 0) return 5;
    if(strcmp(cropName, "Potato") == 0) return 6;
    return 0; // If nothing works, yolo
}
// Plant crop, check if it needs to be on the other side, and then water
void smartPlant(int plotID, const char* cropName, bool invertedSide) {
    int finalPlot;
    if (invertedSide) {
        // If the side is inverted, find the plot pair (1 <--> 2, 3 <--> 6, 4 <--> 5)
        finalPlot = getPairPlots(plotID);
    } else {
        finalPlot = plotID;
    }
    // Translate the text name to the cropID
    int cropID = getCropID(cropName);
    // Execute the normal game commands
    game.MovePlot(finalPlot);
    PlantCropPorA(finalPlot, cropID);
    game.WaterCrop(finalPlot);
}
// Ditto, but with water
void smartWater(int plotID, bool invertedSide) {
    int finalPlot;
    if (invertedSide) {
        // If the side is inverted, find the plot pair (1 <--> 2, 3 <--> 6, 4 <--> 5)
        finalPlot = getPairPlots(plotID);
    } else {
        finalPlot = plotID;
    }
    // Execute the normal game commands
    game.MovePlot(finalPlot);
    game.WaterCrop(finalPlot);
}
// Ditto, but with harvest
void smartHarvest(int plotID, bool invertedSide) {
    int finalPlot;
    if (invertedSide) {
        // If the side is inverted, find the plot pair (1 <--> 2, 3 <--> 6, 4 <--> 5)
        finalPlot = getPairPlots(plotID);
    } else {
        finalPlot = plotID;
    }
    // Execute the normal game commands
    game.MovePlot(finalPlot);
    game.HarvestCrop(finalPlot);
}
// Melon Potato Cabbage 
void melonPotatoCabbageR(bool invertedSide, bool invertedOrder) { //Originally on RIGHT SIDE (Astronaut's Left)
        // Plant MELON, POTATO, CABBAGE
        if(invertedOrder){
            smartPlant(4, "Cabbage", invertedSide);
            smartPlant(3, "Strawberry", invertedSide);
            smartPlant(1, "Melon", invertedSide);
        } else {
            smartPlant(4, "Melon", invertedSide);
            smartPlant(3, "Potato", invertedSide);
            smartPlant(1, "Cabbage", invertedSide);
        }
        if(invertedOrder){
           game.SetWait(12);
        } else {
           game.SetWait(8);
        }
        // 2nd Water CABBAGE, POTATO, MELON
        if(invertedOrder){
            smartWater(4, invertedSide);
            smartWater(3, invertedSide);
            smartWater(1, invertedSide);
        } else {
            smartWater(1, invertedSide);
            smartWater(3, invertedSide);
            smartWater(4, invertedSide);
        }
        // Wait for water to be clear
        while(game.OpponentAtWatering() || game.OpponentGoingToWatering()) {
            if (game.GetTime() > 235) break;
            game.SetWait(1);
        }
        // Refill water
        game.MoveWatering();
        game.FillWateringCan();
         // Harvest CABBAGE, POTATO, MELON
        if(invertedOrder){
            smartHarvest(4, invertedSide);
            smartHarvest(3, invertedSide);
            smartHarvest(1, invertedSide);
        } else {
            smartHarvest(1, invertedSide);
            smartHarvest(3, invertedSide);
            smartHarvest(4, invertedSide);
        }
        game.GetTime();
}
// Blueberry Strawberry Tomato 
void blueberryStrawberryTomatoL(bool invertedSide, bool invertedOrder) { //Originally on LEFT SIDE (Astronaut's Right)
        // Plant BLUEBERRY, STRAWBERRY, TOMATO
        if(invertedOrder){
            smartPlant(5, "Tomato", invertedSide);
            smartPlant(6, "Potato", invertedSide);
            smartPlant(2, "Blueberry", invertedSide);
        } else {
            smartPlant(5, "Blueberry", invertedSide);
            smartPlant(6, "Strawberry", invertedSide);
            smartPlant(2, "Tomato", invertedSide);
        }
        if(invertedOrder){
           game.SetWait(3);
       } else {
           game.SetWait(6);
       }
        // 2nd Water TOMATO, STRAWBERRY, BLUEBERRY
        if(invertedOrder){
            smartWater(5, invertedSide);
            smartWater(6, invertedSide);
            smartWater(2, invertedSide);
        } else {
            smartWater(2, invertedSide);
            smartWater(6, invertedSide);
            smartWater(5, invertedSide);
        }
        // Wait for water to be clear
        while(game.OpponentAtWatering() || game.OpponentGoingToWatering()) {
            if (game.GetTime() > 235) break;
            game.SetWait(1);
        }
        // Refill water
        game.MoveWatering();
        game.FillWateringCan();
         //Harvest TOMATO, STRAWBERRY, BLUEBERRY
        if(invertedOrder){
            smartHarvest(5, invertedSide);
            smartHarvest(6, invertedSide);
            smartHarvest(2, invertedSide);
        } else {
            smartHarvest(2, invertedSide);
            smartHarvest(6, invertedSide);
            smartHarvest(5, invertedSide);
        }
        game.GetTime();
}
// Get the closest plot
int closestPlot() {
    float myPos[3] = {game.GetRobotPositionX(), game.GetRobotPositionY(), game.GetRobotPositionZ()};
    //Define coords for the plots (2,3,5,6 because Cabbage already planted in 1 and 4)
    float plots[4][4] = {
        {2.0f, 0.35f, 0.6f, 0.2f},
        {3.0f, -0.15f, 1.0f, 0.3f},
        {5.0f, 0.35f, 1.4f, 0.25f},
        {6.0f, 0.15f, 1.0f, 0.3f}  
    };
    int bestPlot = 3; //Some placeholder value, and 3 is a lucky number
    int minDist = 10.0f; //Some placeholder big number
    for (int i = 0; i < 4; i++){
        // Get the distance between bot and plot. Pythagorean theorem! 
        float dist = sqrtf(powf(myPos[0] - plots[i][1], 2) + powf(myPos[1] - plots[i][2], 2) + powf(myPos[2] - plots[i][3], 2));
        //If that plot is the closest, change the "bestPlot"
        if (dist < minDist){
            minDist = dist;
            bestPlot = (int)plots[i][0];
        }
    }
    return bestPlot;
}
// Full cycle
void fullCycle(bool invertedSide, bool invertedOrder) {
    // Wait for other team to leave the Astronaut
    if(shouldVisitAstronaut()) getBonus();
    melonPotatoCabbageR(invertedSide, invertedOrder);
    if(shouldVisitAstronaut()) getBonus();
    // ENDGAME!
    if (game.GetTime() > 210){
        if(game.GetTime() < 226){
            int quickPlot = closestPlot();
            smartPlant(quickPlot, "Cabbage", false);
            smartWater(quickPlot, false);
            if (game.GetTime() > 232) return;
            game.SetWait(8); 
            if (game.GetTime() == 240) return;
            smartHarvest(quickPlot, false);
            return;
        } else {
            return;
        }
    }
    blueberryStrawberryTomatoL(invertedSide, invertedOrder);
}
//AI was used to aid with debugging, specifically with staying under the 240 seconds. Everything else was human-programmed :)
//End page main
5 Alliance 5 — Quantum Computing TerraformersBest Presentation

“Precision-driven autonomous systems for sustainable space agriculture.”

Angolan Robotics Team Highland Server Errors Quark Charm 2 TerraBee’s
</> View Source Code
//Begin page main
/**
 *
 *Final code
 *ready for submission
 */
struct CropInfo {
    float points;
    int growthTime;
};
CropInfo crops[6];
enum PlotStage {
    NEED_WATER_1,
    NEED_WATER_2,
    NEED_HARVEST
};
struct PlotInfo{
    bool active;
    int curCrop;
    int nextActionTime;
    PlotStage stage;
};
PlotInfo plots[6];
float OVERHEAD_PER_CROP;
void WaitUntil(int targetTime) {
    int now = game.GetTime();
    if (now < targetTime)
        game.SetWait(targetTime - now);
}
void getWater() {
    if (game.GetTime() >= 238)
        game.EndGame();
    while (game.OpponentAtWatering() ||
           game.OpponentGoingToWatering()) {
        game.SetWait(0.5);
    }
    game.MoveWatering();
    game.FillWateringCan();
}
void doOneBonusCycle(int plotToUse) {
    goAstronaut();
    int bonusCrop = game.GetBonusCrop();
    game.MovePlot(plotToUse);
    game.PlantCrop(plotToUse, bonusCrop);
    game.WaterCrop(plotToUse);
    int growthTime = crops[bonusCrop-1].growthTime;
    game.SetWait(growthTime);
    game.MovePlot(plotToUse);
    game.WaterCrop(plotToUse);
    game.SetWait(growthTime);
    game.MovePlot(plotToUse);
    game.HarvestCrop(plotToUse);
    crops[bonusCrop-1].points *= 0.75f;
}
void goAstronaut() {
    if (game.GetTime() >= 240) {
        game.EndGame();
    }
    while ((game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut())) {
        game.SetWait(0.5);
    }
    game.MoveAstronaut();
}
void completeAstronaut() {
    for(int bonusCycle = 1; bonusCycle <= 3; bonusCycle++) {
        doOneBonusCycle(bonusCycle + 3);
    }
}
struct threeCropSequence {
    int crop1; int crop2; int crop3;
};
threeCropSequence best3Crops() {
    threeCropSequence best = {1,1,1};
    float bestScore = -1.0f;
    for (int i=0;i<6;i++){
        for (int j=0;j<6;j++){
            for (int k=0;k<6;k++){
                float totalPoints = 0;
                float decay[6];
                for(int c=0;c<6;c++)
                    decay[c]=1.0f;
                int t1=crops[i].growthTime;
                int t2=crops[j].growthTime;
                int t3=crops[k].growthTime;
                float totalTime =
                    2*t1 + 2*t2 + 2*t3 +
                    3*OVERHEAD_PER_CROP;
                totalPoints += crops[i].points * decay[i];
                decay[i]*=0.75f;
                totalPoints += crops[j].points * decay[j];
                decay[j]*=0.75f;
                totalPoints += crops[k].points * decay[k];
                float score = totalPoints / totalTime;
                if(score>bestScore){
                    bestScore=score;
                    best.crop1=i+1;
                    best.crop2=j+1;
                    best.crop3=k+1;
                }
            }
        }
    }
    return best;
}
void advanceUntilAllNeedHarvest() {
    while (true) {
        bool allNeedHarvest = true;
        for (int i=0;i<3;i++) {
            if (!plots[i].active)
                continue;
            if (plots[i].stage == NEED_WATER_2) {
                allNeedHarvest = false;
                game.MovePlot(i+1);
                WaitUntil(plots[i].nextActionTime);
                game.WaterCrop(i+1);
                plots[i].stage = NEED_HARVEST;
                plots[i].nextActionTime =
                    game.GetTime() +
                    crops[plots[i].curCrop-1].growthTime;
            }
            if (plots[i].stage != NEED_HARVEST)
                allNeedHarvest = false;
        }
        if (allNeedHarvest)
            break;
    }
}
void batchHarvestAndReplant() {
    threeCropSequence next = best3Crops();
    int cropsToPlant[3] = {
        next.crop1,
        next.crop2,
        next.crop3
    };
    for (int i=0;i<3;i++) {
        int plot=i+1;
        int oldCrop=plots[i].curCrop;
        float scoreNow = game.GetHarvestScore();
        while(game.GetHarvestScore() < 1 + scoreNow) {
             game.MovePlot(plot);
             game.HarvestCrop(plot);
         }
        crops[oldCrop-1].points*=0.75f;
        int newCrop=cropsToPlant[i];
        game.PlantCrop(plot,newCrop);
        game.WaterCrop(plot);
        plots[i].curCrop=newCrop;
        plots[i].stage=NEED_WATER_2;
        plots[i].nextActionTime=
            game.GetTime()+
            crops[newCrop-1].growthTime;
    }
}
void threeCropCycle() {
    if (!plots[0].active) {
        threeCropSequence seq = best3Crops();
        int initial[3] = {
            seq.crop1,
            seq.crop2,
            seq.crop3
        };
        for(int i=0;i<3;i++){
            game.MovePlot(i+1);
            game.PlantCrop(i+1,initial[i]);
            game.WaterCrop(i+1);
            plots[i].active=true;
            plots[i].curCrop=initial[i];
            plots[i].stage=NEED_WATER_2;
            plots[i].nextActionTime=
                game.GetTime()+
                crops[initial[i]-1].growthTime;
        }
    }
    advanceUntilAllNeedHarvest();
    getWater();
    batchHarvestAndReplant();
}
void threeCropImmediateHarvest() {
    advanceUntilAllNeedHarvest();
    for (int i=0;i<3;i++) {
        int plot=i+1;
        float scoreNow = game.GetHarvestScore();
        while(game.GetHarvestScore() < 1 + scoreNow) {
             game.MovePlot(plot);
             game.HarvestCrop(plot);
         }
    }
}
void init() {
    OVERHEAD_PER_CROP = 5.0f;
    crops[0]={6,6};
    crops[1]={7,8};
    crops[2]={5,5};
    crops[3]={11,12};
    crops[4]={3,3};
    crops[5]={8,9};
    for(int i=0;i<6;i++){
        plots[i].active=false;
        plots[i].curCrop=0;
        plots[i].nextActionTime=0;
        plots[i].stage=NEED_WATER_1;
    }
}
void loop(){
    completeAstronaut();
    getWater();
    // CHANGE 1: Farm until 165s instead of 160s 
    while(game.GetTime() <= 165){
        threeCropCycle();
    }
    // CHANGE 2: Final harvest only if time allows
    if(game.GetTime() < 195) {
        threeCropImmediateHarvest();
    }
    // CHANGE 3: Extended movement phase (195-235s = 40 seconds instead of 30)
    int movements = 0;
    while(game.GetTime() < 235 && movements < 60) {
        switch(movements % 4) {
        case 0:
            game.MovePlot(1);
            break;
        case 1:
            game.MovePlot(5);
            break;
        case 2:
            game.MovePlot(2);
            break;
        case 3:
            game.MovePlot(4);
        }
        movements++;
    }
    game.EndGame();
}
//End page main
7 Alliance 7 — BeyondSpace
Astro Girls I Razzi Missile Sage STEM Club The Ultimate SpaceBots 2026 HS
</> View Source Code
//Begin page main
 // the number of times the robot visits the astronaut
//Declare any variables shared between functions here 
int plot1, plot2, plot3, plot4, plot5, plot6, prev1, prev2, prev3, prev5, prev6, secondbonus, bonus;
//Declare any variables shared between functions here
int previousbonus;
int GetReminderTime() {
    return 240 - game.GetTime();
}
bool CanPerformAction(int buffer=5) {
    // Check if we have enough time for an action (safety buffer 5s)
    return GetReminderTime() > buffer;
}
void goAstro(){
    previousbonus = bonus;
    if(game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut()){
        if(game.GetWaterUnits() != 0){
        game.MoveWatering();
        game.FillWateringCan();}
        else{
            game.MovePlot(4);
            game.MovePlot(5);
        }
        game.MoveAstronaut();
        bonus = game.GetBonusCrop();
    }else if(!game.OpponentAtAstronaut() || !game.OpponentGoingToAstronaut()){
        game.MoveAstronaut();
        bonus = game.GetBonusCrop();
        if(bonus == previousbonus){
            if(game.GetWaterUnits() != 0){
            game.MoveWatering();
            game.FillWateringCan();}
            else{
            game.MovePlot(4);
            game.MovePlot(5);
            }
            game.MoveAstronaut();
            bonus = game.GetBonusCrop();
        }
    }
    else{
        if(game.GetWaterUnits() != 0){
        game.MoveWatering();
        game.FillWateringCan();}
        else{
            game.MovePlot(4);
            game.MovePlot(5);
        }
            game.MoveAstronaut();
            bonus = game.GetBonusCrop();
        }
}
void fillWater(){
    if (game.GetWaterUnits() == 1){
        if(!(game.OpponentGoingToWatering() or game.OpponentAtWatering())){
            game.MoveWatering();
            game.FillWateringCan();
        }
    }
    else if (game.GetWaterUnits() == 0){
    if(game.OpponentGoingToWatering() or game.OpponentAtWatering()){
        game.MovePlot(1);
        game.MovePlot(2);
        game.MoveWatering();
        game.FillWateringCan();
    }else if(!(game.OpponentGoingToWatering() or game.OpponentAtWatering())){
        game.MoveWatering();
        game.FillWateringCan();
        if(game.GetWaterUnits() != 6){
            game.MovePlot(1);
            game.MovePlot(2);
            game.MoveWatering();
            game.FillWateringCan();
        }
    }
    }
}
/*
void fillWater(){
    if (game.GetWaterUnits() == 1){
        if(!(game.OpponentGoingToWatering() or game.OpponentAtWatering())){
            game.MoveWatering();
            game.FillWateringCan();
        }
    }
    else if (game.GetWaterUnits() == 0){
        if(!(game.OpponentGoingToWatering() or game.OpponentAtWatering())){
                game.MoveWatering();
                game.FillWateringCan();
            }
        else{
                game.MoveWatering();
                game.FillWateringCan();
        }
    }
}*/
void init(){
    //This function is called once when your code is first loaded.
    //IMPORTANT: make sure to set any variables that need an initial value.
    //Do not assume variables will be set to 0 automatically!
    plot1 = 0;
    plot2 = 0;
    plot3 = 0;
    plot4 = 0;
    plot5 = 0;
    plot6 = 0;
    prev6 = 0;
    prev3 = 0;
    prev1 = 0;
    prev2 = 0;
    prev5 = 0; //I could probably initialize the variables in a better way though by listing them and then =0;
    secondbonus = 0;
    bonus = 0;
    previousbonus = 0;
}
void loop(){
    //float x = game.GetRobotPositionX();
    //float y = game.GetRobotPositionY();
    //float z = game.GetRobotPositionZ();
    /*if (x== 0 && y == 0 && z == 0){//may change based on blue team or red team currently blue
               game.MoveWatering();
            game.FillWateringCan();  // fills 6 units of water
            game.MovePlot(1);
            game.PlantCrop(1, 4);
            prev1 = 4;
            game.WaterCrop(1);*/
        if (!game.GetAstronautVisits()){
                goAstro();
                bonus = game.GetBonusCrop();
                game.MovePlot(4);
                game.PlantCrop(4, bonus);
                game.WaterCrop(4);   
                fillWater();
                game.MovePlot(3);
                game.PlantCrop(3, 6);
                prev3 = 6;
                game.WaterCrop(3);
                fillWater();
                game.MovePlot(1);
                game.PlantCrop(1, 4);
                prev1 = 4;
                game.WaterCrop(1);
                fillWater();
//make sure that multipple prevs are not the same for if statements later on                
                game.MovePlot(2);
                game.PlantCrop(2, 4);
                prev2 = 4;
                game.WaterCrop(2);
                fillWater();
                game.MovePlot(6);
                game.PlantCrop(6, 1);
                prev6 = 1;
                game.WaterCrop(6);
                fillWater(); 
                game.MovePlot(5);
                game.PlantCrop(5, 3);  
                game.WaterCrop(5);
                prev5 = 3;
                fillWater();
                game.MovePlot(4);
                game.WaterCrop(4);
                fillWater();
                game.MovePlot(3);
                game.WaterCrop(3); 
                fillWater();
                game.MovePlot(1);    
                game.WaterCrop(1);
                fillWater();
                game.MovePlot(2);
                game.WaterCrop(2); 
                fillWater();
                game.MovePlot(6);
                game.WaterCrop(6);
                fillWater();
                game.MovePlot(5);      
                game.WaterCrop(5);
                fillWater();
                game.MovePlot(4);
                game.HarvestCrop(4);
                goAstro();  
                bonus = game.GetBonusCrop();
                secondbonus = bonus;
                switch (bonus) {
                  case 1:
                    plot2 = 5;
                    plot1 = 3;
                    plot3 = 2;        
                    plot6 = 6;
                    plot5 = 4;
                    break;
                  case 2:
                    plot2 = 5;
                    plot1 = 3;     
                    plot3 = 1;
                    plot6 = 6;
                    plot5 = 4;
                    break;
                  case 3:
                    plot2 = 5;
                    plot1 = 1;
                    plot3 = 2;
                    plot6 = 6;
                    plot5 = 4;
                    break;
                  case 4:
                    plot2 = 5;
                    plot1 = 3;
                    plot3 = 1;
                    plot6 = 2;
                    plot5 = 6;
                    break;
                  case 5:
                    plot2 = 3;
                    plot1 = 1;
                    plot3 = 2;
                    plot6 = 6;
                    plot5 = 4;
                    break;
                  case 6:
                    plot2 = 5;
                    plot1 = 3;
                    plot3 = 1;
                    plot6 = 2;
                    plot5 = 4;
                    break;    
                }
                game.MovePlot(4);
                game.PlantCrop(4, bonus);
                game.WaterCrop(4);
                fillWater();
                game.MovePlot(3); 
                game.HarvestCrop(3); 
                game.PlantCrop(3, plot3); 
                game.WaterCrop(3); 
                if(prev3 == secondbonus){
                    goAstro();              // Move to astronaut zone
                    bonus = game.GetBonusCrop();}
                fillWater();//idk did not count
                game.MovePlot(1); 
                game.HarvestCrop(1); 
                game.PlantCrop(1, plot1); 
                game.WaterCrop(1); 
                if(prev1 == secondbonus){          
                    goAstro();              // Move to astronaut zone
                    bonus = game.GetBonusCrop();}
                fillWater();//idk did not count
//make prev2 not equal to prev1                
                game.MovePlot(2); 
                game.HarvestCrop(2); 
                game.PlantCrop(2, plot2); 
                game.WaterCrop(2); 
                if(prev2 == secondbonus){
                    goAstro();              // Move to astronaut zone
                    bonus = game.GetBonusCrop();}
                fillWater();//idk did not count
                game.MovePlot(6);
                game.HarvestCrop(6); 
                game.PlantCrop(6, plot6); 
                game.WaterCrop(6); 
                if(prev6 == secondbonus){//assuming the prevs are all different crops except for 1 and 2, so there is no if at 2
                    goAstro();              // Move to astronaut zone
                    bonus = game.GetBonusCrop();}
                fillWater();
                game.MovePlot(5);
                game.HarvestCrop(5);
                game.PlantCrop(5, plot5); 
                game.WaterCrop(5);
                if(prev5 == secondbonus){
                    goAstro();              // Move to astronaut zone
                    bonus = game.GetBonusCrop();            
                }
                fillWater();
                //watering plots starting with 4
                game.MovePlot(4); 
                game.WaterCrop(4); 
                fillWater();//idk did not count
                game.MovePlot(3); 
                game.WaterCrop(3); 
                fillWater();//idk did not count
                game.MovePlot(1); //still have to change the order of th s 
                game.WaterCrop(1); 
                fillWater();//idk did not count
                game.MovePlot(2);                          
                game.WaterCrop(2); 
                fillWater();//idk did not count
                game.MovePlot(6);
                game.WaterCrop(6);
                fillWater();
                game.MovePlot(5); 
                game.WaterCrop(5); 
                fillWater();//idk did not count
                game.MovePlot(4);
                game.HarvestCrop(4);
//test out on its own                
                if (bonus == secondbonus){
                goAstro();              // Move to astronaut zone             
                bonus = game.GetBonusCrop(); //third bonus plant 
                game.MovePlot(3);
                game.HarvestCrop(3);
                game.PlantCrop(3, bonus);
                game.WaterCrop(3);
                } 
                else{
                game.MovePlot(3);
                game.HarvestCrop(3);
                game.PlantCrop(3, bonus);
                game.WaterCrop(3);
                }
                fillWater();
                game.MovePlot(1);
                game.HarvestCrop(1);
                game.PlantCrop(1, 2);
                game.WaterCrop(1);
                fillWater();//idk did not count
                game.MovePlot(2);
                game.HarvestCrop(2);
                game.PlantCrop(2, 2);
                game.WaterCrop(2);
                fillWater();//idk did not count
//test timing of going to plot 5       
                game.MovePlot(5);
                game.HarvestCrop(5);
                game.MovePlot(6);
                game.HarvestCrop(6);
                game.PlantCrop(6, 1);
                game.WaterCrop(6);
                fillWater();//idk did not count
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                /*game.MovePlot(5);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.HarvestCrop(5);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.PlantCrop(5, 2);//finished here
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.WaterCrop(5);
                if(!CanPerformAction()) { game.EndGame(); return; }
                fillWater();//idk did not count*/
                if(!CanPerformAction()) { game.EndGame(); return; }
if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(3);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.WaterCrop(3);
                if(!CanPerformAction()) { game.EndGame(); return; }
                fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.WaterCrop(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
            if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(2);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.WaterCrop(2);
                if(!CanPerformAction()) { game.EndGame(); return; }
                fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(6);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.WaterCrop(6);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.MovePlot(5);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.WaterCrop(5);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.MovePlot(4);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.HarvestCrop(4);
                if(!CanPerformAction()) { game.EndGame(); return; }
 //These crops will all have to be really short waitime crops          
 if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(3);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.HarvestCrop(3);        
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.PlantCrop(3, 1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.WaterCrop(3);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.HarvestCrop(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.PlantCrop(1, 3);                                
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.WaterCrop(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(2);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.HarvestCrop(2);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.PlantCrop(2, 1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //game.WaterCrop(2);
                if(!CanPerformAction()) { game.EndGame(); return; }
                //fillWater();
                if(!CanPerformAction()) { game.EndGame(); return; }
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(6);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.HarvestCrop(6);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MoveWatering();
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MoveWatering();
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MoveWatering();
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MovePlot(1);
                if(!CanPerformAction()) { game.EndGame(); return; }
                game.MoveWatering();
//Done harvisting all, ignore rest 
/*
                game.MovePlot(3);
                game.WaterCrop(3);
               fillWater();
                game.MovePlot(1);
                game.WaterCrop(1);
                fillWater();
                game.MovePlot(2);
                game.WaterCrop(2); 
                fillWater();
                game.MovePlot(6);
                game.WaterCrop(6);
                game.MovePlot(3);
                game.HarvestCrop(3);
                game.MovePlot(1);
                game.HarvestCrop(1);
                game.MovePlot(2);
                game.HarvestCrop(2); 
                game.MovePlot(6);
                game.HarvestCrop(6);
                //game.MovePlot(4);        
                //game.HarvestCrop(4); 
                //game.MovePlot(5);
                //game.HarvestCrop(5);*/
}
        }
//    }
//End page main
8 Alliance 8 — 8 BallBest Student Video

“Internationals unite!”

Brookline Bino Bots I.S. Mercurino Team 1 SMPK 4 PENABUR JAKARTA Wayzata Zero Robotics 2026 HS
</> View Source Code
//Begin page main
//Declare any variables shared between functions here
int plots;
int crops;
bool astro;
float GROWTH_TIME[7];
float BASE_POINTS[7];
float HARVEST_TIME[7];
float WATERING2[7];
int BONUS_PLOT;
bool isThereBonus;
int HARVEST_COUNT[7];
int CROP_PLOT[7];
int bonusharvest;
void init(){
    isThereBonus = false;
    BONUS_PLOT = 0;
    bonusharvest = 0;
    GROWTH_TIME[0] = 0.0f;
    GROWTH_TIME[1] = 6.0f;
    GROWTH_TIME[2] = 8.0f;
    GROWTH_TIME[3] = 5.0f;
    GROWTH_TIME[4] = 12.0f;     //growth time, based on each crop id
    GROWTH_TIME[5] = 3.0f;
    GROWTH_TIME[6] = 9.0f;
    BASE_POINTS[0] = 0.0f;
    BASE_POINTS[1] = 6.0f;
    BASE_POINTS[2] = 7.0f;
    BASE_POINTS[3] = 5.0f;      //base points, based on each crop id
    BASE_POINTS[4] = 11.0f;
    BASE_POINTS[5] = 3.0f;
    BASE_POINTS[6] = 8.0f;
    HARVEST_TIME[0] = 0.0f;
    HARVEST_TIME[1] = 0.0f;
    HARVEST_TIME[2] = 0.0f;
    HARVEST_TIME[3] = 0.0f;     //to know when is harvest time (will be used later)
    HARVEST_TIME[4] = 0.0f;         
    HARVEST_TIME[5] = 0.0f;
    HARVEST_TIME[6] = 0.0f;
    HARVEST_COUNT[0] = 0;
    HARVEST_COUNT[1] = 0;
    HARVEST_COUNT[2] = 0;       //to know how much times each crop has been harvested
    HARVEST_COUNT[3] = 0;
    HARVEST_COUNT[4] = 0;
    HARVEST_COUNT[5] = 0;
    HARVEST_COUNT[6] = 0;
    CROP_PLOT[0] = 0;
    CROP_PLOT[1] = 0;
    CROP_PLOT[2] = 0;
    CROP_PLOT[3] = 0;           // the crop at each plot (i = plot id)
    CROP_PLOT[4] = 0;
    CROP_PLOT[5] = 0;
    CROP_PLOT[6] = 0;
    WATERING2[0] = 0.0f;
    WATERING2[1] = 0.0f;
    WATERING2[2] = 0.0f;
    WATERING2[3] = 0.0f;    // the second watering cycle for each plot
    WATERING2[4] = 0.0f;
    WATERING2[5] = 0.0f;
    WATERING2[6] = 0.0f;
}
void fillwater(){           // function to check if needed to fill water
    int watercan = game.GetWaterUnits();
    if (watercan >0){
        return;             // if the watering is larger than 0 then return 
    }
    mustfillwater(); 
}
void mustfillwater(){
    bool oppwater = game.OpponentAtWatering();
    game.MoveWatering();
    while (oppwater){
        game.SetWait(1);
        oppwater = game.OpponentAtWatering();       // if opponent at watering, wait for a second (getting water wont take that long)
        game.MoveWatering();
    }
    game.FillWateringCan();     // if opponent not at watering then we'll just get water
}
void initiate(){
    // go to astronaut and wait if opponent already at astronaut
                int bonus = 0;
              game.MoveAstronaut();  
              bonus = game.GetBonusCrop();
        while (!bonus){  //bonus 1
                    game.SetWait(1);
                    game.MoveAstronaut();
                    bonus = game.GetBonusCrop();
                }  
        isThereBonus = true;
        int crops[]={4,6,2,1,3,5};
        int plots[]={5,4,3,6,2,1};
        for (int i=0; i<6; i++){        // for loop to plant crops at every plot
            int currentPlot = plots[i];
            int currentCrop = crops[i];
            if (currentCrop == bonus){
                BONUS_PLOT = currentPlot;
            }
            game.MovePlot(currentPlot);
            game.PlantCrop(currentPlot, currentCrop);
            HARVEST_COUNT[currentCrop] = HARVEST_COUNT[currentCrop] + 1; //increases the harvest count of each crop
            CROP_PLOT[currentPlot] = currentCrop;
            game.WaterCrop(currentPlot);
            WATERING2[currentPlot] = game.GetTime() + GROWTH_TIME[currentCrop];
        }
        fillwater();
}
//bestcrop
float calculateExpectedValue(int cropID) {
    int k = HARVEST_COUNT[cropID] + 1;
    float base = BASE_POINTS[cropID];
    float diminishing = powf(0.75f, k-1); // the formula for diminishing points
    float growth = GROWTH_TIME[cropID];
    float totalTime = 2.0f * growth + 3.0f; // ~3 sec for moving
    // dont count if time exceeds remaining time + 10 secs 
    float remainingTime = 240.0f - game.GetTime();
    float timePenalty = 1.0f;
    if (totalTime > remainingTime - 10.0f) {
        timePenalty = 0.0f; //multiply by zero so it doesn't count
    }
    return (base * diminishing * timePenalty) / totalTime;
}
int chooseOptimalCrop() {
    float bestValue = -9999.0f;     
    int bestCrop = 1; // default to tomato
    for (int cropID = 1; cropID <= 6; cropID++) {       //calculate each crop to see which has the best value
        float value = calculateExpectedValue(cropID);
        if (value > bestValue) {
            bestValue = value;
            bestCrop = cropID;
        }
    }
    return bestCrop;
}
void mainloop(){
    int plots[]={2,6,5,4,3,1};
    while (game.GetTime() < 235.0f){    //while true loop until time is more than 235.0 seconds
    for (int j=0; j<6; j++){
        int i = plots[j];
        float currentTime = game.GetTime();
        if (currentTime > WATERING2[i] && WATERING2[i] != 0.0f){    // if watering2 = 0.0f it means theres no need for watering2 
            if (game.GetTime()< 225.0f){    //don't plant if time exceed 225 seconds (wont be able to harvest)
                fillwater();
                game.MovePlot(i);
                game.WaterCrop(i);
                WATERING2[i] = 0.0f;
                HARVEST_TIME[i] = game.GetTime() + GROWTH_TIME[i];
            }
        } else if (currentTime > HARVEST_TIME[i] + 0.5f && HARVEST_TIME[i] != 0.0f){   //if harvest = 0.0f it means theres nothing to harvest / not needed yet
            game.MovePlot(i);
            game.HarvestCrop(i);
            if (BONUS_PLOT == i){
                isThereBonus = false;  //only happens if i is the bonus plot
                BONUS_PLOT = 0;
                bonusharvest = bonusharvest + 1;
            }
            fillwater();
            HARVEST_TIME[i]= 0.0f;
            if (!game.OpponentGoingToAstronaut() && bonusharvest <3 && !game.OpponentAtAstronaut() && !isThereBonus && (i == 5 || i== 4)){      //go take bonus if available, !isThereBonus means theres no bonus planted,
                    game.MoveAstronaut();                                                                               // go to astronaut only when plot 5 or 4 because it's closer so no time wasted
                    int bonus = game.GetBonusCrop();
                    isThereBonus = true;
                    game.MovePlot(i);
                    BONUS_PLOT = i;
                    game.PlantCrop(i, bonus);
                    game.WaterCrop(i);
                    HARVEST_COUNT[bonus] = HARVEST_COUNT[bonus] + 1; //increases the harvest count of each crop
                    CROP_PLOT[i] = bonus;
                    WATERING2[i] = game.GetTime() + GROWTH_TIME[bonus];
                    if (game.GetTime() > 235.0f){ //loop breaker
                    break;
                    game.EndGame(); 
                    }
                } else {                                    // if theres no more bonus crop, then just spam the best crop to plant until loop ends
                    int bestCrop = chooseOptimalCrop();
                    game.PlantCrop(i, bestCrop);
                    HARVEST_COUNT[bestCrop] = HARVEST_COUNT[bestCrop] + 1; //increases the harvest count of each crop
                    CROP_PLOT[i] = bestCrop;
                    game.WaterCrop(i);
                    WATERING2[i] = game.GetTime() + GROWTH_TIME[bestCrop];
                }
            }
            if (game.GetTime() > 235.0f){ //loop breaker
                break;
                game.EndGame(); 
            }
            if (game.GetTime() > 235.0f){ //loop breaker
                break;
                game.EndGame(); 
            }
        }
        if (game.GetTime() > 235.0f){ //loop breaker
            break;
            game.EndGame(); 
        }
        mustfillwater();
    }
}
void loop(){
    initiate();
    mainloop();
}
//End page main
9 Alliance 9 — Distinguished Dragons In SpaceMost Creative Logic

“CHS Zero Robotics, Space Jam, Inverse Matrix, Rooted Intelligence, and Whitney M. Young.”

CHS Zero Robotics Inverse Matrix Rooted Intelligence 2026 HS Space Jam Whitney M. Young Magnet High School
</> View Source Code
//Begin page main
// --- DECLARATIONS ---
float timeOfNext[8]; 
int cropAtPlot[8]; 
int states[8]; 
float SPEED; 
float locationsX[8], locationsY[8], locationsZ[8]; 
float CROP_GROWTH[7];
float CROP_POINTS[7];
// Game State
int bonus;
int bonusesCollected;
int currentCrop;
bool ready;
bool hasSprinkler; 
bool astronautBanned;
// Constants
#define PLANT 0
#define WATER2 2
#define HARV 3
#define AUX 4 
// --- HELPER FUNCTIONS ---
float max(float a, float b) { return a > b ? a : b; }
void plant(int p, int c) {
    if (c < 1 || c > 6) c = 5; 
    game.PlantCrop(p, c);
}
void chooseCrop() {
    float bestEff = -1.0f;
    float timeLeft = 240.0f - game.GetTime();
    currentCrop = 0; 
    if (timeLeft < 16.0f) {
        currentCrop = 5;
        return;
    }
    for (int i = 1; i <= 6; i++) {
        if (i < 1 || i > 6) continue;
        if (timeLeft < (CROP_GROWTH[i] * 2.0f + 1.8f)) continue;
        float pts = (i == bonus) ? (CROP_POINTS[i] * 1.5f) : CROP_POINTS[i];
        if (pts > bestEff) {
            bestEff = pts;
            currentCrop = i;
        }
    }
    if (currentCrop <= 0) currentCrop = 5; 
}
bool shouldRefill(int p) {
    float t = game.GetTime();
    int w = game.GetWaterUnits();
    if (t > 233.5f) return false;
    if (p == 1 || p == 2) return (w < 3);
    return (w < 1);
}
int pbc;
void locateBonusPlot() {
    if (cropAtPlot[1] == bonus) {
        pbc = 1;
    } else if (cropAtPlot[3] == bonus) {
        pbc = 3;
    } else if (cropAtPlot[6] == bonus) {
        pbc = 6;
    } else {
        pbc = 4;
    }
}
void changeState(int p) {
    switch (states[p]) {
        case PLANT:
            // *** PLANTING SAFETY BRAKE ***
            if (game.GetTime() > 237.2f) return;
            if (shouldRefill(p)) { 
                game.MoveWatering(); 
                game.FillWateringCan(); 
                game.MovePlot(p); 
            }
            // Dry Planting Abort
            if (game.GetWaterUnits() < 1) {
                if (game.GetTime() < 236.0f) {
                     game.MoveWatering(); 
                     game.FillWateringCan(); 
                     game.MovePlot(p);
                }
            }
            if (game.GetWaterUnits() < 1) return;
            if (currentCrop < 1 || currentCrop > 6) currentCrop = 5;
            plant(p, currentCrop); 
            cropAtPlot[p] = currentCrop;
            if (currentCrop > 0) CROP_POINTS[currentCrop] *= 0.75f; 
            game.WaterCrop(p);
            if (p == 2 && hasSprinkler) {
                float interval = CROP_GROWTH[currentCrop];
                if (interval < 0.1f) interval = 3.0f;
                game.SetSprinklerInterval(1, interval);
                game.EnableSprinkler(1);
                states[p] = HARV;
                timeOfNext[p] = game.GetTime() + game.GetCropWaitTime(currentCrop);
            } else {
                states[p] = WATER2;
                timeOfNext[p] = game.GetTime() + CROP_GROWTH[currentCrop];
            }
            break;
        case WATER2:
            if (shouldRefill(p)) {
                game.MoveWatering();
                game.FillWateringCan();
                game.MovePlot(p);
            }
            game.WaterCrop(p);
            states[p] = HARV;
            timeOfNext[p] = game.GetTime() + CROP_GROWTH[cropAtPlot[p]];
            break;
        case HARV:
            if (p == 2 && hasSprinkler) game.DisableSprinkler(1);
            // *** HARD ACTION STOP ***
            if (game.GetTime() > 236.0f) return;
            float score1 = game.GetHarvestScore();
            game.HarvestCrop(p);
            float score2 = game.GetHarvestScore();
            while (score2 - score1 < CROP_POINTS[cropAtPlot[p]]) {
                game.MovePlot(p);
                score1 = score2;
                game.SetWait(max(0.0f, timeOfNext[p]-game.GetTime()));
                game.HarvestCrop(p);
                score2 = game.GetHarvestScore();
            }
            if (bonus == cropAtPlot[p]) { 
                bonusesCollected++; 
                bonus = 0; 
            }
            cropAtPlot[p] = 0;
            states[p] = PLANT; 
            // *** STOP AFTER HARVEST ***
            if (game.GetTime() > 236.0f) return;
             if (bonusesCollected < 3 && p == 6) {
                if (!astronautBanned) {
                    game.MoveAstronaut();
                    game.SetWait(0.1f);
                    bonus = game.GetBonusCrop();
                    if (bonus < 1 || bonus > 6) {
                        bonus = 0;
                        astronautBanned = true;
                    }
                    currentCrop = bonus;
                    if (currentCrop <= 0) currentCrop = 5;
                    game.LeaveAstronaut();
                    game.MovePlot(p);
                } else {
                    chooseCrop();
                }
            } else {
                chooseCrop();
            }
            if (currentCrop <= 0) currentCrop = 5;
            // *** REPLANT CHECK ***
            if (shouldRefill(p)) {
                game.MoveWatering();
                game.FillWateringCan();
                game.MovePlot(p);
            }
            if (game.GetWaterUnits() < 1) {
                if (game.GetTime() < 236.0f) {
                     game.MoveWatering(); 
                     game.FillWateringCan(); 
                     game.MovePlot(p); 
                }
            }
            plant(p, currentCrop);
            cropAtPlot[p] = currentCrop;
            if (currentCrop > 0) CROP_POINTS[currentCrop] *= 0.75f;
            game.WaterCrop(p);
            if (p == 2 && hasSprinkler) {
                 float interval = CROP_GROWTH[currentCrop];
                 if (interval < 0.1f) interval = 3.0f;
                 game.SetSprinklerInterval(1, interval);
                 game.EnableSprinkler(1);
                 states[p] = HARV;
                 timeOfNext[p] = game.GetTime() + game.GetCropWaitTime(currentCrop);
            } else {
                 states[p] = WATER2;
                 timeOfNext[p] = game.GetTime() + CROP_GROWTH[currentCrop];
            }
            break;
    }
}
float distanceTo(float x, float y, float z) {
    float xx = (x-game.GetRobotPositionX())*(x-game.GetRobotPositionX());
    float yy = (y-game.GetRobotPositionY())*(y-game.GetRobotPositionY());
    float zz = (z-game.GetRobotPositionZ())*(z-game.GetRobotPositionZ());
    return sqrtf(xx+yy+zz);
}
float timeTo(int plotN) {
    return distanceTo(locationsX[plotN], locationsY[plotN], locationsZ[plotN])/0.18;
}
void doIt(int p) {
    // PRECHECK
    if (game.GetTime() > 236.0f) return;
    game.MovePlot(p);
    float w = timeOfNext[p] - game.GetTime();
    float max_wait = 239.0f - game.GetTime();
    if (w > max_wait) w = max_wait;
    game.SetWait(max(0.0f, w));
    if (states[p] == PLANT) chooseCrop();
    changeState(p);
}
// --- INIT ---
void init() {
    ready = true;
    hasSprinkler = false;
    SPEED = 0.18f; 
    for (int i = 0; i < 8; i++) {
        timeOfNext[i] = 0.0f;
        cropAtPlot[i] = 0;
        states[i] = (i == 0 || i == 7) ? AUX : PLANT;
    }
    locationsX[0]=0.0; locationsY[0]=0.0; locationsZ[0]=0.0; 
    locationsX[1]=-0.35; locationsY[1]=0.6; locationsZ[1]=0.2;
    locationsX[2]=0.35;  locationsY[2]=0.6; locationsZ[2]=0.2;
    locationsX[3]=-0.15; locationsY[3]=1.0; locationsZ[3]=0.3;
    locationsX[4]=-0.35; locationsY[4]=1.4; locationsZ[4]=0.25;
    locationsX[5]=0.35;  locationsY[5]=1.4; locationsZ[5]=0.25;
    locationsX[6]=0.15;  locationsY[6]=1.0; locationsZ[6]=0.3;
    locationsX[7]=0.0;   locationsY[7]=1.5; locationsZ[7]=0.0; 
    // Index 0 Init
    CROP_POINTS[0] = 0.0f;
    CROP_GROWTH[0] = 100.0f; 
    CROP_POINTS[1]=6; CROP_POINTS[2]=7; CROP_POINTS[3]=5; 
    CROP_POINTS[4]=11; CROP_POINTS[5]=3; CROP_POINTS[6]=8;
    CROP_GROWTH[1]=6; CROP_GROWTH[2]=8; CROP_GROWTH[3]=5; 
    CROP_GROWTH[4]=12; CROP_GROWTH[5]=3; CROP_GROWTH[6]=9;
    bonus = 0; bonusesCollected = 0;
    currentCrop = 5; 
    astronautBanned = false; 
}
void start() {
    currentCrop = 4; // Melon
    doIt(2); 
    game.BuySprinkler();
    game.DeploySprinkler(1, 2);
    game.SetSprinklerInterval(1, CROP_GROWTH[currentCrop]);
    game.EnableSprinkler(1);
    hasSprinkler = true;
    game.MovePlot(5);
    if (game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut()) {
        game.MovePlot(4);
        game.MoveAstronaut();
        game.SetWait(0.1f);
        bonus = game.GetBonusCrop();
        if (bonus < 1 || bonus > 6) {
            bonus = 0;
            astronautBanned = true;
        }
        game.LeaveAstronaut();
    } else {
        game.MoveAstronaut();
        game.SetWait(0.1f);
        bonus = game.GetBonusCrop();
        if (bonus < 1 || bonus > 6) {
            bonus = 0;
            astronautBanned = true;
        }
        game.LeaveAstronaut();
        game.MovePlot(4);
    }
    doIt(1);
}
// --- MAIN LOOP ---
void loop() {
    if (!ready) init();
    static bool started = false;
    if (!started) {
        start();
        started = true;
    }
    while (true) {
        if (game.GetTime() >= 236.0f) break;
        doIt(3);
        if (game.GetTime() >= 236.0f) break;
        if (bonusesCollected < 3 && bonus == 0 && !astronautBanned && !(game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut())) {
            game.MoveAstronaut();
            if (game.GetTime() >= 236.0f) break;
            game.SetWait(0.1f);
            bonus = game.GetBonusCrop();
            if (bonus < 1 || bonus > 6) {
                bonus = 0;
                astronautBanned = true;
            }
            game.LeaveAstronaut();
            locateBonusPlot();
        } else if (game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut()) {
            int p = 0;
            float pps = 0.0f;
            for (int i = 1; i <= 6; i++) {
                if (states[i] != HARV) continue;
                if (CROP_POINTS[cropAtPlot[i]]/max(timeTo(i), timeOfNext[i]-game.GetTime()) > pps) {
                    p = i;
                    pps = CROP_POINTS[cropAtPlot[i]]/max(timeTo(i), timeOfNext[i]-game.GetTime());
                }
            }
            if (p == 0) {
                if (bonusesCollected < 3 && bonus == 0) {
                    game.MoveAstronaut();
                    bonus = game.GetBonusCrop();
                    game.LeaveAstronaut();
                }
            } else {
                game.MovePlot(p);
                float score1 = game.GetHarvestScore();
                game.HarvestCrop(p);
                float score2 = game.GetHarvestScore();
                while (score2 - score1 < CROP_POINTS[cropAtPlot[p]]) {
                    game.MovePlot(p);
                    score1 = score2;
                    game.SetWait(max(0.0f, timeOfNext[p]-game.GetTime()));
                    game.HarvestCrop(p);
                    score2 = game.GetHarvestScore();
                }
                if (bonus == cropAtPlot[p]) { 
                    bonusesCollected++; 
                    bonus = 0; 
                }
                cropAtPlot[p] = 0;
                states[p] = PLANT;
            }
            while ((game.OpponentAtAstronaut() || game.OpponentGoingToAstronaut()) && distanceTo(locationsX[7], locationsY[7], locationsZ[7]) > 0.01) {
                game.MoveAstronaut();
            }
            bonus = game.GetBonusCrop();
            game.LeaveAstronaut();
        }
        if (bonusesCollected < 3 && bonus != 0 && (pbc == 6 || pbc == 4)) {
            currentCrop = bonus;
            if (currentCrop <= 0) currentCrop = 5;
            game.MovePlot(6);
            game.SetWait(max(0.0f, timeOfNext[6]-game.GetTime()));
            changeState(6);
        } else {
            doIt(6);
        }
        if (game.GetTime() >= 236.0f) break;
        if (states[2] == HARV) {
            game.DisableSprinkler(1);
            doIt(2);
            float interval = CROP_GROWTH[currentCrop];
            if (interval < 0.1f) interval = 3.0f;
            game.SetSprinklerInterval(1, interval);
            game.EnableSprinkler(1);
            if (game.GetTime() >= 236.0f) break;
        }
        if (shouldRefill(1) && !game.OpponentAtWatering() && !game.OpponentGoingToWatering()) {
            game.MoveWatering();
            if (game.GetTime() >= 236.0f) break;
            game.FillWateringCan();
            if (game.GetTime() >= 236.0f) break;
        } else if (game.OpponentAtWatering() || game.OpponentGoingToWatering()) {
            int p = 0;
            float pps = 0.0f;
            for (int i = 1; i <= 6; i++) {
                if (states[i] != HARV) continue;
                if (CROP_POINTS[cropAtPlot[i]]/max(timeTo(i), timeOfNext[i]-game.GetTime()) > pps) {
                    p = i;
                    pps = CROP_POINTS[cropAtPlot[i]]/max(timeTo(i), timeOfNext[i]-game.GetTime());
                }
            }
            if (p == 0) {
                if (bonusesCollected < 3 && bonus == 0) {
                    game.MoveAstronaut();
                    bonus = game.GetBonusCrop();
                    game.LeaveAstronaut();
                }
            } else {
                game.MovePlot(p);
                float score1 = game.GetHarvestScore();
                game.HarvestCrop(p);
                float score2 = game.GetHarvestScore();
                while (score2 - score1 < CROP_POINTS[cropAtPlot[p]]) {
                    game.MovePlot(p);
                    score1 = score2;
                    game.SetWait(max(0.0f, timeOfNext[p]-game.GetTime()));
                    game.HarvestCrop(p);
                    score2 = game.GetHarvestScore();
                }
                if (bonus == cropAtPlot[p]) { 
                    bonusesCollected++; 
                    bonus = 0; 
                }
                cropAtPlot[p] = 0;
                states[p] = PLANT;
            }
            while ((game.OpponentAtWatering() || game.OpponentGoingToWatering()) && distanceTo(locationsX[0], locationsY[0], locationsZ[0]) > 0.01) {
                game.MoveWatering();
            }
            game.FillWateringCan();
        }
        if (game.GetTime() >= 233.5f) break;
        doIt(1);
        if (game.GetTime() >= 236.0f) break;
    }
}
//End page main
11 Alliance 11 — Team Zenith

“A global alliance from the United States, Turkey, and Italy.”

Don Lorenzo Milani Lumberbots Mount Olive MORT SpaceIST
</> View Source Code
//Begin page main
//Team Zenith Zero Robotics 2026 Season Code (Honorable mention SpaceIST-ATP)
void init() {
}
void farmPlotAstronaut(int plot, int crop) {
    if (plot == 5) {
        game.MoveAstronaut();
        while (game.OpponentAtAstronaut()) {
            game.SetWait(1);
            game.MoveAstronaut();
        }
        int bonusextra = game.GetBonusCrop();
        game.LeaveAstronaut();
        game.MovePlot(plot);
        game.HarvestCrop(plot);
        game.PlantCrop(plot, bonusextra);
        game.WaterCrop(plot);
    }
    if (plot != 5) {
        game.MovePlot(plot);
        game.HarvestCrop(plot);
        game.PlantCrop(plot, crop);
        game.WaterCrop(plot);
    }
}
void farmPlot(int plot, int crop) {
    game.MovePlot(plot);
    game.HarvestCrop(plot);
    game.PlantCrop(plot, crop);
    game.WaterCrop(plot);
}
void waterPlot(int plot) {
    game.MovePlot(plot);
    game.WaterCrop(plot);
}
void harvestPlot(int plot) {
    game.MovePlot(plot);
    game.HarvestCrop(plot);
}
void refillWater() {
    game.MoveWatering();
    while (game.OpponentAtWatering()) {
        game.SetWait(0.5);
        game.MoveWatering();
    }
    game.FillWateringCan();
}
void loop() {
    int route[] = {1, 3, 4, 5, 6, 2};
    int cropsfirst[] = {4, 4, 6, 0, 2, 4};
    int cropssecond[] = {1, 6, 2, 0, 3, 4};
    int cropsthird[] = {2, 6, 2, 0, 3, 5};
    int cropsfourth[] = {4, 4, 3};
    for (int i = 0; i < 6; i++) {
        farmPlotAstronaut(route[i], cropsfirst[i]);
    }
    refillWater();
    for (int i = 0; i < 6; i++) {
        waterPlot(route[i]);
    }
    refillWater();
    for (int i = 0; i < 6; i++) {
        farmPlotAstronaut(route[i], cropssecond[i]);
    }
    refillWater();
    for (int i = 0; i < 6; i++) {
        waterPlot(route[i]);
    }
    refillWater();
    for (int i = 0; i < 6; i++) {
        farmPlotAstronaut(route[i], cropsthird[i]);
    }
    refillWater();
    for (int i = 0; i < 6; i++) {
        waterPlot(route[i]);
    }
    refillWater();
    for (int i = 0; i < 3; i++) {
        farmPlotAstronaut(route[i], cropsfourth[i]);
    }
    refillWater();
    for (int i = 0; i < 3; i++) {
        waterPlot(route[i]);
    }
    for (int i = 0; i < 3; i++) {
        harvestPlot(route[i]);
    }
    float dist = game.GetDistanceTraveled();
    int plots = game.GetPlotsExplored();
    int visits = game.GetAstronautVisits();
    int bonus = game.GetCurrentBonusIndex();
    float score = game.GetScore();
}
//End page main
12 Alliance 12 — Space Sprouts

“St. Helena High School, Emerald High School, Cookies & Nazarbayev Intellectual School.”

Cookies Emerald High School Nazarbayev Intellectual School St. Helena High School
</> View Source Code
bool GoingToAstronaut;
bool AtAstronaut;
float BonusCrop;
float BonusCropTime;
float NextPlot;
bool GoingToWater;
bool AtWater;
float BonusPlot2;
float BonusPlot3;
int AstronautVisits;
float BonusPlot1;
float RemPlot1;
float RemPlot2;
float RemPlot3;
float CropWaitTime;
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 Astronaut
void Astronaut() {
  AtAstronaut = game.OpponentAtAstronaut();
  GoingToAstronaut = game.OpponentGoingToAstronaut();
  AstronautVisits = game.GetAstronautVisits();
}
//End page Astronaut
//Begin page Crop Info
void Crop_Info() {
  BonusCrop = game.GetBonusCrop();
}
//End page Crop Info
//Begin page Cycle 1
void Cycle_1() {
  game.MovePlot(1);
  game.PlantCrop(1, 1);
  game.WaterCrop(1);
  NextPlot = NextPlot + 1;
  game.MovePlot(3);
  game.PlantCrop(3, 3);
  game.WaterCrop(3);
  NextPlot = NextPlot + 1;
  game.MovePlot(4);
  game.PlantCrop(4, 4);
  game.WaterCrop(4);
  NextPlot = NextPlot + 1;
  Astronaut();
  if ((GoingToAstronaut || AtAstronaut) == true) {
    if (NextPlot == 3) {
      game.MovePlot(5);
      game.PlantCrop(5, 5);
      game.WaterCrop(5);
      NextPlot = NextPlot + 1;
      Astronaut();
      if ((GoingToAstronaut || AtAstronaut) == true) {
        game.MovePlot(6);
        game.PlantCrop(6, 6);
        game.WaterCrop(6);
        NextPlot = NextPlot + 1;
        Astronaut();
        if ((GoingToAstronaut || AtAstronaut) == true) {
          game.MovePlot(2);
          game.PlantCrop(2, 2);
          game.WaterCrop(2);
          NextPlot = NextPlot + 1;
          Astronaut();
        }
      } else {
        game.MoveAstronaut();
        game.GetCropInfo(game.GetBonusCrop());
        Crop_Info();
        BonusPlot1 = game.GetBonusCrop();
        game.MovePlot(2);
        game.PlantCrop(2, 2);
        game.WaterCrop(2);
        NextPlot = NextPlot + 1;
        Water();
      }
      game.MoveAstronaut();
      game.GetCropInfo(game.GetBonusCrop());
      Crop_Info();
      BonusPlot1 = game.GetBonusCrop();
      game.MovePlot(2);
      game.PlantCrop(2, 2);
      game.WaterCrop(2);
      NextPlot = NextPlot + 1;
      Water();
    } else {
      game.MoveAstronaut();
      game.GetCropInfo(game.GetBonusCrop());
      Crop_Info();
      BonusPlot1 = game.GetBonusCrop();
      game.MovePlot(6);
      game.PlantCrop(6, 6);
      game.WaterCrop(6);
      NextPlot = NextPlot + 1;
      game.MovePlot(2);
      game.PlantCrop(2, 2);
      game.WaterCrop(2);
      NextPlot = NextPlot + 1;
      Water();
    }
  } else {
    game.MoveAstronaut();
    game.GetCropInfo(game.GetBonusCrop());
    Crop_Info();
    BonusPlot1 = game.GetBonusCrop();
    game.MovePlot(5);
    game.PlantCrop(5, 5);
    game.WaterCrop(5);
    NextPlot = NextPlot + 1;
    game.MovePlot(6);
    game.PlantCrop(6, 6);
    game.WaterCrop(6);
    NextPlot = NextPlot + 1;
    game.MovePlot(2);
    game.PlantCrop(2, 2);
    game.WaterCrop(2);
    Water();
  }
  NextPlot = 0;
}
//End page Cycle 1
//Begin page Cycle 2
void Cycle_2() {
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  Water();
}
//End page Cycle 2
//Begin page Cycle 3
void Cycle_3() {
  game.MovePlot(BonusCrop);
  game.HarvestCrop(BonusCrop);
  game.PlantCrop(BonusCrop, BonusCrop);
  game.WaterCrop(BonusCrop);
  Astronaut();
  if ((GoingToAstronaut || AtAstronaut) == true) {
    game.MoveToVoid(0, 1.2, 0);
    game.SetWait(1);
    game.MoveAstronaut();
    game.GetCropInfo(game.GetBonusCrop());
    Crop_Info();
    BonusPlot2 = game.GetBonusCrop();
  } else {
    game.MoveAstronaut();
    game.GetCropInfo(game.GetBonusCrop());
    Crop_Info();
    BonusPlot2 = game.GetBonusCrop();
  }
  game.MovePlot(BonusCrop);
  game.HarvestCrop(BonusCrop);
  game.PlantCrop(BonusCrop, BonusCrop);
  game.WaterCrop(BonusCrop);
  Astronaut();
  if ((GoingToAstronaut || AtAstronaut) == true) {
    game.MoveToVoid(0, 1.2, 0);
    game.SetWait(1);
    game.MoveAstronaut();
    game.GetCropInfo(game.GetBonusCrop());
    Crop_Info();
    BonusPlot3 = game.GetBonusCrop();
  } else {
    game.MoveAstronaut();
    game.GetCropInfo(game.GetBonusCrop());
    Crop_Info();
    BonusPlot3 = game.GetBonusCrop();
  }
  game.MovePlot(BonusCrop);
  game.HarvestCrop(BonusCrop);
  game.PlantCrop(BonusCrop, BonusCrop);
  game.WaterCrop(BonusCrop);
  Rem1();
  game.MovePlot(RemPlot1);
  game.HarvestCrop(RemPlot1);
  game.PlantCrop(RemPlot1, RemPlot1);
  game.WaterCrop(RemPlot1);
  Rem2();
  game.MovePlot(RemPlot2);
  game.HarvestCrop(RemPlot2);
  game.PlantCrop(RemPlot2, RemPlot2);
  game.WaterCrop(RemPlot2);
  Rem3();
  game.MovePlot(RemPlot3);
  game.HarvestCrop(RemPlot3);
  game.PlantCrop(RemPlot3, RemPlot3);
  game.WaterCrop(RemPlot3);
  Water();
}
//End page Cycle 3
//Begin page Cycle 4
void Cycle_4() {
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  Water();
}
//End page Cycle 4
//Begin page Cycle 5
void Cycle_5() {
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.PlantCrop(1, 1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.PlantCrop(3, 3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.PlantCrop(4, 4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.PlantCrop(5, 5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.PlantCrop(6, 6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.PlantCrop(2, 2);
  game.WaterCrop(2);
  Water();
}
//End page Cycle 5
//Begin page Cycle 6
void Cycle_6() {
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  Water();
}
//End page Cycle 6
//Begin page Cycle 7
void Cycle_7() {
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.PlantCrop(1, 1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.PlantCrop(3, 3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.PlantCrop(4, 4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.PlantCrop(5, 5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.PlantCrop(6, 6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
  game.PlantCrop(2, 2);
  game.WaterCrop(2);
  Water();
}
//End page Cycle 7
//Begin page Cycle 8
void Cycle_8() {
  game.MovePlot(1);
  game.WaterCrop(1);
  game.MovePlot(3);
  game.WaterCrop(3);
  game.MovePlot(4);
  game.WaterCrop(4);
  game.MovePlot(5);
  game.WaterCrop(5);
  game.MovePlot(6);
  game.WaterCrop(6);
  game.MovePlot(2);
  game.WaterCrop(2);
  game.MovePlot(1);
  game.HarvestCrop(1);
  game.MovePlot(3);
  game.HarvestCrop(3);
  game.MovePlot(4);
  game.HarvestCrop(4);
  game.MovePlot(5);
  game.HarvestCrop(5);
  game.MovePlot(6);
  game.HarvestCrop(6);
  game.MovePlot(2);
  game.HarvestCrop(2);
}
//End page Cycle 8
//Begin page Rem1
void Rem1() {
  if (BonusPlot1 != 1 && BonusPlot2 != 1 && BonusPlot3 != 1) {
    RemPlot1 = 1;
  } else {
    if (BonusPlot1 != 2 && BonusPlot2 != 2 && BonusPlot3 != 2) {
      RemPlot1 = 2;
    } else {
      if (BonusPlot1 != 3 && BonusPlot2 != 3 && BonusPlot3 != 3) {
        RemPlot1 = 3;
      } else {
        if (BonusPlot1 != 4 && BonusPlot2 != 4 && BonusPlot3 != 1) {
          RemPlot1 = 4;
        } else {
          if (BonusPlot1 != 5 && BonusPlot2 != 5 && BonusPlot3 != 5) {
            RemPlot1 = 5;
          } else {
            RemPlot1 = 6;
          }
        }
      }
    }
  }
}
//End page Rem1
//Begin page Rem2
void Rem2() {
  if (BonusPlot1 != 1 && BonusPlot2 != 1 && BonusPlot3 != 1 && RemPlot1 != 1) {
    RemPlot2 = 1;
  } else {
    if (BonusPlot1 != 2 && BonusPlot2 != 2 && BonusPlot3 != 2 && RemPlot1 != 2) {
      RemPlot2 = 2;
    } else {
      if (BonusPlot1 != 3 && BonusPlot2 != 3 && BonusPlot3 != 3 && RemPlot1 != 3) {
        RemPlot2 = 3;
      } else {
        if (BonusPlot1 != 4 && BonusPlot2 != 4 && BonusPlot3 != 4 && RemPlot1 != 4) {
          RemPlot2 = 4;
        } else {
          if (BonusPlot1 != 5 && BonusPlot2 != 5 && BonusPlot3 != 5 && RemPlot1 != 5) {
            RemPlot2 = 5;
          } else {
            RemPlot2 = 6;
          }
        }
      }
    }
  }
}
//End page Rem2
//Begin page Rem3
void Rem3() {
  if (BonusPlot1 != 1 && BonusPlot2 != 1 && BonusPlot3 != 1 && RemPlot1 != 1 && RemPlot2 != 1) {
    RemPlot3 = 1;
  } else {
    if (BonusPlot1 != 2 && BonusPlot2 != 2 && BonusPlot3 != 2 && RemPlot1 != 2 && RemPlot2 != 2) {
      RemPlot3 = 2;
    } else {
      if (BonusPlot1 != 3 && BonusPlot2 != 3 && BonusPlot3 != 3 && RemPlot1 != 3 && RemPlot2 != 3) {
        RemPlot3 = 3;
      } else {
        if (BonusPlot1 != 4 && BonusPlot2 != 4 && BonusPlot3 != 4 && RemPlot1 != 4 && RemPlot2 != 4) {
          RemPlot3 = 4;
        } else {
          if (BonusPlot1 != 5 && BonusPlot2 != 5 && BonusPlot3 != 5 && RemPlot1 != 5 && RemPlot2 != 5) {
            RemPlot3 = 5;
          } else {
            RemPlot3 = 6;
          }
        }
      }
    }
  }
}
//End page Rem3
//Begin page Water
void Water() {
  AtWater = game.OpponentAtWatering();
  GoingToWater = game.OpponentGoingToWatering();
  if (GoingToWater == true || AtWater == true) {
    game.MoveToVoid(0, 0, 0.25);
    game.SetWait(1);
    game.MoveWatering();
    game.FillWateringCan();
  } else {
    game.MoveWatering();
    game.FillWateringCan();
  }
}
//End page Water
//Begin page init
void init() {
  AstronautVisits = 0;
  GoingToAstronaut = 0;
  AtAstronaut = 0;
  BonusCrop = 0;
  CropWaitTime = 0;
  BonusCropTime = 0;
  NextPlot = 0;
  GoingToWater = 0;
  AtWater = 0;
  BonusPlot1 = 0;
  BonusPlot2 = 0;
  BonusPlot3 = 0;
  RemPlot1 = 0;
  RemPlot2 = 0;
  RemPlot3 = 0;
}
//End page init
//Begin page main
void loop() {
  Cycle_1();
  Cycle_2();
  Cycle_3();
  Cycle_4();
  Cycle_5();
  Cycle_6();
  Cycle_7();
  Cycle_8();
  game.EndGame();
}
//End page main

Zero Robotics · MIT Space Enabled Lab · zerorobotics.mit.edu