Java Implementation of a simple maze solver
This program will solve simple mazes, by reading in a maze file, solving the maze then outputting the solution.
Maze Input/Output
The input is a maze description file in plain text
1 - wall
0 - passage way
(Width)(Height) - size of the maze
(Start_X)(Start_Y) - Location of the start (0,0) is upper left
(End_X)(End_Y) - Location of the end
Example File:
10 10
1 1
8 8
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 1 0 1 1 1 1 1 1
1 0 1 0 0 0 0 0 0 1
1 0 1 1 0 1 0 1 1 1
1 0 1 0 0 1 0 1 0 1
1 0 1 0 0 0 0 0 0 1
1 0 1 1 1 0 1 1 1 1
1 0 1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
Example Output:
The maze will show a path from start to finish
# - Wall
' ' - Passage
X - Path taken
S/E - Start/End
##########
#SXX #
# #X######
# #XX #
# ##X# ###
# # X# # #
# # XX #
# ###X####
# # XXXE#
##########
Movement
Valid moves are N, S, E W only, no diagonal movements are allowed.
The edges are not considered walls unless specified, and allow for maze wrapping.
Example of horizontal wrapping:
10 10
1 1
8 8
1 1 1 1 1 1 1 1 1 1
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 1 1 1 1 1
1 0 1 0 0 0 0 0 0 1
1 0 1 1 0 1 0 1 1 1
1 0 1 0 0 1 0 1 0 1
1 0 1 0 0 0 0 0 0 1
1 0 1 0 0 0 1 1 1 1
1 0 1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
##########
XS# XXXXXX
# X#####
# # X #
# ##X# ###
# # X# # #
# # X #
# # X ####
# # XXXXE#
##########
Example of vertical wrapping:
10 10
1 1
8 8
1 0 1 1 1 1 1 1 1 1
1 0 1 0 0 0 0 0 0 0
1 0 1 0 1 1 1 1 1 1
1 1 1 0 0 0 0 0 0 1
1 0 1 1 0 1 0 1 1 1
1 0 1 0 0 1 0 1 0 1
1 0 1 0 0 0 0 0 0 1
1 0 1 1 1 0 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 1 1 1 1 1 1 1 1
#X########
#S#
# # ######
### #
# ## # ###
# # # # #
# # #
# ### ####
#XXXXXXXE#
#X########
- Clone or download the repository
- Open the programme in an IDE (Eclipse was used to implement this solution)
- Run the Maze.java file
- A number of default mazes can be used, which can be loaded from the file chooser on first start
- Custom mazes can added, using the maze format shown above and saved in the same folder as the default mazes