Using emojis instead of words to create a programming language that moves a robot in a 2D world. Based on the programming language called Karel, which is used to teach basic programming skills, like loops and conditions.
Use the following emojis:
- โก Moves the robot (Karel) forward
- โบ Turns Karel left
- ๐ค Indicates 'if'
- ๐ Indicates 'else'
- ๐ Indicates 'while' loops
- ๐ซ Indicates 'not'
- ๐งฑ Makes Karel check if the wall to its front is blocked
Sample if-else statement (Karel turns left if the front is blocked, otherwise, it moves forward):
๐ค (๐งฑ) {
โบ
} ๐ {
โก
}
Sample while loops (Note that you can use while loops in two ways - either put a condition inside the parenthesis, in which case the loop will repeat until the condition becomes false; or put a number inside the parenthesis, which repeats the loop that many times similar to that of a for loop)
- Condition-based while loop (Karel moves forward until it hits a wall):
๐ (๐ซ ๐งฑ) {
โก
}
- Counter-based while loop a.k.a for loops (Karel turns left 4 times):
๐ (4) {
โบ
}
Example code (Makes Karel move around the edge of the 2D world once)
๐ (4) {
๐ (๐ซ ๐งฑ) {
โก
}
โบ
}
For now, the program is only tested on linux
The main file to be run is main.out
. To generate this file, run the following command in the terminal
make main.out
Run the following command to start the program:
./main.out
Then type the code you want to run in the terminal and press EOF
. A window should appear where you will see Karel in the bottom right of a 8x8 board. Press space to make Karel execute the next movement instruction (โก or โบ). If the program successfully runs without Karel crashing towards any wall, the bottom region of the window shoud show Karel has executed successfully. But if Karel moves towards a wall, the bottom region will show Karel can't move in that direction. In either case, pressing space again will quit the window (and the program).
Alternatively, you can write your program in a text file and send it to main.out as standard input using <
.
Karel also creates a temporary text file containing a custom assembly language for Karel. Whenever space is pressed, Karel executes instructions from this assembly file. By default, the file's name is temp.krl
. However, you can specifiy a name for the temporary text file by passing the file name as an argument to the command (that is, as argv[1]
).