karel:karel

Programmieren lernen mit Karel

void karelsFirstProgram()
{
    moveForward();
    pickBeeper();
    moveForward();
    turnLeft();
    moveForward();
    turnRight();
    moveForward();
    dropBeeper();
    moveForward(); 
}
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();
}
void defuseTwoBombs(){
    defuseOneBomb();
    turnLeft();
    defuseOneBomb();
}
 
void defuseOneBomb()
{
    goOneWay();
    pickBeeper();
    goOneWay();
}
 
void goOneWay(){
    repeat(9){
        moveForward();
    }
    turnAround();
}
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();
}
if (onBeeper()){
    pickBeeper();
}
if (onBeeper()){
    pickBeeper();
}
else{
    dropBeeper();
}
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.
void repairHole(){
    turnRight();
    moveForward();
    dropBeeper();
    turnAround();
    moveForward();
    turnRight();
    moveForward();
}
 
void repairTheStreet(){
    while(frontIsClear()){
        if(rightIsClear()){
            repairHole();
        }
        else{
            moveForward();   
        }
    }
}
  • karel/karel.txt
  • Zuletzt geändert: 2023/12/14 20:58
  • von silversurfer