Karel 2.4.2 - quantizeBits
Fri Aug 12 2022 10:49:09 GMT+0000 (Coordinated Universal Time)
Saved by
@bibberhug
void quantizeBits(){ // *** 0 bugs ***
repeat(10){ //repeat 10 times for 10 lines, checking every time
if(!onBeeper()){if(frontIsClear()){moveForward();}} //skip an emtpy line
else{ //if on Beeper, do initial scan movement and choice
qB_move();
qB_choice();
}
}
}
void qB_move(){
turnLeft(); repeat(5){if(frontIsClear()){moveForward();}}
}
void qB_choice(){
//choose between line is >5 or <6
if(!onBeeper()){qB_smaller();}
else{qB_greater();}
}
void qB_greater(){ //if line is >5
repeat(4){ //go remaining tiles and place Beepers
moveForward();
if(!onBeeper()){dropBeeper();}
}
//return to bottom and step into next line
turnAround(); while(frontIsClear()){moveForward();}
turnLeft(); if(frontIsClear()){moveForward();}
}
void qB_smaller(){ //if line is <6
turnAround();
repeat(5){ //return to bottom and pick up all Beepers
if(frontIsClear()){moveForward();}
if(onBeeper()){pickBeeper();}
}
//step into next line
turnLeft(); if(frontIsClear()){moveForward();}
}
content_copyCOPY
Comments