I've read many Q/As about how to solve a maze and I'm familiar with using recursion in programming. My case is slightly different:
I'm trying to develop a machine (in Java) to solve a 2D arena with one entry point, which could be anywhere in the map, not just in the edge. The goal is not to find a way out (there is no such. The entry point is the exit). The mission is to walk all places and looking for collectibles, avoiding obstacles.
Imagine it's a digger in a mine. It's dark, you can see 2,3,4 tiles around and what you can see on this range is only collectibles, because they sort of flicker. Neither obstacles, nor edges of the map can be "seen" until digger tries them and fails to move. That means we don't know the full size and shape of the map. Sometimes it's a series of long thin tunnels, sometimes it's a set of large rooms (30x100 blocks), or a combinations of both.
I've tried a simple maze solving solution with recursion in a room-like map with half empty room (no obstacles and no collectibles). Starting from this part of room makes digger to go dozens of times in these empty blocks back and forth, until it finally plays out all possible ways and finally reach the other end of the room.
Obviously I need a different approach for such maps, while this simple maze solver is great (well, almost) for walking long tunnels.
For those of you who've reached this far, here is a list of additional conditions and characteristics:
- While most of collectibles when 'digged' they disappear and make way, some convert to obstacle and cannot be passed.
- There are gates around the map leading to another map. Imagine it as an elevator and floors.
- There are levers, that open doors, keys being collected, stones being moved to open a way or be placed in certain places to unlock areas, etc.
Well, pretty awesome case and, of course, my digger is going to do just simple jobs (1. and 2. are easily codeable, while 3. is for Isaac Asimov)
So, in case it's not clear what exactly I'm asking, here it is:
How to improve my algorithm to not go so many times in an area, where it's already clear and be 'smarter' in looking for collectibles, no matter the type of the map?