UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

130 lines (129 loc) 5.05 kB
import { Location } from '../material'; import { XYCoordinates } from './grid.util'; /** * The different coordinates systems available to describe a Hexagonal Grid. * See https://www.redblobgames.com/grids/hexagons/#coordinates */ export declare enum HexGridSystem { Axial = 0, OddQ = 1, EvenQ = 2, OddR = 3, EvenR = 4 } /** * Converts {@link HexGridSystem.OddQ} coordinates into {@link HexGridSystem.Axial} coordinates */ export declare const oddQToAxial: ({ x, y }: XYCoordinates) => { x: number; y: number; }; /** * Converts {@link HexGridSystem.Axial} coordinates into {@link HexGridSystem.OddQ} coordinates */ export declare const axialToOddQ: ({ x, y }: XYCoordinates) => { x: number; y: number; }; /** * Converts {@link HexGridSystem.EvenQ} coordinates into {@link HexGridSystem.Axial} coordinates */ export declare const evenQToAxial: ({ x, y }: XYCoordinates) => { x: number; y: number; }; /** * Converts {@link HexGridSystem.Axial} coordinates into {@link HexGridSystem.EvenQ} coordinates */ export declare const axialToEvenQ: ({ x, y }: XYCoordinates) => { x: number; y: number; }; /** * Converts {@link HexGridSystem.OddR} coordinates into {@link HexGridSystem.Axial} coordinates */ export declare const oddRToAxial: ({ x, y }: XYCoordinates) => { y: number; x: number; }; /** * Converts {@link HexGridSystem.Axial} coordinates into {@link HexGridSystem.OddR} coordinates */ export declare const axialToOddR: ({ x, y }: XYCoordinates) => { y: number; x: number; }; /** * Converts {@link HexGridSystem.EvenR} coordinates into {@link HexGridSystem.Axial} coordinates */ export declare const evenRToAxial: ({ x, y }: XYCoordinates) => { y: number; x: number; }; /** * Converts {@link HexGridSystem.Axial} coordinates into {@link HexGridSystem.EvenR} coordinates */ export declare const axialToEvenR: ({ x, y }: XYCoordinates) => { y: number; x: number; }; /** * Convert any {@link HexGridSystem} coordinates to {@link HexGridSystem.Axial} * @param hex Coordinates to convert * @param system System of the coordinates * @return Coordinates in {@link HexGridSystem.Axial} */ export declare function hexToAxial(hex: XYCoordinates, system: HexGridSystem): XYCoordinates; /** * Convert {@link HexGridSystem.Axial} coordinates to any other {@link HexGridSystem} * @param hex Axial coordinates to convert * @param system Destination coordinates system * @return Coordinates converted in the description system */ export declare function hexFromAxial(hex: XYCoordinates, system: HexGridSystem): XYCoordinates; /** * Rotate hexagonal coordinates. * @param vector Vector to rotate * @param rotation Number of 60 degrees rotations to apply (1 = 60°, 2 = 120°...) * @param system The coordinates system used * @return the rotated vector */ export declare function hexRotate(vector: XYCoordinates, rotation?: number, system?: HexGridSystem): XYCoordinates; /** * Get the distance between 2 hexagons, i.e. the minimum number of hexagons to cross to got from hex1 to hex2. * @param hex1 First hexagon coordinates * @param hex2 Second hexagon coordinates * @param system The coordinates system used * @return the distance between the hexagons */ export declare function getDistanceBetweenHex(hex1: XYCoordinates, hex2: XYCoordinates, system?: HexGridSystem): number; /** * Get all the hexagons that are exactly at a specific distance from a given hexagon. * @param hex Coordinates of the hexagon * @param distance Distance of the hexagons we want * @param system The coordinates system used * @return the list of the hexagons found at distance from given hex */ export declare function getHexagonsAtDistance(hex: XYCoordinates, distance: number, system?: HexGridSystem): XYCoordinates[]; /** * Translate hexagonal coordinates by a vector. * @param hex Coordinates of the hexagon to translate * @param vector Vector of the translation * @param system The coordinates system used * @return The coordinates of the hexagon after the translation */ export declare function hexTranslate(hex: XYCoordinates, vector: XYCoordinates, system?: HexGridSystem): XYCoordinates; /** * Get the coordinates that will be covered by a polyhex tile when at a specific grid location. * @param polyhex Coordinates occupied by the polyhex without any rotation in given coordinates system * @param location Location of the polyhex on the grid (x, y, and rotation) * @param system The coordinates system used for the polyhex description and the location * @return coordinates in the grid covered when the polyhex has this location */ export declare function getPolyhexSpaces(polyhex: XYCoordinates[], location: Partial<Location>, system?: HexGridSystem): XYCoordinates[]; /** * Get the coordinates of the 6 hexagons adjacent to a given hexagon. * @param hex Coordinates of the hexagon * @param system Coordinates system */ export declare function getAdjacentHexagons(hex: XYCoordinates, system?: HexGridSystem): XYCoordinates[];