r/AskComputerScience • u/nanoman1 • Dec 24 '25
Graph traversal algorithm
I am currently playing the somewhat popular roguelike game "The Binding Of Isaac", whose map is divided into a grid. In it, there is a challenge run (named "Red Redemption") with the following rules:
- You start on a random space on a 30x30 grid.
- The contents of the neighbouring squares (that is [up, down, left, right]) are hidden behind locked doors until you enter them for the first time.
- You can unlock locked doors with a key. After 20 unlocks, a demon starts chasing you. If he catches you, it's game over. After the 20 unlocks, every 5 additional unlocks spawns another demon. The demon makes the game much harder and should be avoided if possible.
- Somewhere on this grid are 5 islands of white spaces (explained later). These islands together contains: two treasure spaces (which make you more powerful), one shop, and two boss rooms.
- If you beat a boss, you can proceed to the next level, if you so choose.
- The grid is divided into white spaces and red spaces.
- White spaces are hidden from view until you enter one. Once you enter one, all of the adjacent white tiles are displayed on the grid. They can either contain nothing, a treasure space, a shop space, or a boss space.
- Red spaces can contain almost anything: an empty space, a treasure space, a shop, and the rare but highly coveted angel/devil rooms. The one thing it cannot contain is a boss room.
- For the sake of analysis, let's imagine the random room generation algorithm is completely fair.
I am wondering what is the best traversal strategy here and why?
EDIT: What I am looking for is the optimal strategy for choosing which doors to unlock, all while minimizing the number of demons that pop out. One demon is manageable but a pain. Any more than that and it becomes impossible for me to manage. I need to encounter at least one treasure room in order to be powerful enough to defeat the boss and proceed to the next level. Furthermore, whatever strategy is proposed should be executable by a human, namely me.
View all comments
Show parent comment
2
u/Nebu Dec 24 '25
This is unlikely to yield "the optimal solution", in the same way that using "reinforcement learning with a value function that measures how sorted a list is" is unlikely to yield the optimal way to sort a list (as opposed to just using Quicksort, say).
The way I interpreted the OP's question is that they are making a simplified model of the game, and they're looking for an optimal strategy that they could use to inform their actual-play strategy. I.e. if the optimal strategy happens to be reasonably executable by a human, great; otherwise, at least we have a baseline from which to then evaluate human-executable strategies against.