Last active
November 16, 2020 14:59
-
-
Save m4r1vs/6d95780a2e3909e8816c40a484bba3e7 to your computer and use it in GitHub Desktop.
Karel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
F1 = moveForward(); | |
F2 = turnLeft(); | |
F3 = turnAround(); | |
F4 = turnRight(); | |
F5 = pickBeeper(); | |
F6 = dropBeeper(); | |
*/ | |
/* void moveForwardCustom(int length) | |
{ | |
repeat(length) | |
{ | |
moveForward(); | |
} | |
} */ | |
void moveForwardThree() | |
{ | |
repeat(3) | |
{ | |
moveForward(); | |
} | |
} | |
void moveForwardNine() | |
{ | |
repeat(9) | |
{ | |
moveForward(); | |
} | |
} | |
void saveBat() | |
{ | |
turnRight(); | |
moveForward(); | |
turnLeft(); | |
moveForwardThree(); | |
turnLeft(); | |
moveForward(); | |
pickBeeper(); | |
moveForward(); | |
turnLeft(); | |
moveForwardThree(); | |
turnLeft(); | |
moveForward(); | |
dropBeeper(); | |
} | |
void defuseOneBomb() | |
{ | |
moveForwardNine(); | |
pickBeeper(); | |
turnAround(); | |
moveForwardNine(); | |
turnAround(); | |
} | |
/* CLIMB THE STAIRS */ | |
void climbAStair() | |
{ | |
turnLeft(); | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
} | |
void climbTheStairs() | |
{ | |
moveForward(); | |
repeat(6) | |
{ | |
climbAStair(); | |
} | |
} | |
/* FILL THE HOLES */ | |
void fillHole() | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnAround(); | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
} | |
void fillTheHoles() | |
{ | |
repeat(4) | |
{ | |
fillHole(); | |
} | |
} | |
/* MOW THE LAWN */ | |
void mowLawnRow() | |
{ | |
repeat(6) | |
{ | |
moveForward(); | |
pickBeeper(); | |
} | |
} | |
void uTurnLeft() | |
{ | |
moveForward(); | |
turnLeft(); | |
moveForward(); | |
turnLeft(); | |
} | |
void uTurnRight() | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
turnRight(); | |
} | |
void mowTheLawn() | |
{ | |
repeat(2) | |
{ | |
mowLawnRow(); | |
uTurnLeft(); | |
mowLawnRow(); | |
uTurnRight(); | |
} | |
mowLawnRow(); | |
uTurnLeft(); | |
mowLawnRow(); | |
} | |
/* HARVEST THE FIELD */ | |
void climbAStairAndHarvest() | |
{ | |
repeat(4) | |
{ | |
moveForward(); | |
pickBeeper(); | |
turnRight(); | |
moveForward(); | |
turnLeft(); | |
} | |
} | |
void weirdUTurnLeft() | |
{ | |
moveForward(); | |
moveForward(); | |
turnLeft(); | |
moveForward(); | |
moveForward(); | |
turnLeft(); | |
} | |
void harvestTheField() | |
{ | |
climbAStairAndHarvest(); | |
weirdUTurnLeft(); | |
climbAStairAndHarvest(); | |
turnAround(); | |
climbAStairAndHarvest(); | |
weirdUTurnLeft(); | |
climbAStairAndHarvest(); | |
} | |
/* REPAIR THE STREET */ | |
void repairTheStreet() | |
{ | |
repeat(10) | |
{ | |
if (rightIsClear()) | |
{ | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnAround(); | |
moveForward(); | |
turnRight(); | |
} | |
if (frontIsClear()) | |
{ | |
moveForward(); | |
} | |
} | |
} | |
/* CLEAN THE ROOM */ | |
void pickBeeperIfPossible() { | |
if (onBeeper()) | |
{ | |
pickBeeper(); | |
} | |
} | |
void moveForwardNineAndPickBeeper() | |
{ | |
repeat(9) | |
{ | |
pickBeeperIfPossible(); | |
moveForward(); | |
} | |
} | |
void cleanTheRoom() | |
{ | |
repeat(5) | |
{ | |
moveForwardNineAndPickBeeper(); | |
turnLeft(); | |
pickBeeperIfPossible(); | |
moveForward(); | |
turnLeft(); | |
moveForwardNineAndPickBeeper(); | |
if (rightIsClear()) { | |
turnRight(); | |
pickBeeperIfPossible(); | |
moveForward(); | |
turnRight(); | |
} | |
} | |
} | |
/* DEFUSE TWO BOMBS */ | |
void defuseTwoBombs() | |
{ | |
defuseOneBomb(); | |
turnLeft(); | |
defuseOneBomb(); | |
} | |
/* PRACTICE HOME RUN */ | |
void practiceHomeRun() | |
{ | |
repeat(4) | |
{ | |
moveForwardNine(); | |
pickBeeper(); | |
turnLeft(); | |
} | |
} | |
/* SAVE THE FLOWER */ | |
void climbBigStair() | |
{ | |
pickBeeperIfPossible(); | |
turnLeft(); | |
moveForward(); | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
} | |
void descentBigStair() | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
moveForward(); | |
turnLeft(); | |
} | |
void saveTheFlower() | |
{ | |
moveForward(); | |
repeat(4) | |
{ | |
climbBigStair(); | |
} | |
dropBeeper(); | |
repeat(4) | |
{ | |
descentBigStair(); | |
} | |
} | |
/* TILE THE FLOOR */ | |
void moveForwardAndDropBeeper() | |
{ | |
moveForward(); | |
dropBeeper(); | |
} | |
void tileTheFloor() | |
{ | |
dropBeeper(); | |
repeat(3) | |
{ | |
repeat(9) | |
{ | |
moveForwardAndDropBeeper(); | |
} | |
turnLeft(); | |
} | |
repeat(87) | |
{ | |
if (!beeperAhead()) | |
{ | |
moveForwardAndDropBeeper(); | |
} else { | |
turnLeft(); | |
} | |
} | |
turnLeft(); | |
moveForward(); | |
} | |
/* STEAL OLYMPIC FIRE */ | |
void stealOlympicFire() | |
{ | |
moveForward(); | |
repeat(6) | |
{ | |
climbAStair(); | |
} | |
pickBeeper(); | |
moveForward(); | |
turnRight(); | |
repeat(6) | |
{ | |
moveForward(); | |
} | |
turnLeft(); | |
moveForward(); | |
} | |
/* REMOVE THE TILES */ | |
void moveForwardAndPickBeeper() | |
{ | |
moveForward(); | |
pickBeeper(); | |
} | |
void removeTheTiles() | |
{ | |
pickBeeper(); | |
repeat(3) | |
{ | |
repeat(9) | |
{ | |
moveForwardAndPickBeeper(); | |
} | |
turnLeft(); | |
} | |
repeat(87) | |
{ | |
if (beeperAhead()) | |
{ | |
moveForwardAndPickBeeper(); | |
} else { | |
turnLeft(); | |
} | |
} | |
turnLeft(); | |
moveForward(); | |
} | |
/* WALK THE LABYRINTH */ | |
void walkTheLabyrinth() | |
{ | |
repeat(81) | |
{ | |
if (onBeeper()) | |
{ | |
pickBeeper(); | |
} | |
else | |
{ | |
if (frontIsClear()) { | |
moveForward(); | |
} | |
if (rightIsClear()) { | |
turnRight(); | |
moveForward(); | |
} | |
if (leftIsClear()) { | |
turnLeft(); | |
moveForward(); | |
} | |
} | |
} | |
} | |
/* HANG THE LAMPIONS */ | |
void moveToWall() | |
{ | |
while(frontIsClear()) | |
{ | |
moveForward(); | |
} | |
} | |
void hangTheLampions() | |
{ | |
repeat(10) | |
{ | |
pickBeeper(); | |
turnLeft(); | |
moveToWall(); | |
dropBeeper(); | |
turnAround(); | |
moveToWall(); | |
turnLeft(); | |
if (frontIsClear()) { moveForward(); } | |
} | |
} | |
/* FOLLOW THE SEEDS */ | |
void followTheSeeds() | |
{ | |
while(beeperAhead()) | |
{ | |
while(beeperAhead()) | |
{ | |
moveForward(); | |
pickBeeper(); | |
} | |
turnLeft(); | |
} | |
} | |
/* INCREMENT */ | |
void increment() | |
{ | |
if (onBeeper()) | |
{ | |
while(beeperAhead()) | |
{ | |
pickBeeper(); | |
moveForward(); | |
} | |
pickBeeper(); | |
moveForward(); | |
dropBeeper(); | |
} else { | |
dropBeeper(); | |
} | |
} | |
/* DECREMENT */ | |
void decrement() | |
{ | |
if (onBeeper()) | |
{ | |
pickBeeper(); | |
} else { | |
while (!beeperAhead() && frontIsClear()) | |
{ | |
moveForward(); | |
} | |
if (frontIsClear()) | |
{ | |
moveForward(); | |
pickBeeper(); | |
turnAround(); | |
while(frontIsClear()) | |
{ | |
moveForward(); | |
dropBeeper(); | |
} | |
} | |
} | |
} | |
/* CLEAN THE TUNNELS */ | |
void cleanTheTunnels() | |
{ | |
repeat(10) | |
{ | |
turnLeft(); | |
pickBeeper(); | |
while(beeperAhead()) | |
{ | |
moveForward(); | |
pickBeeper(); | |
} | |
turnAround(); | |
moveToWall(); | |
turnLeft(); | |
if (frontIsClear()) | |
{ | |
moveForward(); | |
} | |
} | |
} | |
/* SAVE THE FLOWERS */ | |
void saveTheFlowers() | |
{ | |
while(!frontIsClear()) | |
{ | |
turnLeft(); | |
while(!rightIsClear()) | |
{ | |
moveForward(); | |
} | |
turnRight(); | |
moveForward(); | |
if(onBeeper()) | |
{ | |
pickBeeper(); | |
} | |
} | |
while(!rightIsClear()) | |
{ | |
dropBeeper(); | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
turnLeft(); | |
} | |
turnRight(); | |
moveToWall(); | |
turnLeft(); | |
} | |
/* FIND TEDDY BEAR */ | |
void findTeddyBear() | |
{ | |
repeat(4) | |
{ | |
while(frontIsClear() && !beeperAhead()) | |
{ | |
moveForward(); | |
} | |
if (beeperAhead()) | |
{ | |
moveForward(); | |
} | |
else | |
{ | |
turnLeft(); | |
} | |
} | |
} | |
/* JUMP THE HURDLES */ | |
void jumpTheHurdles() | |
{ | |
turnLeft(); | |
while(!onBeeper()) | |
{ | |
while(!rightIsClear()) | |
{ | |
moveForward(); | |
} | |
turnRight(); | |
moveForward(); | |
turnRight(); | |
moveToWall(); | |
turnAround(); | |
} | |
} | |
/* SOLVE THE MAZE */ | |
void solveTheMaze() | |
{ | |
while(!onBeeper()) | |
{ | |
if (leftIsClear()) | |
{ | |
turnLeft(); | |
moveForward(); | |
} | |
else if (rightIsClear()) | |
{ | |
turnRight(); | |
moveForward(); | |
} | |
else if (frontIsClear()) | |
{ | |
moveForward(); | |
} | |
else | |
{ | |
turnAround(); | |
moveForward(); | |
} | |
} | |
} | |
/* QUANTIZE */ | |
void quantize() | |
{ | |
repeat(10) | |
{ | |
turnLeft(); | |
repeat(5) | |
{ | |
moveForward(); | |
} | |
if(onBeeper()) /* 1er bit */ | |
{ | |
moveToWall(); | |
turnAround(); | |
while(!onBeeper()) | |
{ | |
dropBeeper(); | |
moveForward(); | |
} | |
moveToWall(); | |
turnLeft(); | |
if(frontIsClear()) | |
{ | |
moveForward(); | |
} | |
} | |
else | |
{ | |
turnAround(); | |
while(frontIsClear()) | |
{ | |
moveForward(); | |
if (onBeeper()) | |
{ | |
pickBeeper(); | |
} | |
} | |
turnLeft(); | |
if(frontIsClear()) | |
{ | |
moveForward(); | |
} | |
} | |
} | |
} | |
/* ADD SLOW */ | |
void addSlow() | |
{ | |
while(frontIsClear()) | |
{ | |
decrement(); | |
if (!frontIsClear()) | |
{ | |
turnAround(); | |
} | |
turnLeft(); | |
if(frontIsClear()) | |
{ | |
moveForward(); | |
turnRight(); | |
increment(); | |
turnAround(); | |
moveToWall(); | |
turnLeft(); | |
moveForward(); | |
turnLeft(); | |
} | |
} | |
turnRight(); | |
while (!beeperAhead() && frontIsClear()) | |
{ | |
moveForward(); | |
dropBeeper(); | |
} | |
} | |
/* ADD FAST */ | |
void addFast() | |
{ | |
repeat(8) | |
{ | |
if(onBeeper() && beeperAhead()) | |
{ | |
moveForward(); | |
if (!beeperAhead()) | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnRight(); | |
moveToWall(); | |
turnAround(); | |
} | |
else | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnAround(); | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnRight(); | |
moveForward(); | |
turnRight(); | |
moveToWall(); | |
turnAround(); | |
} | |
} | |
else if ((onBeeper() && !beeperAhead()) || !onBeeper() && beeperAhead()) | |
{ | |
moveForward(); | |
if (beeperAhead()) | |
{ | |
moveForward(); | |
turnRight(); | |
moveForward(); | |
dropBeeper(); | |
turnRight(); | |
moveToWall(); | |
turnAround(); | |
} | |
else | |
{ | |
moveForward(); | |
moveForward(); | |
dropBeeper(); | |
turnRight(); | |
moveForward(); | |
turnRight(); | |
moveToWall(); | |
turnAround(); | |
} | |
} | |
else | |
{ | |
moveForward(); | |
if (beeperAhead()) | |
{ | |
moveForward(); | |
moveForward(); | |
dropBeeper(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment