@gamepark/rules-api
Version:
API to implement the rules of a board game
71 lines (70 loc) • 3.14 kB
TypeScript
import { LocationStrategy } from '../location';
import { ItemMoveRandomized, ItemMoveView, MoveItem, MoveItemsAtOnce } from '../moves';
import { MaterialItem } from './index';
/**
* Helper class to change the state of any {@link MaterialItem} in a game implemented with {@link MaterialRules}.
*
* @typeparam P - identifier of a player. Either a number or a numeric enum (eg: PlayerColor)
* @typeparam M - Numeric enum of the types of material manipulated in the game
* @typeparam L - Numeric enum of the types of location in the game where the material can be located
*/
export declare class MaterialMutator<P extends number = number, M extends number = number, L extends number = number> {
private readonly type;
private readonly items;
private readonly locationsStrategies;
private readonly canMerge;
private readonly rulesClassName;
/**
* @param type Type of items this mutator will work on
* @param items Items to work with
* @param locationsStrategies The strategies that these items must follow
* @param canMerge Whether to items at the exact same location can merge into one item with a quantity
* @param rulesClassName Constructor name of the main rules class for logging
*/
constructor(type: M, items: MaterialItem<P, L>[], locationsStrategies?: Partial<Record<L, LocationStrategy<P, M, L>>>, canMerge?: boolean, rulesClassName?: string);
/**
* Executes a move on the game items
* @param move
*/
applyMove(move: ItemMoveRandomized<P, M, L> | ItemMoveView<P, M, L>): void;
/**
* Find the index of an existing item we could merge a new item with (create a single item with a quantity)
*
* @param newItem An item to compare with existing items
* @returns {number} Index of the existing item we can merge with, or -1 if there is no possible merge
*/
findMergeIndex(newItem: MaterialItem<P, L>): number;
private addItem;
/**
* Provides the index that the new item will have
* @param newItem An item that is going to be created
* @returns {number} the future index of that item
*/
getItemCreationIndex(newItem: MaterialItem<P, L>): number;
private applyAddItemStrategy;
private applyMoveItemStrategy;
private removeItem;
private applyRemoveItemStrategy;
private create;
private move;
private roll;
private moveItem;
private moveItemsAtOnce;
/**
* Provides the state of an item after it is moved
* @param move The move that is going to happen
* @return {MaterialItem} state of the item after the move is executed
*/
getItemAfterMove(move: MoveItem<P, M, L>): MaterialItem<P, L>;
/**
* Provides the state of an item after it is moved
* @param move The move that is going to happen
* @param index Index of the item to consider
* @return {MaterialItem} state of the item after the move is executed
*/
getItemAfterMoveAtOnce(move: MoveItemsAtOnce<P, M, L>, index: number): MaterialItem<P, L>;
private getItemWithLocation;
private delete;
private shuffle;
private select;
}