Creating a maze solving algorithm in Java

前端 未结 5 1358
萌比男神i
萌比男神i 2021-02-01 10:56

I\'ve been assigned with the task of creating a maze solver in Java. Here\'s the assignment:

Write an application that finds a path through a maze.  
The maze sh         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 11:24

    You need to separate your program in two phases. The first one is the initialization, where you read the maze description and the initial position of the player. After this you have a data structure to represent the board. The second one is the actual game, where there should be 3 abstractions:

    • The player state. In your case it is pretty simple, its actual position on the board.
    • The maze itself, which is the environment. It should have functions telling you if you have visited a given position, to mark position you have visited, where is the goal,the next reachable cells, etc...
    • The logic, which is the search algorithm.

    Any of these should be able to change without much change of the others. For example, you may be asked to improve your search algorithm, or a problem where you have more than one goal. The easiness of switching from the current problem to a slightly modified one is the real metric of a program design.

提交回复
热议问题