haskell-karel/interface.md

93 lines
4.2 KiB
Markdown
Raw Permalink Normal View History

# Karel Language Reference
## Primitives
- `step :: Karel -> Karel`<br>
Moves Karel one intersection forward.
- `turnLeft :: Karel -> Karel`<br>
Pivots Karel 90 degrees left.
- `pickBeeper :: Karel -> Karel`<br>
Takes a beeper from the current intersection and puts it in the beeper bag.
- `putBeeper :: Karel -> Karel`<br>
Takes a beeper from the beeper bag and puts it at the current intersection.
## Sensors
- `frontIsClear :: Karel -> Bool`<br>
Returns `True` if there is no wall directly in front of Karel. Returns `False` if there is a wall.
- `beepersPresent :: Karel -> Bool`<br>
Returns `True` if Karel is standing at an intersection that has a beeper, `False` otherwise.
- `facing :: Direction -> Karel -> Bool`<br>
Returns `True` if Karel is facing queried direction, `False` otherwise.
- `facingNorth :: Karel -> Bool`<br>
Returns `True` if Karel is facing north, `False` otherwise.
- `beepersInBag :: Karel -> Bool`<br>
Returns `True` if there is at least one beeper in Karel's beeper bag, `False` if the beeper bag is empty.
## Creating world
- `worldWithDimensions :: Vector -> World`<br>
Takes a pair of integers, specifying dimensions of a world `(width, height)` and
returns new world.
- `setBeepersAt :: Vector -> Int -> World -> World`<br>
Sets beepers at specified position, if beepers = 0 => removes them, negative count
or position not in the world results in error.
- `addWallAt :: Vector -> Direction -> World -> World`<br>
Adds wall at specified position to specified direction, if position is not in the
world, results in error.
- `removeWallAt :: Vector -> Direction -> World -> World`<br>
Removes wall at specified position to specified direction, if position is not in
the world, results in error.
## Creating Karel
- `defaultKarel :: World -> Karel`<br>
Creates Karel instance with a given world. Karel is defaultly placed at (1, 1),
facing East with no beepers in his bag.
- `initialPosition :: Vector -> Karel -> Karel`<br>
Sets Karel's initial position, if position is out of the world, results in error.
- `initialDirection :: Direction -> Karel -> Karel`<br>
Sets Karel's initial direction.
- `initialBeepersInBag :: Int -> Karel -> Karel`<br>
Sets Karel's initial beepers in bag, if negative number is given, results in error.
# Super Karel Language Reference
Super Karel is an extension to the basic Karel the Karel library. Super Karel is "equipped" with additional sensors.
## Sensors
- `frontIsBlocked :: Karel -> Bool`<br>
Returns `True` if there is a wall directly in front of Karel, `False` otherwise.
- `leftIsClear :: Karel -> Bool`<br>
Returns `True` if there is no wall immediately to Karel's left, `False` if there is.
- `leftIsBlocked :: Karel -> Bool`<br>
Returns `True` if there is a wall immediately to Karel's left, `False` otherwise.
- `rightIsClear :: Karel -> Bool`<br>
Returns `True` if there is no wall immediately to Karel's right, `False` if there is.
- `rightIsBlocked :: Karel -> Bool`<br>
Returns `True` if there is a wall immediately to Karel's right, `False` otherwise.
- `no_beepers_present :: Karel -> Bool`<br>
Returns `True` if there is not beeper at the current intersection, `False` if there is a beeper at the current intersection.
- `notFacing :: Direction -> Karel -> Bool`<br>
Returns `True` if Karel is not facing queried direction, `False` if he is not.
- `notFacingNorth :: Karel -> Bool`<br>
Returns `True` if Karel is not facing north, `False` if he is facing north.
- `facingSouth :: Karel -> Bool`<br>
Returns `True` if Karel is facing south, `False` otherwise.
- `notFacingSouth :: Karel -> Bool`<br>
Returns `True` if Karel is not facing south, `False` if he is facing south.
- `facingEast :: Karel -> Bool`<br>
Returns `True` if Karel is facing east, `False` otherwise.
- `notFacingEast :: Karel -> Bool`<br>
Returns `True` if Karel is not facing east, `False` if he is facing east.
- `facingWest :: Karel -> Bool`<br>
Returns `True` if Karel is facing west, `False` otherwise.
- `notFacingWest :: Karel -> Bool`<br>
Returns `True` if Karel is not facing west, `False` if he is facing west.
- `noBeepersInBag :: Karel -> Bool`<br>
Returns `True` if Karel's beeper bag is empty, `False` if there is at least one beeper in the beeper bag.