“1.1.4 Your First Karel Program move(); move(); move(); move(); takeBall(); 1.1.5 Short Stack move(); putBall(); putBall(); move(); 1.2.4 Make a Tower move(); turnLeft(); putBall(); move(); putBall(); move(); putBall(); move(); turnLeft(); turnLeft(); turnLeft(); 1.2.5 Pyramid of Karel putBall(); move(); putBall(); move(); putBall(); turnLeft(); move(); putBall(); turnLeft(); move(); putBall(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); turnLeft(); turnLeft(); move(); putBall(); 1.3.4 Slide Karel putBall(); move(); turnRight(); move(); putBall(); turnLeft(); move(); turnRight(); move(); putBall(); turnLeft(); function turnRight() { turnLeft(); turnLeft(); turnLeft(); }, 1.3.5 Fireman Karel turnRight(); move(); move(); move(); turnLeft(); function turnRight(){ turnLeft(); turnLeft(); turnLeft(); }, 1.4.4 Pancakes makePancakes(); move(); makePancakes(); move(); makePancakes(); move(); function makePancakes(){ move(); putBall(); putBall(); putBall(); }, 1.4.5 Mario Karel turnLeft(); move(); move(); move(); turnRight(); move(); collectCoins(); turnLeft(); move(); turnRight(); move(); move(); turnRight(); move(); collectCoins(); move(); turnLeft(); move(); move(); turnLeft(); move(); collectCoins(); move(); turnRight(); move(); move(); turnRight(); move(); collectCoins(); move(); move(); move(); turnLeft(); function turnRight(){ turnLeft(); turnLeft(); turnLeft(); }, function collectCoins(){ takeBall(); takeBall(); }, 1.5.4 Pancakes with Start function start(){ move(); makePancakes(); move(); move(); makePancakes(); move(); move(); makePancakes(); move(); }, function makePancakes(){ putBall(); putBall(); putBall(); }, 1.6.4 The Two Towers function start(){ runtoPancakes(); putPancakes(); goBack(); putPancakes(); move(); turnRight(); }, function runtoPancakes(){ move(); turnLeft(); }, function putPancakes(){ putBall(); move(); putBall(); move(); putBall(); }, function goBack(){ turnRight(); move(); turnRight(); move(); move(); turnLeft(); move(); turnLeft(); }, function turnRight(){ turnLeft(); turnLeft(); turnLeft(); }, 1.7.4 The Two Towers + Comments function start(){ runtoPancakes(); putPancakes(); goBack(); putPancakes(); move(); turnRight(); }, /* * Precondition:starting point,Karel is facing east * Postcondition: Karel is inline to drop the balls */ function runtoPancakes(){ move(); turnLeft(); }, function putPancakes(){ putBall(); move(); putBall(); move(); putBall(); }, function goBack(){ turnRight(); move(); turnRight(); move(); move(); turnLeft(); move(); turnLeft(); }, function turnRight(){ turnLeft(); turnLeft(); turnLeft(); }, 1.8.4 The Two Towers + SuperKarel function start(){ runtoPancakes(); putPancakes(); goBack(); putPancakes(); move(); turnRight(); }, /* * allows karel to get in line to drop the balls */ function runtoPancakes(){ move(); turnLeft(); }, /* * Karel drops all 3 balls in the appropriate position */ function putPancakes(){ putBall(); move(); putBall(); move(); putBall(); }, function goBack(){ turnRight(); move(); turnRight(); move(); move(); turnLeft(); move(); turnLeft(); }, “
Leave a Reply