Skip to content

Latest commit

 

History

History
42 lines (40 loc) · 752 Bytes

2.4.2 quantizeBits.md

File metadata and controls

42 lines (40 loc) · 752 Bytes

2.4.2 quantizeBits

void quantizeBits() {
    repeat (10) {
        if (onBeeper()) {
            updateCode();   
        }
        if (frontIsClear()) {
            moveForward();    
        }
    }
}

void updateCode() {
    turnLeft();
    repeat (5) {
        moveForward();
    }
    if (onBeeper()) {
        while (frontIsClear()) {
            moveForward();
            if (!onBeeper()) {
                dropBeeper();
            }
        }
        turnAround();
        while (frontIsClear()) {
            moveForward();
        }
    } else {
        turnAround();
        repeat (5) {
            moveForward();
            if (onBeeper()) {
                pickBeeper();
            }
        }
    }
    turnLeft();
}