Class: PieceGrid<G>
A grid that tracks adjacency for pieces placed within it. This is useful for tile placement games, e.g. dominoes. Only pieces can be placed in a PieceGrid and each must have a column and row. Pieces that have been assigned irregular shapes using Piece#setShape will be rendered as taking up more than a single cell in the grid, depending on their shape. Adjacency is calculated for the entire shape.
Type parameters
Name | Type |
---|---|
G | extends Game |
Hierarchy
-
↳
PieceGrid
Adjacency
isAdjacentTo
▸ isAdjacentTo(element
): boolean
If this element is adjacent to some other element, using the nearest containing space that has an adjacency map.
Parameters
Name | Type |
---|---|
element | GameElement <BaseGame , BasePlayer > |
Returns
boolean
Inherited from
Defined in
boardzilla-core/src/board/element.ts:540
distanceTo
▸ distanceTo(element
): number
Finds the shortest distance between two spaces
Parameters
Name | Type | Description |
---|---|---|
element | GameElement <BaseGame , BasePlayer > | element to measure distance to |
Returns
number
Inherited from
Defined in
boardzilla-core/src/board/element.ts:552
adjacencies
▸ adjacencies<F
>(className
, ...finders
): ElementCollection
<F
>
Find all elements adjacent based on row/column placement or based on this element having connections created by Space#connectTo. Uses the same parameters as GameElement#all
Type parameters
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
Inherited from
Defined in
boardzilla-core/src/board/element.ts:564
withinDistance
▸ withinDistance<F
>(distance
, className
, ...finders
): ElementCollection
<F
>
Finds all spaces connected to this space by a distance no more than
distance
Type parameters
Name | Type |
---|---|
F | extends GameElement <BaseGame , BasePlayer > |
Parameters
Name | Type |
---|---|
distance | number |
className | ElementClass <F > |
...finders | ElementFinder <F >[] |
Returns
Inherited from
Defined in
boardzilla-core/src/board/element.ts:578
setShape
▸ setShape(...shape
): void
Set an irregular shape for this element. This is only meaningful for the purposes of finding specifically adjacent cells when placed into a PieceGrid. See PieceGrid#adjacenciesByCell. When rendered in a PieceGrid, the element will have a size large enough to fill the appropriate number of spaces in the grid, but it's appearance is otherwise unaffected and will be based on appearance. When not rendered in a PieceGrid, the element will take up a single cell but will be scaled relatively to other elements with a shape in the same layout.
Parameters
Name | Type | Description |
---|---|---|
...shape | string [] | A set of single characters used as labels for each cell. The cell label characters are provided as an array of strings, with each string being one row of cell labels, with spaces used to indicate empty "holes" in the shape. Each row must be the same length. The specific non-space characters used are used for labelling the adjacencies in PieceGrid#adjacenciesByCell but are otherwise unimportant. |
Returns
void
Example
domino12.setShape(
'12'
);
tetrisPiece.setShape(
'XX ',
' XX'
);
Inherited from
Defined in
boardzilla-core/src/board/element.ts:902
setEdges
▸ setEdges(edges
): void
Set the edge labels for this element. These are only meaningful for the purposes of finding specifically adjacent edges when placed into a PieceGrid. See PieceGrid#adjacenciesByEdge.
Parameters
Name | Type | Description |
---|---|---|
edges | Partial <Record <Direction , string >> | Record <string , Partial <Record <Direction , string >>> | A set of edge labels for each cell label provided by setShape. For simple 1-celled shapes, the edges can be provided without cell labels. |
Returns
void
Example
// a bridge tile with a road leading from left to right and a river leading
// from top to bottom.
simpleTile.setEdge(
up: 'river',
down: 'river',
left: 'road'
right: 'road'
});
// A tetris-shaped tile with sockets coming out either "end"
tetrisPiece.setShape(
'AX ',
' XB'
);
tetrisPiece.setEdge({
A: {
left: 'socket'
},
B: {
right: 'socket'
}
});
Inherited from
Defined in
boardzilla-core/src/board/element.ts:947
extendableGrid
• extendableGrid: boolean
= true
If true, the space will be automatically enlarged when new places are added using Action#placePiece.
Defined in
boardzilla-core/src/board/piece-grid.ts:26