Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
websfera.pl

Tiled board with mines

Question

Hi,

got another nice problem: I need to generate 4x4 tiled board, but some of tiles need to be a "mine" or "don't go" tiles. The hardest thing is, that there must be at least one clean way from point A to point B

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 1

Your request is not really clear. At first, do you want to use a procedural generation ? I guess - because you want to test a path. I could do this way (but I assume that another way could be better) : create a 4x4 tiles board using some simple loops. Add each tile in a list. Select randomly a few of them as an obstacle or mines. You can check, using booleans, a free way starting from your goal to the base. If a tile is free, check if this new tile has a free way (...) until your base. If there is no more free tile, return on your previous true boolean, trying to find another way - a second eventually free tile...

 

Closing my explanation, I would like to say that if you have less than four mines (3 max), you have always a free path - excepted if they are around your base and if it is in a corner. Again, because of a lack of explanation, I guess that you can move your player in a diagonal ++

Share this post


Link to post
Share on other sites

  • 0

@geckoo you're right - player can't move diagonal and yes, it is procedural generation.

\Yesterday I figured something similar to your solution and will try to mix those two :)

Thanks

Share this post


Link to post
Share on other sites
  • 0

Another way is to generate random path first, put them in a list and when creating tiles, don’t put a mine if it’s part of the path

 

 

psuedo:

List<Vector2> path = RandomPath(width, height);

for(int y = 0; y < height; y++)

{

for(int x = 0; x < width; x++)

{

bool a = false;

for(int i = 0; i < path.count; i++)

{

if(path = Vector2(x, y))

{

a = true;

break;

}

if(a) continue;

if(Random.value < 0.5) PlaceBomb(x,y);

}

}

}

 

Edit: just remember when creating a random path, you need to a* it back to find the shortest path. But if you are going to keep it 4x4 and never bigger, you can also just place bombs at 3 out of 4 nodes diagonally and a* to the finish since 4x4 isn’t very big to begin with. 

 

I.e.

int c = 0;

bool done = false;

for(int i = 0; i < 4; i++)

{

if(!done)

{

if(Random.value > 0.8 || i == 3)

{

done = true;

continue;

}

else

{

c++;

placeBombAt(i, i);

}

else placeBombAt(i, i);

}

}

FindPath();

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...