@gamepark/rules-api 7.6.4 → 7.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { TFunction } from 'i18next';
1
+ import { TFunction } from './TFunction';
2
2
  export type Option = {
3
3
  label: (t: TFunction) => string;
4
4
  help?: (t: TFunction) => string;
@@ -1,4 +1,4 @@
1
- import { TFunction } from 'i18next';
1
+ import { TFunction } from './TFunction';
2
2
  import { OptionSpecOf } from './OptionSpecOf';
3
3
  import { WithPlayerOptionsSpec } from './WithPlayerOptionsSpec';
4
4
  import { WithPlayersOptions } from './WithPlayersOptions';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Minimal structural type for a translation function, compatible with i18next's `TFunction`.
3
+ * Declared locally so this library does not depend on i18next.
4
+ */
5
+ export type TFunction = (key: string | string[], options?: Record<string, any>) => string;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TFunction.js","sourceRoot":"","sources":["../../src/options/TFunction.ts"],"names":[],"mappings":""}
@@ -7,6 +7,7 @@ export * from './OptionsSpec';
7
7
  export * from './OptionsValidationError';
8
8
  export * from './PlayerEnumOption';
9
9
  export * from './PlayersOptionsSpec';
10
+ export * from './TFunction';
10
11
  export * from './WithIdOption';
11
12
  export * from './WithPlayerOptionsSpec';
12
13
  export * from './WithPlayersOptions';
@@ -7,6 +7,7 @@ export * from './OptionsSpec';
7
7
  export * from './OptionsValidationError';
8
8
  export * from './PlayerEnumOption';
9
9
  export * from './PlayersOptionsSpec';
10
+ export * from './TFunction';
10
11
  export * from './WithIdOption';
11
12
  export * from './WithPlayerOptionsSpec';
12
13
  export * from './WithPlayersOptions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { Location } from '../material';
1
2
  import { XYCoordinates } from './grid.util';
2
3
  /**
3
4
  * Check if two squares in a grid are orthogonally adjacent based on their coordinates
@@ -35,3 +36,38 @@ export declare const directions: Direction[];
35
36
  * @returns the coordinates of the destination square
36
37
  */
37
38
  export declare const getSquareInDirection: (origin: Partial<XYCoordinates>, direction: Direction, distance?: number) => XYCoordinates;
39
+ /**
40
+ * Rotate square-grid coordinates.
41
+ * A quarter turn (90°) matches a positive CSS rotation (clockwise on a y-down screen).
42
+ * @param vector Vector to rotate
43
+ * @param rotation Number of 90 degrees rotations to apply (1 = 90°, 2 = 180°...)
44
+ * @return the rotated vector
45
+ */
46
+ export declare function squareRotate(vector: XYCoordinates, rotation?: number): XYCoordinates;
47
+ /**
48
+ * Translate square-grid coordinates by a vector.
49
+ * @param square Coordinates of the square to translate
50
+ * @param vector Vector of the translation
51
+ * @return the coordinates of the square after the translation
52
+ */
53
+ export declare function squareTranslate(square: XYCoordinates, vector: XYCoordinates): XYCoordinates;
54
+ /**
55
+ * Get all the squares that are exactly at a specific (Manhattan) distance from a given square.
56
+ * @param square Coordinates of the square
57
+ * @param distance Distance of the squares we want
58
+ * @return the list of the squares found at distance from given square
59
+ */
60
+ export declare function getSquaresAtDistance(square: XYCoordinates, distance: number): XYCoordinates[];
61
+ /**
62
+ * Get the coordinates of the 4 squares orthogonally adjacent to a given square.
63
+ * @param square Coordinates of the square
64
+ * @return the coordinates of the adjacent squares
65
+ */
66
+ export declare function getAdjacentSquares(square: XYCoordinates): XYCoordinates[];
67
+ /**
68
+ * Get the coordinates that will be covered by a polyomino tile when at a specific grid location.
69
+ * @param polyomino Coordinates occupied by the polyomino without any rotation
70
+ * @param location Location of the polyomino on the grid (x, y, and rotation)
71
+ * @return coordinates in the grid covered when the polyomino has this location
72
+ */
73
+ export declare function getPolyominoSpaces(polyomino: XYCoordinates[], location: Partial<Location>): XYCoordinates[];
@@ -44,4 +44,72 @@ export const getSquareInDirection = (origin, direction, distance = 1) => {
44
44
  y: direction === Direction.North ? origin.y - distance : direction === Direction.South ? origin.y + distance : origin.y
45
45
  };
46
46
  };
