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:
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:
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

Cephalofair Designer Diary Issue 2: Gloomhaven RPG
Cephalofair Designer Diary Issue 2: Gloomhaven RPG

November 30, 2023

In this month's Designer Diary, Danielle answers questions about the physical components of the game, and more information about the core game rules, modifier decks, and more.

Read More

Cephalofair Designer Diary Issue 1
Cephalofair Designer Diary Issue 1: Gloomhaven RPG

October 30, 2023

Introducing our new Project Manager for the Cephalofair Games Gloomhaven RPG - Danielle Lauzon. In the first Designer Diary - Danielle shares behind the scenes of turning the Gloomhaven Boardgame into an RPG.

Read More

Cephalofair Games New Marketing and Support Staff and More Updates
Cephalofair Games New Marketing and Support Staff and More Updates

October 20, 2023

Read More