Lazy Robots - Block selection

April 09, 2012

So after creating the basic building blocks of the levels, I started working on selecting boxes by clicking on them. Which would seem relatively straightforward, right? Like a couple lines of code...

But then complications arose. First of all, I wanted a shift-click option as well that would highlight all contiguous blocks at once, so that was somewhat complex - writing a function to take coordinates from an array, look at all the nearest neighbor spaces of that coordinate and feed those back into the array under certain conditions so the function could be run recursively until all contiguous blocks were found.

The goal in the end is really ease of control. So shift-click just seemed like an obvious implementation, as well as the ability to deselect specific boxes, say, if you wanted to move all the boxes of a specific group except one (and shift-clicking a selected box would deselect all boxes).

But then I started to have major problems with having multiple groups of non-contiguous blocks selected at the same time. So, first of all, every time you select any block, you've gotta check if any other boxes are selected, and, if so, are they adjacent to the box you're selecting? (If not, deselect them.) But the real ass-kicker was what if deselecting an individual box split up a large group of boxes into two separate groups.

Now we've gotta look at all the neighboring boxes of the deselected square, including diagonals, and see if there are multiple groupings of selected boxes. Something like:
XOO
XDX
OOX
where D is the deselected box, and Os are selected boxes. But that doesn't necessarily mean two separate groups because the selected boxes could connect up farther away from the center, like:
XXXOO
XXOOO
XXDXO
XOOXO
OOOOO
So for N groupings of deselected boxes around the original deselected box, I investigate N-1 groups by storing all their coordinates in an array, and then starting with the first coordinate (moving clockwise around the D), I attempt to move around the border of a group of selected boxes counter-clockwise, always keeping track of the coordinate I am in and the coordinate I came from. If you move around the border of group, eventually you are going to get back to where you started. And here's the thing: if I enter the original D square by moving from a coordinate that was in the original set of deselected boxes I started in, then there wasn't a break in the group of selected boxes, but if I move in from a coordinate corresponding to another set, then the group of selected boxes I traveled around, then that group is separate from the other selected boxes neighboring the original D and I've split up a group by deselecting that box. In that case, I just deselect everything as punishment to the play from making me write that ridiculous code.

Here's a movie demonstration (first screens!). It might be a little clearer. Maybe not.
And I'm sorry there aren't cute lazy robots yet. Just boxes...


Leave a comment

Comments will be approved before showing up.


Also in Blog

Isaac's Newsletter: March 2025
Isaac's Newsletter: March 2025

March 28, 2025

Isaac talks about his involvement with Frosthaven Digital and reveals how much of the board game he’s played.

Read More

Arc Games Partners with ASMODEE and Cephalofair Games to Bring Highly Acclaimed Board Game “FROSTHAVEN” to the Digital Realm
Arc Games Partners with ASMODEE and Cephalofair Games to Bring Highly Acclaimed Board Game “FROSTHAVEN” to the Digital Realm

March 20, 2025

From the creative mind of Isaac Childres, the best-selling board game moves to the digital realm in a video game adaptation of FROSTHAVEN.

Read More

Gloomhaven Second Edition: Why It's Worth Playing
Gloomhaven Second Edition: Why It's Worth Playing

March 15, 2025

Gloomhaven has captured the hearts of board game enthusiasts around the world with it's innovative mechanics, uncompromising vision and addictively rewarding gameplay. Now, Gloomhaven Second Edition is here, and it's better than ever.

Read More