## logic confusion

### logic confusion

Im not sure on how about going on this logic for this game. The game is Flood it.
my repo:
https://github.com/metulburr/FloodIt

the game:
http://floodit.appspot.com/

Basically the idea is.... the top left block color is the starting position/color. And you change your color to touching blocks colors to consume them. The goal being that by before 25 turns, you have the entire board all one color, otherwise you lose.

Ive got the basic UI setup. Im just not sure on how to go about the logic for changing your color to nearby color blocks? Ive sat here for a bit drawing on a white board how to come to a conclusion with this, but i end up getting no where. For some reason i think i am over thinking this, and the answer is simple.
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: logic confusion

Hmm. I can think of some ideas, but I would probably have to try to implement it myself to give you a confident solution.

You might want to start by looking at flood fill algorithms and think about how you can adapt that kind of idea:
http://en.wikipedia.org/wiki/Flood_fill

I would probably keep the entire board as a dictionary of coordinate to color.
Then I would keep track of several sets of checked coordinates.
Perhaps an open_set containing all the cells that needed to be checked for neighbors, and a closed_set of cells that had already been confirmed to have no neighbors that weren't already the same color. When the length of the closed_set reaches the length of the board dictionary, the player has won.

That is just a rough idea of how I would approach it.

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: logic confusion

I used a recursive function that i pretty much barrowed from a replica game.
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: logic confusion

Looks pretty nice. Do you understand the algorithm you implemented?

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: logic confusion

Do you understand the algorithm you implemented?

Yes. That was more along the lines of what i was thinking, except i wasnt thinking of using recursion to handle neighboring blocks.
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: logic confusion

Just glanced at it. Looks pretty clean. I think it is essentially a recursive flood fill.

You should go post it on the pygame subreddit (might want to include how to play for the uninitiated).

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Who is online

Users browsing this forum: No registered users and 2 guests