StoneMason

0

java

목록 보기
2/11
post-thumbnail

import stanford.karel.*;

public class StoneMasonKarel extends SuperKarel {

public void run() {
	fixBeeper();
}

private void fixBeeper() {
	upColumn();
	downColumn();
    if(frontIsClear()) {
        moveToNextColumn();
        fixBeeper();
    }
}   

private void upColumn() {
	turnLeft();
    while(frontIsClear()) {
        if(noBeepersPresent()) {
            putBeeper();
        }
        move();
    }
    if(noBeepersPresent()) {
        putBeeper();
    }
}

private void downColumn() {
	turnAround();
    while(frontIsClear()) {
        move();
    }
    turnLeft();
}

private void moveToNextColumn() {
    for(int i=0; i<4; i++) {
        move();
    }
}

}

profile
초보 데이터분석가의 기록 공간입니다 😁

0개의 댓글