Flood-It Game Recursive Function Algorithm in PHP?

Reading your code, it looks like if you're always starting at (0,0), then once the squares immediately adjacent to that cell are under player control, further checks won't get passed them You'll go: start at (0,0) check (0,1) : already set to 0, do nothing check (1,0) : already set to 0, do nothing I think maybe you need to remove the concept of "controlling" squares. All you want to do is repeatedly execute a flood fill algorithm with different colours I think something like this might be better, where $oldcolor is the color of your starting cell before you begin, and $newcolor is the color chosen by the user: function checkRecursive($rkey, $ckey) { global $board, $size, $oldcolor, $newcolor; if ($board$rkey$ckey == $oldcolor) { $board$rkey$ckey = $newcolor if ($rkey 0 && $board$rkey - 1$ckey == $oldcolor) { checkRecursive($rkey - 1, $ckey); } if ($ckey > 0 && $board$rkey$ckey - 1 == $oldcolor) { checkRecursive($rkey, $ckey - 1); } } }.

Reading your code, it looks like if you're always starting at (0,0), then once the squares immediately adjacent to that cell are under player control, further checks won't get passed them. You'll go: start at (0,0) check (0,1) : already set to 0, do nothing. Check (1,0) : already set to 0, do nothing.

I think maybe you need to remove the concept of "controlling" squares. All you want to do is repeatedly execute a flood fill algorithm with different colours. I think something like this might be better, where $oldcolor is the color of your starting cell before you begin, and $newcolor is the color chosen by the user: function checkRecursive($rkey, $ckey) { global $board, $size, $oldcolor, $newcolor; if ($board$rkey$ckey == $oldcolor) { $board$rkey$ckey = $newcolor if ($rkey 0 && $board$rkey - 1$ckey == $oldcolor) { checkRecursive($rkey - 1, $ckey); } if ($ckey > 0 && $board$rkey$ckey - 1 == $oldcolor) { checkRecursive($rkey, $ckey - 1); } } }.

I hadn't realized flood was fine with online update ;) nice. This code looks like it ought to do the job. Remind me in 21 hours to come back and upvote.

:) – sarnold Jan 26 at 2:48 Thanks, it is working now. Took me a while because I had to remove the "controlling" squares. – TheAutumnAurora Jan 26 at 3:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions