Algorithm Properties

Created by Emília Pietriková / ema

Super Karel Sensors

front_is_blocked()
left_is_clear()
left_is_blocked()
right_is_clear()
right_is_blocked()
no_beepers_present()
no_beepers_in_bag()

Super Karel Sensors

not_facing_north()
facing_south()
not_facing_south()
facing_west()
not_facing_west()
facing_east()
not_facing_east()

How to compile a program?

gcc -std=c11 -Wall -Werror karel.c -lsuperkarel -lcurses -o karel

or

make karel

How to run a program?

./karel

Algorithm
Properties

Maze!

          CORNER  FACING  BEEP-BAG  BEEP-CORNER
          (1, 1)   EAST      0         0
         ST.+-----------------------+
          6 | .   .   .   .   . | 1 |
            |----   +   +   +---+   |
          5 | .   . | . | . | .   . |
            |   +---+   |   |   +---|
          4 | . | .   . | . | . | . |
            |   |   ----+---+       |
          3 | . | .   .   . | .   . |
            |   +---+----   +---+   |
          2 | .   . | .   .   . | . |
            |   +---+   ----+       |
          1 | > | .   .   . | .   . |
            +-----------------------+
              1   2   3   4   5   6   AVE.

COMPLETE ALGORITHM
 

Maze!

          CORNER  FACING  BEEP-BAG  BEEP-CORNER
          (1, 1)   EAST      0         0
         ST.+-----------------------+
          6 | .   .   .   .   . | 1 |
            |----   +   +   +---+   |
          5 | .   . | . | . | .   . |
            |   +---+   |   |   +---|
          4 | . | .   . | . | . | . |
            |   |   ----+---+       |
          3 | . | .   .   . | .   . |
            |   +---+----   +---+   |
          2 | .   . | .   .   . | . |
            |   +---+   ----+       |
          1 | > | .   .   . | .   . |
            +-----------------------+
              1   2   3   4   5   6   AVE.

CLEAR ALGORITHM
 

Maze!

          CORNER  FACING  BEEP-BAG  BEEP-CORNER
          (1, 1)   EAST      0         0
         ST.+-----------------------+
          6 | .   .   .   .   . | 1 |
            |----   +   +   +---+   |
          5 | .   . | . | . | .   . |
            |   +---+   |   |   +---|
          4 | . | .   . | . | . | . |
            |   |   ----+---+       |
          3 | . | .   .   . | .   . |
            |   +---+----   +---+   |
          2 | .   . | .   .   . | . |
            |   +---+   ----+       |
          1 | > | .   .   . | .   . |
            +-----------------------+
              1   2   3   4   5   6   AVE.

EFFECTIVE ALGORITHM
 

Maze!

          CORNER  FACING  BEEP-BAG  BEEP-CORNER
           (1, 1)   EAST      0         0
         ST.+-----------------------------------------------+
          6 | .   .   .   .   . | . | . | .   .   .   .   1 |
            |----   +   +   +---+       +---+   +   +   ----|
          5 | .   . | . | . | .   .   .   . | . | . | .   . |
            |   +---+   |   |   +---+---+   |   |   +---+   |
          4 | . | .   . | . | . | . | . | . | . | .   . | . |
            |   |   ----+---+       |       +---+----   |   |
          3 | . | .   .   . | .   . | .   . | .   .   . | . |
            |   +---+----   +---+   |   +---+   ----+---+   |
          2 | .   . | .   .   . | . | . | .   .   . | .   . |
            |   +---+   ----+       |       +----   +---+   |
          1 | > | .   .   . | .   . | .   . | .   .   . | . |
            +-----------------------------------------------+
              1   2   3   4   5   6   7   8   9   10  11  12  AVE.

VERSATILE (UNIVERSAL) & CORRECT ALGORITHM

Bad Practice

Infinite Loop

Best Practice

FINITE ALGORITHM

Maze?

              CORNER  FACING  BEEP-BAG  BEEP-CORNER
              (1, 3)   NORTH      0         0
             ST.+-------------------+
              5 | .   .   .   .   . |
                |   +---+   +---+   |
              4 | ^ | . | 1 | . | . |
                |   |   +---+   |   |
              3 | . | .   .   . | . |
                |   |           |   |
              2 | . | .   .   . | . |
                |   +-----------+   |
              1 | .   .   .   .   . |
                +-------------------+
                  1   2   3   4   5   AVE.
 
 

not always finite...
 

Harvest

              CORNER  FACING  BEEP-BAG  BEEP-CORNER
              (2, 3)   EAST      10         0
             ST.+-------------------------------+
              8 | .   .   .   .   .   .   .   . |
                |                               |
              7 | .   .   .   .   .   .   .   . |
                |                               |
              6 | .   .   1   1   1   1   .   . |
                |                               |
              5 | .   .   1   1   1   1   .   . |
                |                               |
              4 | .   .   1   1   1   1   .   . |
                |                               |
              3 | .   >   1   1   1   1   .   . |
                |                               |
              2 | .   .   .   .   .   .   .   . |
                |                               |
              1 | .   .   .   .   .   .   .   . |
                +-------------------------------+
                  1   2   3   4   5   6   7   8   AVE.

DETERMINISTIC ALGORITHM

Harvest

              CORNER  FACING  BEEP-BAG  BEEP-CORNER
              (2, 3)   EAST      10         0
             ST.+-------------------------------+
              8 | .   .   .   .   .   .   .   . |
                |                               |
              7 | .   .   .   .   .   .   .   . |
                |                               |
              6 | .   .   1   1   1   1   .   . |
                |                               |
              5 | .   .   1   1   1   1   .   . |
                |                               |
              4 | .   .   1   1   1   1   .   . |
                |                               |
              3 | .   >   1   1   1   1   .   . |
                |                               |
              2 | .   .   .   .   .   .   .   . |
                |                               |
              1 | .   .   .   .   .   .   .   . |
                +-------------------------------+
                  1   2   3   4   5   6   7   8   AVE.

RESULTATIVE ALGORITHM

Questions?

MS Teams