47
+ /**
48
+ * Rotate square-grid coordinates.
49
+ * A quarter turn (90°) matches a positive CSS rotation (clockwise on a y-down screen).
50
+ * @param vector Vector to rotate
51
+ * @param rotation Number of 90 degrees rotations to apply (1 = 90°, 2 = 180°...)
52
+ * @return the rotated vector
53
+ */
54
+ export function squareRotate(vector, rotation = 0) {
55
+ switch (((rotation % 4) + 4) % 4) {
56
+ case 1:
57
+ return { x: -vector.y, y: vector.x };
58
+ case 2:
59
+ return { x: -vector.x, y: -vector.y };
60
+ case 3:
61
+ return { x: vector.y, y: -vector.x };
62
+ default:
63
+ return vector;
64
+ }
65
+ }
66
+ /**
67
+ * Translate square-grid coordinates by a vector.
68
+ * @param square Coordinates of the square to translate
69
+ * @param vector Vector of the translation
70
+ * @return the coordinates of the square after the translation
71
+ */
72
+ export function squareTranslate(square, vector) {
73
+ return { x: square.x + vector.x, y: square.y + vector.y };
74
+ }
75
+ /**
76
+ * Get all the squares that are exactly at a specific (Manhattan) distance from a given square.
77
+ * @param square Coordinates of the square
78
+ * @param distance Distance of the squares we want
79
+ * @return the list of the squares found at distance from given square
80
+ */
81
+ export function getSquaresAtDistance(square, distance) {
82
+ if (distance <= 0)
83
+ return [square];
84
+ const result = [];
85
+ let currentSquare = { x: square.x + distance, y: square.y };
86
+ const vectors = [{ x: -1, y: 1 }, { x: -1, y: -1 }, { x: 1, y: -1 }, { x: 1, y: 1 }];
87
+ for (const vector of vectors) {
88
+ for (let j = 0; j < distance; j++) {
89
+ result.push(currentSquare);
90
+ currentSquare = squareTranslate(currentSquare, vector);
91
+ }
92
+ }
93
+ return result;
94
+ }
95
+ /**
96
+ * Get the coordinates of the 4 squares orthogonally adjacent to a given square.
97
+ * @param square Coordinates of the square
98
+ * @return the coordinates of the adjacent squares
99
+ */
100
+ export function getAdjacentSquares(square) {
101
+ return directions.map((direction) => getSquareInDirection(square, direction));
102
+ }
103
+ /**
104
+ * Get the coordinates that will be covered by a polyomino tile when at a specific grid location.
105
+ * @param polyomino Coordinates occupied by the polyomino without any rotation
106
+ * @param location Location of the polyomino on the grid (x, y, and rotation)
107
+ * @return coordinates in the grid covered when the polyomino has this location
108
+ */
109
+ export function getPolyominoSpaces(polyomino, location) {
110
+ const vector = { x: location.x ?? 0, y: location.y ?? 0 };
111
+ return polyomino
112
+ .map((square) => squareRotate(square, location.rotation ?? 0))
113
+ .map((square) => squareTranslate(square, vector));
114
+ }
47
115
  //# sourceMappingURL=grid.squares.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grid.squares.util.js","sourceRoot":"","sources":["../../src/utils/grid.squares.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAiB,MAAM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qB;IACtD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAA0B,EAAE,QAA2B;IACxF,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAA;IACzD,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;SAC7D,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AACrD,CAAC"}
