Dynamic Two-Dimensional Maze Generation and Decryption with
Weights and Traps Based on DFS and Dijkstra Algorithm
Linjia Guo
Institute of Waterford, Nanjing University of Information Science and Technology, Ningliu Road, Nanjing, China
Keywords: Maze Generation, Dynamic Pathfinding, Depth-First Search, Dijkstra Algorithm, Robotics Navigation.
Abstract: Dynamic weighted maze generation and solving represent a critical challenge for intelligent navigation
systems in complex and unpredictable environments. In this study, the paper proposes a modular and
extensible platform that integrates randomized depth-first search (DFS) for unique maze construction and
supports real-time hazard injection, such as traps and mutable barriers. For pathfinding, both breadth-first
search (BFS) and Dijkstra’s algorithm are implemented to handle unweighted and weighted scenarios,
respectively, thereby enabling adaptive and cost-sensitive navigation. The solver is instantly re-invoked
whenever the maze environment changes, ensuring up-to-date risk avoidance and route optimization.
Extensive experiments in two-dimensional and three-dimensional mazes demonstrate that the proposed
platform achieves highly reliable, robust, and efficient navigation, even under frequent dynamic updates. The
system features real-time visualization, making it an ideal tool for research, algorithm benchmarking, and
education in areas such as robotics and intelligent path planning. This work provides a solid foundation for
further investigation into resilient autonomous navigation under real-world uncertainties.
1 INTRODUCTION
Maze generation and solving are fundamental topics
in artificial intelligence and robotics, widely
employed as abstract models for path planning and
navigation in complex, uncertain environments. In
practical applications, navigation is rarely static—
autonomous robots and emergency rescue teams
regularly confront evolving obstacles and hazardous
zones, demanding rapid response and adaptive
decision-making from intelligent systems.
Consequently, dynamically generated, weighted
mazes that incorporate traps and variable barriers
provide a far more realistic testbed for validating and
advancing intelligent pathfinding algorithms.
Recent advances underscore both the challenges
and significance of this problem. A quantum-walk-
based framework has excelled at finding shortest
paths in static, unweighted mazes, offering
compelling theoretical foundations (Matsuoka, Ohno,
& Segawa, 2025).Nevertheless, such approaches do
not address the intricacies of dynamically changing
environments or the effects of cell-specific risks.
Multi-agent maze exploration has also been enhanced
using improved flood-fill algorithms, emphasizing
coordination among agents in unknown environments
(Tjiharjadi, Razali, Sulaiman, 2022; Fernando, 2022).
However, these strategies omit dynamically shifting
hazards and weighted traversal costs. Hybrid
algorithms have been proposed for minimizing
expected escape time, balancing path length and risk,
though they do not consider mazes with dynamically
updated traps or barriers(Yendri, Soelaiman, &
Purwananto, 2023). Solutions that integrate ant
colony algorithms with Dijkstra’s algorithm for
search and rescue illustrate the potential for
combining exploration and hazard-avoidant
navigation(Husain, Zaabi, Hildmann, et al, 2022).
Still, such approaches typically treat navigation and
response to danger as separate phases rather than as
continuous, adaptive strategies.
Despite these developments, there remains a
notable gap, as existing research seldom integrates
dynamic, weighted hazards with pathfinding methods
capable of instant adaptation to environmental
changes. This is particularly pressing in domains such
as smart manufacturing and disaster relief, where
resilient navigation systems must simultaneously
ensure safety and efficiency under unpredictable
conditions. Addressing how to combine robust risk
avoidance with optimal path efficiency in the face of
Guo, L.
Dynamic Two-Dimensional Maze Generation and Decryption with Weights and Traps Based on DFS and Dijkstra Algorithm.
DOI: 10.5220/0014325700004718
Paper published under CC license (CC BY-NC-ND 4.0)
In Proceedings of the 2nd International Conference on Engineering Management, Information Technology and Intelligence (EMITI 2025), pages 227-231
ISBN: 978-989-758-792-4
Proceedings Copyright © 2025 by SCITEPRESS Science and Technology Publications, Lda.
227
ongoing changes is key to advancing reliable
autonomous systems.
This project presents an extensible platform for
dynamic weighted maze generation and solving,
supporting both 2D and 3D scenarios. The system
employs depth-first search (DFS) to generate unique
maze solutions while dynamically injecting random
traps and variable barriers. For maze solving, the
framework integrates both breadth-first search (BFS)
for standard cases and a weight-sensitive Dijkstra
algorithm for efficient, adaptive path planning as
conditions change in real time. Integrated
visualization modules provide intuitive displays of
solution paths and risk distributions, making the
platform well-suited as a simulation and teaching tool
for intelligent robotics and rescue operations.
By uniting dynamic hazard modeling with real-
time, weight-adaptive pathfinding, this work not only
advances the theoretical foundation of intelligent
navigation but also delivers practical value for
research and real-world deployment in challenging
environments.
2 METHODOLOGY
To create a realistic and challenging pathfinding
environment, the paper model the maze as a grid-
based structure in either two or three dimensions.
Each grid cell is assigned a type: wall (impassable),
space (traversable), or trap (traversable but with a
significantly higher traversal cost) (Shi, & Ma. 2022;
Chen. 2020; Tang, Jiang, Gao, et al, 2024). The
internal data organization is a matrix of Cell objects
for 2D, or nested lists in 3D, where each Cell keeps
track of wall status, trap status, and its traversal
weight or cost. Upon initialization, all cells are made
walls and default weights are assigned, ready for
maze carving and hazard insertion.
Maze generation leverages the randomized DFS
algorithm, which is selected for its efficiency and its
guarantee to produce “perfect” mazes—connectivity
without cycles and a unique solution between any two
points (Shi, He, & Ma. 2022). The process begins by
selecting a random starting cell; from there, the
algorithm recursively explores all unvisited
neighbors in random order, removing walls between
the current cell and its neighbor to create legal
passages. When it reaches a dead-end, it backtracks
until another unexplored branch is found. In two
dimensions, neighbors are checked in the four
cardinal directions, while in three dimensions, up and
down are added for extra spatial complexity.
After maze construction, traps are randomly
placed to create high-cost traversal zones, mimicking
hazardous locations. Dynamic behavior is further
simulated by allowing traps or walls to emerge or
disappear during runtime, representing the
unpredictable changes encountered by robots and
agents in real environments (Husain, Zaabi,
Hildmann, et al, 2022; Tjiharjadi, Razali, Sulaiman,
et al, 2022).
For finding routes through the maze, the paper
implements both BFS and Dijkstra’s algorithm to
accommodate different scenario complexities. BFS is
primarily used for unweighted mazes where each step
has uniform cost, guaranteeing the derivation of the
minimal-step route from start to goal (Chen, 2020).
The algorithm enqueues the starting cell, explores all
reachable neighbors in layers.
When cell weights vary—due to traps or other
hazards—Dijkstra’s algorithm is employed as it seeks
the path with the minimum total cost, regardless of
spatial distance (Yendri, Soelaiman, & Purwananto,
2023; Husain, Zaabi, Hildmann, et al, 2022). This
algorithm maintains a priority queue, always
expanding the node with the lowest accumulated cost
so far and updating the cost of reaching each neighbor
when a less expensive route is discovered. Upon
reaching the goal, the total cost and the path can be
reconstructed efficiently.
In both algorithms, each time the maze changes
during simulation (e.g., when a new trap appears or a
wall is erected), the corresponding solver is invoked
anew so that the navigation path reflects the latest
maze structure and hazards (Montenegro, Robinson,
Fu, et al, 2025; Valenzuela, Schaa, Barriga, et al,
2022). Visualization is handled using matplotlib with
black lines indicating walls, red hues for traps, and
blue lines highlighting the final chosen path. During
experimentation, the paper test on grid sizes such as
20×15 for 2D and up to 5×5×5 for 3D, with hundreds
of random dynamic events per simulation. Key
performance metrics—including path length, total
cost, traps avoided, and the speed of adaptation to
changes—are logged throughout each run.
3 RESULTS
The effectiveness and adaptability of our dynamic
weighted maze generation and solving system are
vividly illustrated in Figure 1, which showcases a
typical experimental output from our platform. In this
2D case, the maze is initially constructed using the
randomized DFS algorithm, ensuring a uniquely
solvable structure without loops (Shi, He, & Ma,
EMITI 2025 - International Conference on Engineering Management, Information Technology and Intelligence
228
2022). The maze’s intricate walls, drawn in black,
create a challenging yet fully traversable environment
from the designated start in the upper left to the exit
at the bottom right.
Figure 1: Generated maze display diagram. (Picture credit:
Original)
Within the maze, several cells are highlighted in
translucent red, representing traps or hazard zones.
These special cells were introduced after the basic
maze construction and assigned a higher traversal
cost, emulating real-world dangers or impediments an
autonomous agent might encounter in unpredictable
terrain. The location of each trap is determined
randomly at runtime. Furthermore, during each
simulation step, trap status or even the presence of
certain walls may be adjusted dynamically to
replicate the evolving hazards typical in actual
robotics navigation, such as sudden blockages or new
risk zones (Husain, Zaabi, Hildmann, et al, 2022).
Pathfinding within this dynamic environment is
performed using Dijkstra’s algorithm, which is
particularly well-suited for weighted mazes with
varying traversal costs. In the displayed example, the
solution path is highlighted with a bold blue line.
Unlike simple shortest-path algorithms such as BFS,
Dijkstra’s algorithm seeks to minimize total traversal
cost rather than the sheer number of steps. As such,
the calculated route purposely circumvents most red
trap areas, sometimes accepting a longer geometric
pathway to ensure the agent avoids incurring high risk
or cost (Yendri, Soelaiman, & Purwananto, 2023;
Husain, Zaabi, Hildmann, et al, 2022). This behavior
is clearly observed in Figure 1: the blue route
consistently detours around trap zones, adhering
closely to safe corridors even if it means not taking
the most direct route to the goal.
The dynamic aspect of the system is further
demonstrated throughout the simulation cycles.
When new traps or barriers are triggered during
navigation, the algorithm promptly recalculates and
adapts the current route. This allows the agent to
respond instantly to changing hazards, a capability
essential for real-time robotics navigation and search-
and-rescue applications (Montenegro, Robinson, Fu,
et al,2025; Valenzuela, Schaa, Barriga, et al, 2022).
Repeated experiments confirm the platform’s
stability and responsiveness, with path recalculations
occurring almost instantly as the maze environment
mutates.
Quantitatively, the system yields several clear
advantages. For mazes without traps (where all
weights are uniform), Dijkstra’s and BFS perform
equivalently, both returning the shortest possible step
path (Yendri, Soelaiman, & Purwananto, 2023; Chen,
2020). However, when hazards are introduced,
Dijkstra’s approach consistently reduces the number
of risky (trap-laden) cells traversed, often at the cost
of additional path length. This tradeoff mirrors the
demands of realistic environments, where safe
navigation must be prioritized above sheer efficiency.
Our experiments further show that, regardless of the
frequency and intensity of dynamic updates, the
system reliably avoids new hazards and maintains
high-quality solution paths, supporting ongoing
adaptation as new obstacles or risks appear.
Lastly, the integration of real-time visualization
not only makes the system accessible for educational
and research purposes, but also facilitates
troubleshooting and performance assessment
(Montenegro, Robinson, Fu, et al, 2025). The
immediate graphical feedback allows users to observe
precisely how the agent negotiates traps and barriers,
and to verify that the implemented algorithms behave
as intended under a wide variety of challenging and
changing scenarios (Valenzuela, Schaa, Barriga, et al,
2022).
In conclusion, the results captured in Figure 1
exemplify the strengths of the dynamic weighted
maze platform: robust organic maze generation,
intelligent risk-aware navigation using Dijkstra’s
algorithm, and thorough visual feedback—all of
which support robust benchmarking and exploration
of intelligent path planning under realistic, uncertain
conditions.
4 DISCUSSION
The results underscore the necessity and advantages
of employing dynamic, weighted maze models for
testing and advancing intelligent navigation. The
DFS-based generator provides an unending supply of
challenging, uniquely solvable environments that
maintain their value across both 2D and 3D cases,
Dynamic Two-Dimensional Maze Generation and Decryption with Weights and Traps Based on DFS and Dijkstra Algorithm
229
aligning well with trends in game design, simulation,
and evaluation methods favored in recent works
(Montenegro, Robinson, Fu, et al, 2025; Valenzuela,
Schaa, Barriga, & Patow, 2022). By supporting not
only static but also endlessly changing configurations,
the system closely matches the shifting hazards found
in real robotics, public safety, and emergency
applications.
However, limitations remain. The current model
assigns traps randomly, which does not fully capture
the spatial correlations or sensor-informed risks
present in true operational contexts. The visualization
module, though clear, could be further developed for
3D interactive inspection and overlay of additional
data, such as energy use or threat probability fields.
Most notably, while Dijkstra’s solver is effective and
robust, it recalculates from scratch after each update.
Future research should consider incremental or
heuristic approaches that reuse prior computations to
further reduce latency, as well as hybrid multi-agent
or probabilistic path planning strategies inspired by
recent industry advances (Tjiharjadi, Razali,
Sulaiman, 2022; Fernando, 2022; Yendri, Soelaiman,
& Purwananto, 2023; Husain, Zaabi, Hildmann, et al,
2022).
Comparing our results to the literature, the
presented system extends the state of the art by
facilitating continuous, online adaptation in the face
of dynamic hazards, a clear step beyond most prior
work emphasizing static or phase-based approaches
(Matsuoka, Ohno, & Segawa, 2025; Matsuoka, Yuki,
Lavička, & Segawa, 2021; Husain, Zaabi, Hildmann,
et al, 2022). The easily extensible simulation and
visualization environment also offers a strong
foundation for deployment in education, algorithm
research, or hardware-in-the-loop validation.
Opportunities for further extension include real-
world data integration, richer user interaction, and
cross-validation with quantum-inspired or multi-
agent approaches documented in current academic
research (Montenegro, Robinson, Fu, et al, 2025;
Valenzuela, Schaa, Barriga, & Patow, 2022). This
work thus lays a solid groundwork for safer and
smarter autonomous navigation in increasingly
complex and dynamic real-world environments.
5 CONCLUSION
This paper presents a comprehensive solution for
dynamic weighted maze generation and adaptive
pathfinding, addressing a core need in intelligent
robotics and navigation research. By combining
randomized DFS maze generation with real-time risk
modeling and integrating both BFS and Dijkstra’s
algorithms, the proposed platform robustly adapts to
continuous environmental changes. Experimental
results confirm that the system maintains high
efficiency and safety when navigating evolving
mazes, consistently avoiding newly introduced traps
and overcoming unexpected obstacles. The
platform’s real-time visualization and modular design
not only facilitate academic exploration and
educational use, but also offer broad applicability for
future expansion—such as the integration of sensor-
driven risk assessment, incremental search strategies,
and multi-agent coordination. Overall, this research
provides valuable practical and theoretical
contributions towards the development of reliable,
resilient, and intelligent autonomous navigation in
complex and dynamic environments.
REFERENCES
Chen, J. (2020). Implementation of maze generation and
pathfinding program based on Scratch 3.0. Digital
Technology and Applications, 38(9), 96–98.
Husain, Z., Al Zaabi, A., Hildmann, H., Saffre, F., Ruta, D.,
& Isakovic, A. F. (2022). Search and rescue in a maze-
like environment with ant and Dijkstra algorithms.
Drones, 6(10), 273.
Matsuoka, L., Ohno, H., & Segawa, E. (2025). A
mathematical framework for maze solving using
quantum walks. Quantum Information Processing, 24,
93.
Montenegro, G. A. D. C., Robinson, T. L., Fu, J. F.,
Properzi, M. J., Penney, D., Davis, R., Sperling, R. A.,
Johnson, K. A., Amariglio, R. E., & Rentz, D. M.
(2025). The digital maze test offers a unique method for
detecting early cognitive changes in preclinical
Alzheimer’s disease. Alzheimer’s & Dementia, 20
(Suppl8), e095237.
Matsuoka, L., Yuki, K., Lavička, H., & Segawa, E. (2021).
Maze solving by a quantum walk with sinks and self-
loops: Numerical analysis. Symmetry, 13(12), 2263.
Shi, B., He, Y., & Ma, S. (2022). Research and design of
improved disjoint-set-based maze map generation
algorithm. Journal of Changchun Normal University,
41(4), 51–55.
Tang, D., Jiang, E., Gao, X., & others. (2024). Design and
modeling of modular three-dimensional maze
amusement facilities. Journal of Hubei University of
Technology, 39(6), 106–112.
Tjiharjadi, S., Razali, S., Sulaiman, H., & Fernando, G. V.
(2022). Design of multi-agent pathfinding robot using
improved flood fill algorithm in maze exploration.
International Journal of Mechanical Engineering and
Robotics Research, 11(8), 631–638.
EMITI 2025 - International Conference on Engineering Management, Information Technology and Intelligence
230
Valenzuela, E., Schaa, H., Barriga, N., & Patow, G. (2022).
Using search algorithm statistics for predicting puzzle
difficulty.
Yendri, S., Soelaiman, R., & Purwananto, Y. (2023).
Hybrid algorithm to find minimum expected escape
time from a maze. Engineering Letters, 31(1), 346–357.
Dynamic Two-Dimensional Maze Generation and Decryption with Weights and Traps Based on DFS and Dijkstra Algorithm
231