<jupyter_start><jupyter_text>Reset the state, we track sectors being scanned and the resoruce found<jupyter_code>#!rover

RoverBrain.Perceive = () => {
    if (currentSector == null){
        return;
    }

    if (currentSector.CapturedFrame == null) {
        Task.Delay(500).Wait();
        currentSector.CapturedFrame = RoverBody.Camera.GetFrame().Focus();
    }
};
#!rover
RoverBody.Reset();
#!rover
RoverBrain.ClearState = () => {
    foreach (var sector in scannedSectors) {
        sector.Reset();
    }

    currentSector = null;
    RoverBody.Reset();
};<jupyter_output><empty_output><jupyter_text>Let's capture the current sector frame<jupyter_code>#!rover

RoverBrain.Act = () => { 
    if(currentSector != null){
        RoverBody.TiltController.GoToSector(currentSector);
    }   
};<jupyter_output><empty_output><jupyter_text>Define the planning logic:1. Terminate when all sector have been visited and image was aquired2. Classify the current sector if needed3. Blink lights if a classification has been aquired<jupyter_code>#!rover

RoverBrain.Plan = () => {
    if (AllSectorScanned(scannedSectors)){
        RoverBody.AllLightsOff();
        return PlanningResult.NoPlan;
    }  

    if (currentSector != null) {
       
        currentSector.Marked = true;
    }   
    
    currentSector = scannedSectors.FirstOrDefault(s => s.Marked == false);
    
    RoverBody.AllLightsOff();

    return currentSector != null 
        ? PlanningResult.NewPlan 
        : PlanningResult.NoPlan;    
};
#!rover

RoverBrain.Plan = () => {
    if (AllSectorScanned(scannedSectors)){
        RoverBody.AllLightsOff();
        return PlanningResult.NoPlan;
    }  

    if (currentSector != null) {
       
        currentSector.Marked = true;
    }

    if (AnalyseSectorForEnergyCards(currentSector))
    {
        RoverBody.BlinkAllLights();
    }else {
        RoverBody.AllLightsOff();
    }
    
    currentSector = scannedSectors.FirstOrDefault(s => s.Marked == false);

    RoverBody.AllLightsOff();

    return currentSector != null 
        ? PlanningResult.NewPlan 
        : PlanningResult.NoPlan;  
};
#!rover

RoverBrain.Plan = () => {

    if (AllSectorScanned(scannedSectors) || EnoughResourcesFound(scannedSectors, 3)){
        RoverBody.AllLightsOff();
        return PlanningResult.NoPlan;
    }  

    if (currentSector != null) {       
        currentSector.Marked = true;
    }
   
    if (AnalyseSectorForResource(currentSector))
    {
        RoverBody.BlinkAllLights();
    }else {
        RoverBody.AllLightsOff();
    }
    
    currentSector = scannedSectors.FirstOrDefault(s => s.Marked == false);

    RoverBody.AllLightsOff();

    return currentSector != null 
        ? PlanningResult.NewPlan 
        : PlanningResult.NoPlan;  
};<jupyter_output><empty_output><jupyter_text>Let's move the camera to the sector we planned to scan<jupyter_code>#!rover
RoverBrain.ClearState();<jupyter_output><empty_output><jupyter_text>Let's explore the sectors<jupyter_code>#!rover
scannedSectors
    .Where(s => s.ClassificationResults != null )
    .GroupBy(s => s.ClassificationResults.Prediction.Label)
    .Select(g => new { Label = g.Key, Count = g.Count()})

#!rover
scannedSectors.Count(s => s.Marked == true)
#!rover
scannedSectors.Where(s => s.Marked == true)
#!rover
scannedSectors
#!rover
currentSector
#!rover
testSector
#!rover
AllSectorScanned(scannedSectors)
#!rover
currentSector = scannedSectors.FirstOrDefault(s => s.Marked == false);<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup