@gamepark/rules-api
Version:
API to implement the rules of a board game
38 lines (37 loc) • 1.58 kB
TypeScript
import { XYCoordinates } from './grid.util';
/**
* Check if two squares in a grid are orthogonally adjacent based on their coordinates
* @param square1 Coordinates of the first square
* @param square2 Coordinates of the second square
* @returns true if the squares are orthogonally adjacent
*/
export declare const areAdjacentSquares: (square1: Partial<XYCoordinates>, square2: Partial<XYCoordinates>) => boolean;
/**
* Get the distance between 2 squares in a square-grid, ie the minimum number of steps you need to take to go from square 1 to square 2 following
* orthogonally adjacent squares
* @param square1 Coordinates of the first square
* @param square2 Coordinates of the second square
* @returns the distance between square1 and square2
*/
export declare const getDistanceBetweenSquares: (square1: XYCoordinates, square2: XYCoordinates) => number;
/**
* The direction (cardinal points) you can orient in a square grid
*/
export declare enum Direction {
North = 1,
South = 2,
East = 3,
West = 4
}
/**
* List of the 4 {@link Direction}s
*/
export declare const directions: Direction[];
/**
* Get the coordinates of the next square if you move in a square grid following a direction
* @param origin The coordinates of the square you start from
* @param direction The direction you move to
* @param distance The number of steps you move (A by default)
* @returns the coordinates of the destination square
*/
export declare const getSquareInDirection: (origin: Partial<XYCoordinates>, direction: Direction, distance?: number) => XYCoordinates;