@@ -12,5 +12,6 @@ export * from './loops.util';
12
12
  export * from './money.util';
13
13
  export * from './neighbors.util';
14
14
  export * from './polyhex.util';
15
+ export * from './polyomino.util';
15
16
  export * from './random.util';
16
17
  export * from './rank.util';
@@ -12,6 +12,7 @@ export * from './loops.util';
12
12
  export * from './money.util';
13
13
  export * from './neighbors.util';
14
14
  export * from './polyhex.util';
15
+ export * from './polyomino.util';
15
16
  export * from './random.util';
16
17
  export * from './rank.util';
17
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,52 @@
1
+ import { XYCoordinates } from './grid.util';
2
+ /**
3
+ * Configuration of a Polyomino
4
+ */
5
+ export interface PolyominoConfig<T = any> {
6
+ /**
7
+ * Minimum x coordinates of the polyomino (arrays cannot have negative index)
8
+ */
9
+ xMin: number;
10
+ /**
11
+ * Minimum y coordinates of the polyomino (arrays cannot have negative index)
12
+ */
13
+ yMin: number;
14
+ /**
15
+ * Function to evaluate whether a value is empty or not in the grid.
16
+ * By default, undefined and null values are considered as empty.
17
+ * @param value Value to evaluate
18
+ * @return true if the value should be considered as empty
19
+ */
20
+ isEmpty: (value: T) => boolean;
21
+ }
22
+ /**
23
+ * Class to work on Polyominoes (multiple squares linked together)
24
+ */
25
+ export declare class Polyomino<T = any> implements PolyominoConfig<T> {
26
+ grid: (T | undefined)[][];
27
+ xMin: number;
28
+ yMin: number;
29
+ isEmpty: (value: (T | undefined)) => boolean;
30
+ constructor(grid: (T | undefined)[][], config?: Partial<PolyominoConfig>);
31
+ get xMax(): number;
32
+ get yMax(): number;
33
+ getValue(coordinates: XYCoordinates): T | undefined;
34
+ /**
35
+ * Utility function to merge multiple polyominoes together to create a bigger polyomino: it merges given polyomino grid in current polyomino.
36
+ * @param polyomino Polyomino to merge in the current polyomino
37
+ * @param location Location to merge the new polyomino in
38
+ * @param onOverlap Callback function when a non-empty value is erased
39
+ */
40
+ merge(polyomino: Polyomino, location?: {
41
+ x?: number;
42
+ y?: number;
43
+ rotation?: number;
44
+ }, onOverlap?: (x: number, y: number) => void): void;
45
+ /**
46
+ * Get the minimum distance from given square to a square of the polyomino that matches given predicate
47
+ * @param square Starting square
48
+ * @param predicate The predicate to match (not empty by default)
49
+ * @returns the minimum distance found
50
+ */
51
+ getDistance(square: XYCoordinates, predicate?: (value: T | undefined) => boolean): number;
52
+ }
@@ -0,0 +1,81 @@
1
+ import { getSquaresAtDistance, squareRotate, squareTranslate } from './grid.squares.util';
2
+ /**
3
+ * Class to work on Polyominoes (multiple squares linked together)
4
+ */
5
+ export class Polyomino {
6
+ grid;
7
+ xMin = 0;
8
+ yMin = 0;
9
+ isEmpty = (value) => value == null; // true for null and undefined
10
+ constructor(grid, config) {
11
+ this.grid = grid;
12
+ this.xMin = config?.xMin ?? this.xMin;
13
+ this.yMin = config?.yMin ?? this.yMin;
14
+ this.isEmpty = config?.isEmpty ?? this.isEmpty;
15
+ }
16
+ get xMax() {
17
+ return Math.max(...this.grid.map((line) => line.length)) + this.xMin - 1;
18
+ }
19
+ get yMax() {
20
+ return this.grid.length + this.yMin - 1;
21
+ }
22
+ getValue(coordinates) {
23
+ return this.grid[coordinates.y - this.yMin]?.[coordinates.x - this.xMin];
24
+ }
25
+ /**
26
+ * Utility function to merge multiple polyominoes together to create a bigger polyomino: it merges given polyomino grid in current polyomino.
27
+ * @param polyomino Polyomino to merge in the current polyomino
28
+ * @param location Location to merge the new polyomino in
29
+ * @param onOverlap Callback function when a non-empty value is erased
30
+ */
31
+ merge(polyomino, location = {}, onOverlap = () => {
32
+ }) {
33
+ for (let y = polyomino.yMin; y <= polyomino.yMax; y++) {
34
+ for (let x = polyomino.xMin; x <= polyomino.xMax; x++) {
35
+ const value = polyomino.getValue({ x, y });
36
+ if (!this.isEmpty(value)) {
37
+ const rotatedCoordinates = squareRotate({ x, y }, location.rotation);
38
+ const coordinates = squareTranslate(rotatedCoordinates, { x: location.x ?? 0, y: location.y ?? 0 });
39
+ while (coordinates.y < this.yMin) {
40
+ this.grid.unshift([]);
41
+ this.yMin--;
42
+ }
43
+ while (coordinates.x < this.xMin) {
44
+ for (const line1 of this.grid) {
45
+ line1.unshift(undefined);
46
+ }
47
+ this.xMin--;
48
+ }
49
+ while (this.grid.length <= coordinates.y - this.yMin) {
50
+ this.grid.push([]);
51
+ }
52
+ if (this.grid[coordinates.y - this.yMin][coordinates.x - this.xMin]) {
53
+ onOverlap(x, y);
54
+ }
55
+ this.grid[coordinates.y - this.yMin][coordinates.x - this.xMin] = value;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Get the minimum distance from given square to a square of the polyomino that matches given predicate
62
+ * @param square Starting square
63
+ * @param predicate The predicate to match (not empty by default)
64
+ * @returns the minimum distance found
65
+ */
66
+ getDistance(square, predicate = (value) => !this.isEmpty(value)) {
67
+ let distance = 0;
68
+ const maxDistance = this.xMax + this.yMax - this.xMin - this.yMin;
69
+ while (distance < maxDistance) {
70
+ const squaresAtDistance = getSquaresAtDistance(square, distance);
71
+ if (squaresAtDistance.some((square) => predicate(this.getValue(square)))) {
72
+ return distance;
73
+ }
74
+ else {
75
+ distance++;
76
+ }
77
+ }
78
+ return Infinity;
79
+ }
80
+ }
81
+ //# sourceMappingURL=polyomino.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyomino.util.js","sourceRoot":"","sources":["../../src/utils/polyomino.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,YAA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,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBACpE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;oBACjB,CAAC;oBACD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACzE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,MAAqB,EAAE,YAAY,CAAC,KAAoB,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAC3F,IAAI,QAAQ,GAAG,CAAC,CAAA;QAChB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACjE,OAAO,QAAQ,GAAG,WAAW,EAAE,CAAC;YAC9B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;YAChE,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzE,OAAO,QAAQ,CAAA;YACjB,CAAC;iBAAM,CAAC;gBACN,QAAQ,EAAE,CAAA;YACZ,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamepark/rules-api",
3
- "version": "7.6.4",
3
+ "version": "7.6.5",
4
4
  "description": "API to implement the rules of a board game",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,11 +27,10 @@
27
27
  "access": "public"
28
28
  },
29
29
  "devDependencies": {
30
- "@types/node": "^25.6.0",
31
- "es-toolkit": "^1.46.0",
32
- "i18next": "^26.0.8",
30
+ "@types/node": "^26.0.1",
31
+ "es-toolkit": "^1.49.0",
33
32
  "typescript": "^6.0.3",
34
- "vitest": "^4.1.5"
33
+ "vitest": "^4.1.9"
35
34
  },
36
35
  "peerDependencies": {
37
36
  "es-toolkit": "^1.46.0"