- Event management and process scheduling using Elma and Enviro
- A randomized maze generator using a divide & conquer algorithmic paradigm (recursive division).
- A dynamic agent (robot) that uses effective backtracking + depth-first-search (DFS) to solve the maze.
- (Algorithm & design) DFS + Backtracking using map and stack:
- Visualizing the grid co-ordinates as graph nodes and use graph based search techniques like Depth-First Search (DFS) and Backtracking, without actually constructing the graph or edges explicitly. Assuming the the robot is performing a DFS traversal through the maze.
- Designing a DFS algorithm without using recursion: Given how event management and process scheduling works in elma and enviro it is difficult to code a recursive DFS inside during() or any class method. Solved this efficiently by using the first-in-last-out data-structure (STL
stack
). The stack tracked the order in which nodes (i.e the robot position co-ordinates) get accessed and traversed in the maze. - Keeping tracking of the cells visited by the robot in the maze using a STL
map<>
container. - Effectively backtracking through dead ends (i.e leaf nodes) in linear time by using
stack
to track the order of entry of cells.
- (Algorithm & design) Randomized divided & conquer based maze generation:
- Recursively dividing the empty region into smaller sub-regions and processing each through a similar recursive subroutine.
- Using randomly generated vertical and horizontal axes to divide the region. Interpreting the axes as static agents (or walls).
- Creating a randomized gap in each of the walls (or axis) to connect the divided sub-regions, to form a maze.
- Implementation challenges:
- Working with integer aproximations of the robot locations. Storing and handling the state space (in maps and stacks) would be too large to handle if we consider all the possible floating point values too.
- Calculating closed polygon points inside the recursive division subroutine to represent static agent shapes in a format the enviro expects.
- Integrating DFS+Backtracking and Divide & Conquer paradigms as processes in enviro.
- Converting the generated maze to json and writing to the
config.json
file that enviro renders on screen.
I did not get the time to catalogue all the bugs and issues I face during the implementation phase.
Briefly highlighting some important files:
- I have define and implement various modules used for generating the randomized maze in the files
maze_gen.h
andmaze_gen.cc
. The maze is converted to json and written into theconfig.json
file in theupdate_enviro_config()
method in the MAZE class. run.sh
is used to start the projectsrc/my_robot.h
used to implement the Robot controller (DFS + Backtracking).
First start docker v1.2:
docker run -p80:80 -p8765:8765 -v $PWD:/source -it klavins/enviro:v1.2 bash
esm start
then run the shell script:
bash run.sh
The bash script performs the following:
- Compiles and runs
maze_gen
. - Compiles the robot source codes through
make
- Starts Enviro
The usage is fairly simple:
- After starting the project using the bash script, open
localhost
. - You'll find a freshly generated maze on screen without robot:
- The robot is assigned an initial position based on
screen click
. Therefore click on an emtpy space in the maze. - That's it! Watch the robot traverse the maze. If there is no path (with enough gap to go through) then the robot will backtrack to the initial starting point and stop. Or else it will escape the grid border and wait outside for a new screen click.
- A new maze is generated everytime the bash script is run. Here are some sample "in action" screenshots:
Note that it is possible to change the wall width and recursion depth in my maze generator code (maze_gen.cc
) to get arbitrarily complex mazes!
However, it takes more computation and occupies more memory to store. Moreover, the robot size needs to be manually adjusted to fit in the small gaps in the maze, which is not very pleasing to the eye. I will upload more screenshots and videos (possibly) if time permits.
All the code is original and written from scratch by me. I don't use any pre-built libraries or third-party code, other than json, enviro, and c++ stl. However, the general algorithmic principles used are variations of popular literature:-
Also, I've used KlavinsLab GitHub, Stackoverflow, and CPP language docs for some general syntaxes related debugging.