Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Assistance needed with flood fill

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Dec 2013 11:28 Edited at: 22nd Dec 2013 11:31
I was rewriting a minesweeper tutorial when I ran into a little problem. I'm using a flood fill to uncover all the blank squares. It'll keep revealing squares until it either finds a bomb or uncovers a square with a number. The problem is, it doesn't uncover all the squares it should.




There are 10 bombs in this example. I clicked once (on a blank square) which began the flood fill process of uncovering the rest of the map. But notice the lower right corner. If it stopped there, it should be showing a border of numbers around what's left. Turns out those squares were all blank anyway, so why are they still there?


Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Dec 2013 12:45
I think that you will have to step through all coordinates first and set the bomb counts, rather than doing that in the 'calculate the numbers' loop. I see this problem sometimes as well, when I don't check the directions... like I tend to check 1 direction at a time, north east south then west, in a loop, until the whole array has been covered. The idea being that the fill will extend to a line going up, then that line is spread to the right, then down, then left, then up again in a loop. Doing it that way, spreading in each direction is a very fast way to fill an area, as opposed to checking an array for neighboring cells. For example using just 1 pass per loop in a pacman game would be enough to provide a path map for enemies.

I think the main thing, you'd have to repeat the flood fill routine to fill the whole space, like keep filling until a pass is complete that needs no array cells to be changed. If you do that, then it should keep going and fill up the bottom right (or areas like that)... so if you change an array value, set a variable so you know to repeat the whole thing, only stop when every array has been checked and no changes needed.

I am the one who knocks...
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Dec 2013 12:56
i modified the revealBox for test but
after the recursive call of revealBox the game crashed at exit.
i put a global depth var in and a sync to see whats going on there.
seems agk have a stack problem.

AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Dec 2013 07:05
I fixed a small bug, but it didn't help any. Although, I am curious as to how it was working at all with this line:



Clearly, I'm missing a y after the comma but never got any compiler errors.

Also, my test map of 20x20 makes a total of 400 blocks. I kept track of the recursion and a single call to revealBox() can call itself about 1400 times. Seems like an inefficient way to search.

I changed the order of the recursive calls and seems to have helped a little bit.

Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 2nd Jan 2014 22:43
Just a thought, but minesweeper games aren't exactly frame rate essential, so you could use a very simply modified a* routine for this one. In my game the user can edit the game world, but the engine needs to identify unique islands which are separate from each other (kinda of like minesweeper but in reverse).

I got around it quite quickly by using a modified a* routine to check the 8 boxes surrounding a certain point, then add them all to an open list. In your game, at this point is where you would clear any boxes that had no mine, add them to an open list. Repeat for for each tile in the open list until that list is empty and it would efficiently check every reachable tile just as it's meant to, and it's actually perfectly quick for this type of game. If you synced between cycles you would even get a decent spreading effect I think.

Just a thought.

Login to post a reply

Server time is: 2024-11-24 23:47:56
Your offset time is: 2024-11-24 23:47:56