Lecture/컴퓨터프로그래밍및실습/SteepHurdle
Retired DISLab
< Lecture | 컴퓨터프로그래밍및실습
문제) 그림과 같이 장애물이 있을 경우 장애물을 넘어 마지막 지점까지 Karel을 이동시키려면?
import stanford.karel.SuperKarel; public class SteepChase extends SuperKarel { public void run() { for (int i = 0; i < 8; i++) { if (frontIsClear()) { move(); } else { jumpHurdle(); } } } private void jumpHurdle() { ascendHurdle(); move(); descendHurdle(); } private void ascendHurdle() { turnLeft(); while (rightIsBlocked()) { move(); } turnRight(); } private void descendHurdle() { turnRight(); moveToWall(); turnLeft(); } private void moveToWall() { while (frontIsClear()) { move(); } } public static void main(String[] args) { String[] newArgs = new String[args.length + 1]; System.arraycopy(args, 0, newArgs, 0, args.length); newArgs[args.length] = "code=" + new SecurityManager(){ public String className() { return this.getClassContext()[1].getCanonicalName(); } }.className(); SuperKarel.main(newArgs); } }