mercredi 4 février 2015

2-Dimensional Array of ints, filled randomly with 1s and 0s. How do I make it so there is always a way to go corner to corner?

So, this project is supposed to be a sort of dungeon-traversing simulator. It is made from randomly generated 5x5 arrays of 1s and 0s. Initially, I fill each 5x5 array with 1s and 0s randomly, with 1s being spaces you can move to and from, and 0s being walls.


The problem is, with the arrays' 1s and 0s being put in random spots, there is currently no way to guarantee that the player can move up/down/left/right. There is no diagonal movement, and I'm trying to find a way to ensure that the player can always move from one corner to another corner. There could be only one way to move in a direction, and no way to get to another corner. Corners are always 1, so the player can exist there. Either one or both indexes immediately beside each corner are also moveable to. So if you're in the top left corner, you can always move down and/or right. You can't be stuck on that spot.


Example:


1 1 0 0 1


0 1 0 1 1


0 0 0 1 0


1 0 1 0 1


1 0 0 1 1


If the player is at the top left corner, they can move right, then down, but then they are stuck. I'm trying to find a way to ensure that all arrays are able to move from corner to corner. So the problem isn't simply making sure every 1 has a neighboring 1, but also that those 1s eventually move towards a corner.


Thanks





Aucun commentaire:

Enregistrer un commentaire