4.8 KiB
id | title | description |
---|---|---|
seminar-04 | 4th seminar | Robot in a maze. |
For this bonus you can get 1.5 K₡ and another 0.5 K₡ for the bonus part of it.
Introduction
In this task you are given a 2D map for a robot. The map contains multiple markers:
^v<>
- which denote the directions the robot will be facing when he steps into the cell or starts on it.K
- denotes the key.T
- denotes the treasure.
In case robot lands at the beginning on unknown field, e.g. .
in the tests, he
faces the direction that is given through the parameter.
Your task is to write the walk
function that returns end result of the walk.
Walk can end in multiple ways:
FOUND_TREASURE
- when you find the treasureFOUND_KEY
- when you find the keyOUT_OF_BOUNDS
- when the robot falls off the mapINFINITE_LOOP
- in case you will implement the bonusNONE
- which is used right now as a default return in the skeleton, has no meaning later on
Hard requirement
There is only one hard requirement that tests cannot check.
You are not allowed to use any indexing related to map or your current position in your implementation.
Reason for this requirement is for you to get used to working with pointers. And for the implementation of this task it is much easier to use just the pointers.
Example of run
For a better understanding of your task, I will describe a simple walk with corresponding function call.
const char *map = (
">.v"
".K<"
"..."
);
walk(map, &map[6], '^', 3, 3);
For this call, you should return FOUND_KEY
. Let us walk through the walk ;)
-
Robot is placed at the bottom left corner, there is no direction specified, so he follows the direction given by parameter (upwards, denoted as
N
(orth), so that we can differentiate markers on the map with the robot when using printing function).>.v .K< N..
-
Moves up:
>.v NK< ...
-
Moves up (now covers
>
), changes direction to right:E.v .K< ...
-
Moves to right:
>Ev .K< ...
-
Moves to right, faces south:
>.S .K< ...
-
Moves down, faces west:
>.v .KW ...
-
Moves left, founds key, returns
FOUND_KEY
:>.v .W< ...
Bonus part
For the bonus part you are supposed to return INFINITE_LOOP
in case the robot
is stuck in the infinite loop. There are three tests for it. If you pass only the
easy and medium one, you can get 0.25 K₡ for doing your best and trying it out. :)
Easter eggs
-
Statistics
Language Files Lines Blanks Comments Code Complexity C 4 458 34 58 366 33 test_maze.c
225 9 0 216 4 sol.maze.c
141 15 28 98 24 maze.c
84 8 30 46 5 main.c
8 2 0 6 0 C Header 1 33 3 19 11 0 maze.h
33 3 19 11 0 CMake 1 25 4 6 15 2 CMakeLists.txt
25 4 6 15 2 Total 6 516 41 83 392 35 -
Majority of the line count in solution is caused by the formatting :)
-
Included headers can be interpreted as hints, same goes for the unimplemented
static
functions which you can use, but are not required. -
Given
CMakeLists.txt
will generate 2 binaries,test_maze
andmaze
.test_maze
runs the tests you are given.maze
runs themain.c
, where you can debug, print mazes and whatever else you want.
-
I keep only one copy of
cut.h
in my repository, so you need to download it from here and place it into the directory where you have your source code. -
I would recommend cloning this repository and copying the
maze
directory to your own repository, since there are multiple files and it may be easier for you.
In case you have any questions, feel free to reach out to me.
Submitting
Ideally submit the assignment through the merge request. Step-by-step tutorial is
present here. For setting assignee my xlogin is xfocko
.
In case you do not want to experiment on GitLab, send me the source code via email,
but please prefix subject with: [PB071/14][seminar-04]
Deadline for the submission of the bonus is April 5th 24:00.