====== Programmieren lernen mit Karel ======
{{tag>Karel}}
* Karel bei FredOverflow auf [[https://github.com/fredoverflow/karel|GitHub]]
* [[https://www.youtube.com/watch?v=IdbLJKs2K0g&list=PL5vhQpd0v6Y5dVcY8_9Ru6dANaz6UmPnL|Karel Playlist]] von Fred Überlauf
* [[https://www.youtube.com/watch?v=MLIWyMXEo_U&list=PL0VBitL0dCgQhvP6Nob7_SeMCnKtH6Lk8|Karel Lösungen]] Christian Ottenhaus
===== Sequenzen =====
void karelsFirstProgram()
{
moveForward();
pickBeeper();
moveForward();
turnLeft();
moveForward();
turnRight();
moveForward();
dropBeeper();
moveForward();
}
===== Schleifen =====
void defuseOneBomb()
{
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
turnAround();
pickBeeper();
turnAround();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
moveForward();
turnAround();
}
void defuseOneBomb()
{
repeat(9){
moveForward()
}
pickBeeper();
turnAround();
repeat(9){
moveForward()
}
turnAround();
}
===== 1.1.3 defuseTwoBombs =====
void defuseTwoBombs(){
defuseOneBomb();
turnLeft();
defuseOneBomb();
}
void defuseOneBomb()
{
goOneWay();
pickBeeper();
goOneWay();
}
void goOneWay(){
repeat(9){
moveForward();
}
turnAround();
}
===== Funktionen =====
void defuseOneBomb()
{
goOneWay()
pickBeeper();
goOneWay()
}
void goOneWay(){
repeat(9){
moveForward()
}
turnAround();
}
void defuseTwoBombs(){
defuseOneBomb();
turnLeft();
defuseOneBomb();
}
void defuseOneBomb()
{
goOneWay();
pickBeeper();
goOneWay();
}
void goOneWay(){
repeat(9){
moveForward();
}
turnAround();
}
===== Bedingungen / Verzweigungen =====
if (onBeeper()){
pickBeeper();
}
if (onBeeper()){
pickBeeper();
}
else{
dropBeeper();
}
==== Bedingungen ====
^ Bedingung ^ Anmerkung ^
| onBeeper() | Karel checks whether a beeper is on the square he currently stands on. |
| beeperAhead() | Karel checks whether a beeper is on the square immediately in front of him. |
| leftIsCleear() | Karel checks whether no wall is between him and the square to his left. |
| frontIsClear() | Karel checks whether no wall is between him and the square in front of him. |
| rightIsClear() | Karel checks whether no wall is between him and the square to his right. |
===== Generalisieren =====
void repairHole(){
turnRight();
moveForward();
dropBeeper();
turnAround();
moveForward();
turnRight();
moveForward();
}
void repairTheStreet(){
while(frontIsClear()){
if(rightIsClear()){
repairHole();
}
else{
moveForward();
}
}
}