Algorithms

The Algorithms toolbox works with grids of whole numbers and with random orders. A grid can be a game board, a tile map or a mask. You can read and set cells, find the cells that hold a value, find a path between two cells, fill a region like a paint bucket, pair neighboring cells, and shuffle what the cells hold. The orders part gives random permutations, samples and shuffles, and pairs two sets with a maximum matching.

Use it for board and puzzle games, maze-like levels, or any job that pairs items with slots, such as workers to jobs.

  • Included in: Divooka Explore and Divooka Compute Standard. In Compute, start a document from the Game Development workload, or add the Crime Engine reference with Add reference (Ctrl+Shift+L). The Crime Engine reference holds Crime Engine and Algorithms.
  • Maturity: Preview · Support: Tier 3 (proposed) · what these mean
  • Open it: node library (Ctrl+Shift+Space) → Algorithms, or search for a node with Ctrl+Space.
  • Examples and reference: Ctrl+Shift+E → Glaze > Lian Lian Kan (a tile-matching game) · node reference

New to graphs? Start with Your first program.

Main ideas

A grid is width by height cells, row by row from the top. Cell (0, 0) is the top-left; x is the column and y the row.

Grid nodes return new grids. Set Cell returns a grid with one cell changed; the grid you passed in stays as it was.

Random nodes take a seed. The same seed gives the same order every run.

Example: a path around a wall

The task: in a 5 by 4 grid where 0 is open floor and 1 is wall, find a path from the top-left corner to the cell at column 2, row 2.

  1. Grid From Values, Width 5, Height 4, Values 0,0,0,0,0, 0,1,1,1,0, 0,0,0,1,0, 1,1,0,0,0.
  2. Find Grid Path, From X 0, From Y 0, To X 2, To Y 2. Open is 0 by default, so the path crosses only 0 cells.
  3. Count Cells, Value 0, counts the open cells.

The results:

Found: True, turns: 1
Corners: (0, 0) → (0, 2) → (2, 2)
Open cells: 14

Find Grid Path returns only the corners: the start, each turn and the end, enough to draw the path as straight lines.

To use your own level: build the values from a text map or an image with Basic and Data Types nodes.

Tips and limits

  • Tile-matching links. For a link like in tile-matching games (straight runs through empty cells, at most two turns, around the outside if needed), set Open 0, Margin 1, Step Cost 0, Turn Cost 1, Max Turns 2.
  • Whole numbers only. Cells hold integers. Keep a separate table if a cell needs more than one number.
  • Find Grid Path moves four ways, never diagonally.

Goes well with: Application Framework and Game Components for the game window and input.

What is in the toolbox

Category Some of its nodes
Grids Count Cells, Find Cells, Find Grid Path, Grid From Values and 8 more
Orders and Matchings Maximum Matching, Random Permutation, Random Sample, Shuffle Numbers
Value Grid

See also