Commit cc73ba1e authored by Ing. Miroslav Biňas PhD.'s avatar Ing. Miroslav Biňas PhD.
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request kpi/karel-the-robot!2
parents cac17504 f0d3addb
Authors of Karel the robot library:
===================================
Miroslav Binas <mirek.binas at tuke dot sk>
# Authors of Karel the robot library
* Miroslav Binas <miroslav.binas at tuke dot sk>
## Contributors
* Matej Focko
* Janka Paračková
* Ján Juhár
cmake_minimum_required(VERSION 2.8.9)
# Set project
# Set project
project("Karel the Robot C Library" C)
set(PROJECT_VERSION_MAJOR 2018)
set(PROJECT_VERSION_MAJOR 2019)
set(PROJECT_VERSION_MINOR 1)
#For the Curses library to load
# for the Curses library to load
find_package(Curses REQUIRED)
set(CURSES_USE_NCURSES TRUE)
# set compiler flags
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -std=c11")
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -std=c11 -g")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
# Set build features
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
# include directories
include_directories(include)
include_directories(${CURSES_INCLUDE_DIR})
include_directories(include ${CURSES_INCLUDE_DIR})
# build targets
add_library(karel STATIC src/karel.c src/internals.c)
set_property(TARGET karel PROPERTY CXX_STANDARD 11)
# karel
add_library(karel STATIC src/karel.c src/internals.c)
#set_property(TARGET karel PROPERTY CXX_STANDARD 11)
target_link_libraries(karel ${CURSES_LIBRARIES})
# superkarel
add_library(superkarel STATIC src/karel.c src/superkarel.c src/internals.c)
#set_property(TARGET superkarel PROPERTY CXX_STANDARD 11)
target_link_libraries(superkarel ${CURSES_LIBRARIES})
# install library and header files to /usr/local/{lib,include}
install(TARGETS karel DESTINATION lib)
install(TARGETS superkarel DESTINATION lib)
install(FILES "include/karel.h" DESTINATION include)
install(FILES "include/superkarel.h" DESTINATION include)
install(DIRECTORY "doc/" DESTINATION share/doc/libkarel USE_SOURCE_PERMISSIONS
PATTERN "CMakeLists.txt" EXCLUDE)
# add subdirectories
add_subdirectory(doc/examples)
#add_subdirectory(tests)
# tests
#enable_testing()
add_subdirectory(tests)
- move from ncurses to s-lang
- avoid usage of movek() function for Karel's movement because of ncurses move() function
- or maybe termbox (but no support for windows :-( http://code.google.com/p/termbox/
- gettext support for error messages
- SDL support for GUI
- more interesting ;)
# TODO
## NCurses alternatives
- move from ncurses to s-lang
- avoid usage of movek() function for Karel's movement because of ncurses move() function
- or maybe termbox (but no support for windows :-( http://code.google.com/p/termbox/
- SDL support for GUI
- more interesting ;)
## Internationalization
- gettext support for error messages
## Karel and Super Karel
- karel should contain only the basic vocabulary:
* `turn_on()`
* `turn_off()`
* `move()` or `step()`
* `turn_left()`
* `pick_beeper()`
* `put_beeper()`
- karel should be equipped with following basic sensors:
* `front_is_clear()`
* `facing_north()`
* `beepers_present()`
* `beepers_in_bag()`
- super karel extension
- "batteries included" Karel
## Naming Conventions
* rewrite from Java/C++ style to C style
......@@ -6,18 +6,18 @@
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/doc/examples)
#For the shared library:
#set ( PROJECT_LINK_LIBS libkarel.a )
#link_directories(../../build)
#For the static library:
#set ( PROJECT_LINK_LIBS libtestStudent.a )
#link_directories( ~/exploringBB/extras/cmake/studentlib_static/build )
#include_directories(../../include)
include_directories(../../include)
add_executable(stairs stairs.c)
target_link_libraries(stairs LINK_PUBLIC karel)
set_property(TARGET stairs PROPERTY CXX_STANDARD 11)
#include <karel.h>
void turnRight(){
loop(3)
turnLeft();
void turn_right(){
loop(3){
turn_left();
}
}
int main(){
// turn on karel in the world stairs.kw
turnOn( "stairs.kw");
turn_on("stairs.kw");
// pick all beepers on all stairs
loop(3){
turnLeft();
movek();
turnRight();
movek();
pickBeeper();
turn_left();
step();
turn_right();
step();
pick_beeper();
}
// climb the top stair
turnLeft();
movek();
turnRight();
movek();
turn_left();
step();
turn_right();
step();
// put all beepers
while(beepersInBag())
putBeeper();
while(beepersPresent()){
pickBeeper();
while(beepers_in_bag()){
put_beeper();
}
// turn off
turnOff();
turn_off();
}
<!-- saved from url=(0062)file:///home/mirek/Projekty/tuke/pvjc/scenarios/api/index.html -->
<html xmlns:j="http://kpi.fei.tuke.sk/tjava" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:p="http://kpi.fei.tuke.sk/practices"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Karel Language Reference</title>
<meta http-equiv="Content-Language" content="sk">
<link rel="stylesheet" type="text/css" href="style.css">
</head><body>
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Karel Language Reference</title>
<meta http-equiv="Content-Language" content="sk">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="background">
<div class="header">
<div id="logo">
<h1>Karel the Robot Library</h1>
</div>
<div class="menu">
</div>
</div>
<div id="content">
<div class="title">Karel Language Reference</div>
<div class="subtitle">Primitives</div>
<ul>
<li>
<tt><b>void movek()</b></tt> - Move Karel one intersection
<div class="header">
<div id="logo">
<h1>Karel the Robot Library</h1>
</div>
<div class="menu">
</div>
</div>
<div id="content">
<div class="title">Karel Language Reference</div>
<div class="subtitle">Primitives</div>
<ul>
<li>
<tt><b>void step()</b></tt> - Move <i>Karel</i> one intersection
forward.
</li>
<li>
<tt><b>void turnLeft()</b></tt> - Pivots Karel 90 degrees
left.
<li>
<tt><b>void turn_left()</b></tt> - Pivots <i>Karel</i> <i>90</i>
degrees left.
</li>
<li>
<tt><b>void pickBeeper()</b></tt> - Take a beeper from the
<li>
<tt><b>void pick_beeper()</b></tt> - Take a beeper from the
current intersection and put it in the beeper bag.
</li>
<li>
<tt><b>void putBeeper()</b></tt> - Take a beeper from the
<li>
<tt><b>void put_beeper()</b></tt> - Take a beeper from the
beeper bag and put it at the current intersection.
</li>
<li>
<tt><b>void turnOn(char* path)</b></tt> - Turn Karel on.
<li>
<tt><b>void turn_on(char* path)</b></tt> - Turn <i>Karel</i> on.
</li>
<li>
<tt><b>void turnOff()</b></tt> - Turn Karel off.
<li>
<tt><b>void turn_off()</b></tt> - Turn <i>Karel</i> off.
</li>
</ul>
</ul>
<div class="subtitle">Sensors</div>
<div class="subtitle">Sensors</div>
<ul>
<li>
<tt><b>int frontIsClear()</b></tt> - 1 if there is no
wall directly in front of Karel. 0 if there is.
<ul>
<li>
<tt><b>bool front_is_clear()</b></tt> - <tt>true</tt> if there
is no wall directly in front of <i>Karel</i>, <tt>false</tt> if
there is.
</li>
<li>
<tt><b>int frontIsBlocked()</b></tt> - 1 if there is a
wall directly in front of Karel. 0 otherwise.
<li>
<tt><b>bool beepers_present()</b></tt> - <tt>true</tt> if <i>Karel</i>
is standing at an intersection that has a beeper, <tt>false</tt>
otherwise.
</li>
<li>
<tt><b>int leftIsClear()</b></tt> - 1 if there is no
wall immediately to Karel's left. 0 if there is.
<li>
<tt><b>bool facing_north()</b></tt> - <tt>true</tt> if
<i>Karel</i> is facing north, <tt>false</tt> otherwise.
</li>
<li>
<tt><b>int leftIsBlocked()</b></tt> - 1 if there is a
wall immediately to Karel's left. 0 otherwise.
</li>
<li>
<tt><b>int rightIsClear()</b></tt> - 1 if there is no
wall immediately to Karel's right. 0 if there is.
<li>
<tt><b>bool beepers_in_bag()</b></tt> - <tt>true</tt> if there
is at least one beeper in <i>Karel</i>'s beeper bag,
<tt>false</tt> if the beeper bag is empty.
</li>
</ul>
<div class="subtitle">Misc</div>
<li>
<tt><b>int rightIsBlocked()</b></tt> - 1 if there is a
wall immediately to Karel's right. 0 otherwise.
<ul>
<li>
<tt><b>void set_step_delay(int)</b></tt> - Sets delay of one
<i>Karel</i>'s step in miliseconds.
</li>
</ul>
<div class="title">Super Karel Language Reference</div>
<p>
Super Karel is an extension to the basic Karel the Robot library.
Super Karel is "equipped" with additional sensors.
</p>
<div class="subtitle">Sensors</div>
<li>
<tt><b>int beepersPresent()</b></tt> - 1 if Karel is
standing at an intersection that has a beeper. 0 otherwise.
<ul>
<li>
<tt><b>bool front_is_blocked()</b></tt> - <tt>true</tt> if there
is a wall directly in front of <i>Karel</i>, <tt>false</tt>
otherwise.
</li>
<li>
<tt><b>int noBeepersPresent()</b></tt> - 1 if there
is not beeper at the current intersection. 0 if there is a
beeper at the current intersection.
<li>
<tt><b>bool left_is_clear()</b></tt> - <tt>true</tt> if there is
no wall immediately to <i>Karel</i>'s left, <tt>false</tt> if
there is.
</li>
<li>
<tt><b>int facingNorth()</b></tt> - 1 if Karel is
facing north. 0 otherwise.
<li>
<tt><b>bool left_is_blocked()</b></tt> - <tt>true</tt> if there
is a wall immediately to <i>Karel</i>'s left, <tt>false</tt>
otherwise.
</li>
<li>
<tt><b>int notFacingNorth()</b></tt> - 1 if Karel is not
facing north. 0 if he is facing north.
<li>
<tt><b>bool right_is_clear()</b></tt> - <tt>true</tt> if there
is no wall immediately to <i>Karel</i>'s right, <tt>false</tt>
if there is.
</li>
<li>
<tt><b>int facingSouth()</b></tt> - 1 if Karel is facing
south. 0 otherwise.
<li>
<tt><b>bool right_is_blocked()</b></tt> - <tt>true</tt> if there
is a wall immediately to <i>Karel</i>'s right, <tt>false</tt>
otherwise.
</li>
<li>
<tt><b>int notFacingSouth()</b></tt> - 1 if Karel is not
facing south. 0 if he is facing south.
<li>
<tt><b>bool no_beepers_present()</b></tt> - <tt>true</tt> if
there is not beeper at the current intersection, <tt>false</tt>
if there is a beeper at the current intersection.
</li>
<li>
<tt><b>int facingEast()</b></tt> - 1 if Karel is facing
east. 0 otherwise.
<li>
<tt><b>bool not_facing_north()</b></tt> - <tt>true</tt> if <i>Karel</i>
is not facing north, <tt>false</tt> if he is facing north.
</li>
<li>
<tt><b>int notFacingEast()</b></tt> - 1 if Karel is not
facing east. 0 if he is facing east.
<li>
<tt><b>bool facing_south()</b></tt> - <tt>true</tt> if
<i>Karel</i> is facing south, <tt>false</tt> otherwise.
</li>
<li>
<tt><b>int facingWest()</b></tt> - 1 if Karel is facing
west. 0 otherwise.
<li>
<tt><b>bool not_facing_south()</b></tt> - <tt>true</tt> if <i>Karel</i>
is not facing south, <tt>false</tt> if he is facing south.
</li>
<li>
<tt><b>int notFacingWest()</b></tt> - 1 if Karel is not
facing west. 0 if he is facing west.
<li>
<tt><b>bool facing_east()</b></tt> - <tt>true</tt> if
<i>Karel</i> is facing east, <tt>false</tt> otherwise.
</li>
<li>
<tt><b>int beepersInBag()</b></tt> - 1 if there
is at least one beeper in Karel's beeper bag. 0 if the beeper
bag is empty.
<li>
<tt><b>bool not_facing_east()</b></tt> - <tt>true</tt> if <i>Karel</i>
is not facing east, <tt>false</tt> if he is facing east.
</li>
<li>
<tt><b>int noBeepersInBag()</b></tt> - 1 if Karel's
beeper bag is empty. 0 if there is at least one beeper in
the beeper bag.
<li>
<tt><b>bool facing_west()</b></tt> - <tt>true</tt> if
<i>Karel</i> is facing west, <tt>false</tt> otherwise.
</li>
</ul>
<div class="subtitle">Misc</div>
<li>
<tt><b>bool not_facing_west()</b></tt> - <tt>true</tt> if <i>Karel</i>
is not facing west, <tt>false</tt> if he is facing west.
</li>
<ul>
<li>
<tt><b>void setStepDelay(int)</b></tt> - Sets delay of one
Karel's step in miliseconds.
<li>
<tt><b>bool no_beepers_in_bag()</b></tt> - <tt>true</tt> if <i>Karel</i>'s
beeper bag is empty, <tt>false</tt> if there is at least one
beeper in the beeper bag.
</li>
</ul>
</ul>
</div>
<div class="footer">
Created by: <a href="http://www.cnl.sk/~mirek">mirek</a>, 2010, 2019
<a href="https://git.kpi.fei.tuke.sk/kpi/karel-the-robot">Karel the
robot library homepage</a>
</div>
</div>
<div class="footer">
Created by: <a href="http://www.cnl.sk/~mirek">mirek</a>, 2010,
<a href="http://www.cnl.sk/~mirek">Karel the robot library homepage</a>
</div>
</div>
</body></html>
</body>
</html>
#include "karel.h"
#ifndef _INTERNALS_H
#define _INTERNALS_H
#define _INTERNALS_H
#include "karel.h"
#define MULTIPLIER 1000
#define MAX_WIDTH 30
#define MAX_HEIGHT 30
#define MAX_WIDTH 30
#define MAX_HEIGHT 30
// global variables (application context)
extern int stepDelay;
extern bool summary_mode;
extern struct world world;
extern struct robot karel;
extern int _step_delay;
extern struct summary _summary;
extern struct world _world;
extern struct robot _karel;
/**
* Summary mode metadata
*/
struct summary {
bool is_active; // flag to check, if summary is active or not
char* type; // type of summary (e.g. json)
};
enum block{
/**
* Types of blocks
*/
enum block {
CLEAR = 0,
WALL = -1
};
......@@ -23,7 +35,7 @@ enum block{
/**
* World definition
*/
struct world{
struct world {
int width, height; // world's width and height
int **data; // world data definition
};
......@@ -32,7 +44,7 @@ struct world{
/**
* Available directions
*/
enum direction{
enum direction {
EAST = 0,
NORTH = 90,
WEST = 180,
......@@ -43,16 +55,19 @@ enum direction{
/**
* Robot definition
*/
struct robot{
struct robot {
int x, y; // position
enum direction direction; // direction
int steps; // nr. of steps
int beepers; // nr. of beepers in bag
bool isRunning; // robot's state
char lastCommand[10]; // last executed command
bool is_running; // robot's state
char *last_command; // last executed command
};