Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3798220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:32:14+00:00 2026-05-19T13:32:14+00:00

I’m trying to make a Flood-It style game, and I am having issues with

  • 0

I’m trying to make a Flood-It style game, and I am having issues with the main algorithm.

The algorithm checks for every square that you already control and finds adjacent squares that have the selected color that you don’t control.

Variables:

1 – $board: the 2 dimensional array that holds the state of the board

  • The squares you control in the array are = 0
  • The squares you don’t control range from 1, 6 and represent different colors.

2 – $color: is the color selected by the user

3 – $size: is the square size of the playing board

4 – $rkey / $ckey : the row and column in the 2 dimensional array

The main issue is that it works for the first few squares in the starting corner, maybe 2 or 3, and then it stops taking control of new squares.

Here is an example of the game I’m trying to make: http://floodit.appspot.com/

function checkRecursive($rkey, $ckey)
{
    global $board, $size, $color;
    if ($board[$rkey][$ckey] == 0)
    {
        if ($rkey < $size-1 && $board[$rkey + 1][$ckey] == $color)
        {
            $board[$rkey + 1][$ckey] = 0;
            checkRecursive($rkey + 1, $ckey);
        }
        if ($ckey < $size-1 && $board[$rkey][$ckey + 1] == $color)
        {
            $board[$rkey][$ckey + 1] = 0;
            checkRecursive($rkey, $ckey + 1);
        }
        if ($rkey > 0 && $board[$rkey - 1][$ckey] == $color)
        {
            $board[$rkey - 1][$ckey] = 0;
            checkRecursive($rkey - 1, $ckey);
        }
        if ($ckey > 0 && $board[$rkey][$ckey - 1] == $color)
        {
            $board[$rkey][$ckey - 1] = 0;
            checkRecursive($rkey, $ckey - 1);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:32:15+00:00Added an answer on May 19, 2026 at 1:32 pm

    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 < $size-1 && $board[$rkey + 1][$ckey] == $oldcolor)
            {            
                checkRecursive($rkey + 1, $ckey);
            }
            if ($ckey < $size-1 && $board[$rkey][$ckey + 1] == $oldcolor)
            {
                checkRecursive($rkey, $ckey + 1);
            }
            if ($rkey > 0 && $board[$rkey - 1][$ckey] == $oldcolor)
            {
                checkRecursive($rkey - 1, $ckey);
            }
            if ($ckey > 0 && $board[$rkey][$ckey - 1] == $oldcolor)
            {
                checkRecursive($rkey, $ckey - 1);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.