Gamelogic
  • Home
  • Blog
  • Tools
    • Grids 2 (for Unity)
      • Features
      • Documentation
    • Grids 1 (Legacy, for Unity)
      • 30 games in 30 days
      • Features
      • Tutorials, Documentation, and FAQ
      • Games made with Grids for Unity
      • Examples
      • What is new?
      • Grid Prototypes and Previews
      • Buy
    • Extensions
    • Colors
      • Features
      • Documentation and tutorials
      • Buy
    • Words
      • Features
      • Documentation
      • Buy
    • Abstract Strategy
      • Features
      • Documentation and tutorials
      • Examples
      • Buy
    • Match
      • Features
    • Grids (for GameMaker)
      • 30 games in 30 days
      • Features
      • Documentation
      • Buy
  • Buy
  • Articles
  • Support
    • Knowledge Base
    • Email Support
  • About
    • Meet our team

Blog

Support for Bitmask Shapes and Polyominoes in Grids 2.3

Polyominoes are used as pieces in many puzzle games, and now Grids has support for them too.

The technology is not very complicated, but it took us a long time to get here.

First, we had to realize that the grid data structure was not just useful for game boards (or game worlds), but also for game pieces (and sections of game worlds). The first example where we used this idea was in this tri-grid game.

Second, we had to realize that the part of the grid that was usually useful in such cases is the grid shape. In Grids 1, shapes were second class citizens – merely used to make grids. The usual way to get a shape was to make an empty grid from it. This is one of the things we changed in Grids 2: shapes can now be used completely independently. (A useful tip: you can declare a ShapeGraph field in a MonoBehaviour and use the node editor to make shapes for your own purposes too).

Third, we had to make it easier to define more complicated shapes. Shapes used for playing fields are usually simple, symmetric shapes. However, shapes used for pieces are often much more complicated. Although you could define polyominoes using a union of a bunch of rectangles, it is awkward to work with. In this version, we introduce “bitmask” shapes: a shape defined by a bunch of bools that says whether a point is inside a shape or not. We provide a few methods to define these shapes. The easiest is to use an array of strings, like this:

C#
1
var cross = ExplicitShape.BitMaskShape(new [] {"010", "111", "010"});

Which defines a 3×3 cross:

C#
1
2
3
010
111
010

(The other methods allow you to specify a 2D array of int or bool instead of strings – under the hood all these are converted to the same thing).

PolyminoNodesThere are nodes for these shapes too, but when it comes to using shapes for pieces, you are likely to require a whole bunch of shapes, so it’s easier to make a set of pieces in code. The class Polyominoes defines shapes for all polyominoes up to hexominoes. There are also enums, and dictionaries linking the enums to the actual shapes.

We also added an example that shows how to use these shapes in a typical game. The example shows two important techniques: how to define a custom shape data structure with more information to make it easier to write algorithms, and how to define a custom grid data structure to make it easier to deal with pieces that span multiple cells.

TightShape2 is a shape that guarantees that the shape’s bounding box is as tight as it can be. (IExplicitShapes make no such guarantee, even though it is usually the case). If the bounding box is tight, it is much easier to compare shapes and determine whether they are they same. You can use the bounding box dimensions as early bail-out tests, and then move them to canonical positions and compare the shapes point-by-point.

PuzzleGrid is a grid-data structure that keeps track of multi-cell pieces. For example, it has a contains method that can check an entire shape (not just a single point), it can return the shape (appropriately translated) of a piece at any location (if there is a piece), and place a piece at a location. This type of grid should be useful in any type of game where you have multi-cell pieces that cannot occupy the same space, but moreover, shows the type of thinking in designing algorithms for grid games.

 

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

  1. Grids 2.2  Grids 2.2 was accepted in the Asset Store last week....
  2. Day 3 Game 3: 30 games in 30 days using Grids  Game 3 is a version of the famous game Ludo....
  3. Grids 2 is out: What changed  Grids 2 has finally been released in the asset store....
  4. What is coming in Grids 2.0  The new version of Grids is a major upgrade, with...
  • Permalink
  • Posted: 18 August 2016
  • Comments: 2
  • Author: Gamelogic

Comments (2)

  1. Pingback: What is new in Words 2.0.2 | Gamelogic

  2. Pingback: What is new in Abstract Strategy 2.1.1 | Gamelogic

Comments are closed.

Recent Posts
  • Tool Documentation Overhaul
  • What is new in Grids Pro 2.3.5
  • What is new in Grids Pro 2.3.2
  • What is new in Abstract Strategy 2.1.1
  • What is new in Words 2.0.2
Categories
  • 30 Games in 30 Days
  • AbstractStrategy
  • Aside
  • Colors
  • Example
  • Extensions
  • General
  • Grids
  • Grids 2
  • Previews
  • Programming
  • Social Media
  • Uncategorized
  • Words
Follow us on Twitter
My Tweets
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
  • Home
  • Features
  • Blog
  • About
  • 14 Eglin Road, Sunninghill, Johannesburg, South Africa
  • support@gamelogic.co.za
Stay Connected
  • Facebook
  • Google
  • Linkedin
  • Rss
  • Twitter
  • Gamelogic © 2013