Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.16.4
- public class SuperCleanupKarel extends SuperKarel{
- public void run(){
- faceNorth();
- while(frontIsClear()){
- cleanRow();
- faceNorth();
- move();
- }
- cleanRow();
- }
- private void faceNorth(){
- while(notFacingNorth()){
- turnLeft();
- }
- }
- private void faceEast(){
- while(notFacingEast()){
- turnLeft();
- }
- }
- private void cleanRow(){
- faceEast();
- if(frontIsClear()){
- while(frontIsClear()){
- if(ballsPresent()){
- takeBall();
- }
- move();
- }
- if(ballsPresent()){
- takeBall();
- }
- }
- else{
- turnAround();
- if(frontIsClear()){
- while(frontIsClear()){
- if(ballsPresent()){
- takeBall();
- }
- move();
- }
- }
- if(ballsPresent()){
- takeBall();
- }
- }
- }
- }
- 1.16.5
- public class DoubleTennisBallsKarel extends SuperKarel
- {
- public void run()
- {
- move();
- while(ballsPresent()){
- takeBall();
- turnLeft();
- move();
- turnRight();turnRight();
- putBall();
- move();
- turnLeft();
- }
- turnLeft();
- move();
- turnRight();
- while(ballsPresent()){
- takeBall();
- turnRight();
- move();
- putBall();putBall();
- turnAround();
- move();
- turnRight();
- }
- turnAround();
- move();
- turnLeft();
- move();
- turnLeft();
- }
- }
- 1.16.5
- public class MidpointKarel extends SuperKarel
- {
- public void run()
- {
- turnLeft();
- while(frontIsClear()){
- move();
- }
- turnAround();
- while(frontIsClear()){
- move();
- if(frontIsClear()){
- move();
- }
- else{
- break;
- }
- turnLeft();
- if(frontIsClear()){
- move();
- }
- turnRight();
- }
- putBall();
- turnLeft();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement