UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

50 lines (49 loc) 2.57 kB
import { Location, Material, MaterialMove } from '../material'; /** * This class help manipulate any kind of money with arbitrary unit values, like a set of coins of values 1, 2, 5, 10 for instance. * @deprecated use {@link MaterialMoney} instead */ export declare class Money<Unit extends number = number, P extends number = number, M extends number = number, L extends number = number> { private units; constructor(units: Unit[]); /** * Count the total value of a material instance * @param material The material to count * @returns the sum of each item id multiplied by its quantity */ count(material: Material<P, M, L>): number; /** * Perform an operation of adding or removing an amount from a location by creating or deleting items * @param material The material instance * @param location The location to filter material onto, and to create new items in * @param amount Amount to create or delete * @returns the moves that need to be played to perform the operation */ createOrDelete(material: Material<P, M, L>, location: Location<P, L>, amount: number): MaterialMove<P, M, L>[]; /** * Move an amount of money from a place to another place. It searches after the easiest way to do it, making money with the bank only if necessary. * @param material Material instance for the money (needs to be unfiltered) * @param origin Location to remove money from * @param target Location to move money to * @param amount Amount of money to transfer * @returns the moves that need to be played to perform the operation */ moveAmount(material: Material<P, M, L>, origin: Location<P, L>, target: Location<P, L>, amount: number): MaterialMove<P, M, L>[]; /** * Creates a new record indexes by all units, with value equal to 0 for each unit */ get record(): Record<Unit, number>; /** * Return the best way to gain an amount, prioritizing the highest unit values * @param amount Amount to gain, default 1 * @returns the record of coins to earn (only positive values) */ gain(amount?: number): Record<Unit, number>; /** * Return the best way to spend an amount of owned units, prioritizing the smallest unit values * @param owned Amount of units owned before spending * @param amount Amount to gain, default 1 * @returns the record of coins to give away and eventually take (positive and negative values) */ spend(owned: Record<Unit, number>, amount?: number): Record<Unit, number>; }