card-games-utils
Version:
Utility package for card games
114 lines • 5.5 kB
TypeScript
import { StandardCardName } from '../constants/StandardDeckEnum';
import { type Meld } from '../interfaces/Meld';
import { type RummyConfig } from '../interfaces/RummyConfig';
import { type RummyDeclareCheck } from '../interfaces/RummyDeclareCheck';
import { type StandardCard } from '../interfaces/StandardCard';
/**
* Class to handle operations of Rummy game
* @class
*/
export declare class Rummy {
private readonly config;
/**
* Constructs a new instance of Rummy.
* @param {RummyConfig} config the config for the rules of game.
*/
constructor(config: RummyConfig);
/**
* @method
* @static
* make the config for Rummy game
*
* @param {boolean} [isSetRequired = true] - is SET of card-group required for meld to be ready to declare?
* @param {boolean} [isSequenceRequired = true] - is SEQUENCE of card-group required for meld to be ready to declare?
* @param {boolean} [isPureSequenceRequired = true] - is PURE-SEQUENCE of card-group required for meld to be ready to declare?
* @param {boolean} [isJokerAllowed = true] - is joker card allowed in meld or not
* @param {boolean} [isWildAllowed = true] - is wild card allowed in meld or not
* @param {boolean} [isDuplicateCardsAllowed = true] - is duplicate cards allowed in 1 meld(wild cards will be ignored)?
* @param {number} [numCardsPerMeld = 13] - how many cards should there be in 1 meld
* @param {number} [numFlexCardPerMeld = 3] - how many flexible cards(JOKER + WILD) should there be in 1 meld
* @param {number} [numFlexCardPerGroup = 1] - how many flexible cards(JOKER + WILD) should there be in 1 group(SET, SEQUENCE, PURE-SEQUENCE)
* @returns {RummyConfig} - instance of RummyConfig interface based on given data
*/
static makeRummyConfig(isSetRequired?: boolean, isSequenceRequired?: boolean, isPureSequenceRequired?: boolean, isJokerAllowed?: boolean, isWildAllowed?: boolean, numCardsPerMeld?: number): RummyConfig;
/**
* @method
* verify the given meld with the config of the game.
*
*
* @param {meld} meld meld to verify
* @returns {boolean} return true if meld is correct
* @throws {Error} throws error if there is something wrong with meld
*/
verifyMeld(meld: Meld): boolean;
/**
* @method
* convert given array cards and groups into Meld interface
*
* @param {StandardCard[]} cards - array of cards
* @param {number[][]} groups - mutlidimenal array of numbers that make different groups in meld
* @returns {Meld} - returns the generated meld
*/
makeMeld(cards: StandardCard[], groups?: number[][]): Meld;
/**
* @method
* get the groups of card from the given Meld
*
* @param {Meld} meld - the meld who's groups should be returned
* @throws {Error} - if groups has any index that doesn't have card in it.
*/
getCardGroup(meld: Meld): StandardCard[][];
/**
* @method
* sort the cards in meld and divide card into 4 groups with game suites, and 1 for joker(if any)
*
* @param {Meld} meld - the meld who's groups should be returned
*/
sortMeld(meld: Meld): Meld;
/**
* @method
* @static
* calculate the points for given array cards(joker wont be counted)
*
* @param {StandardCard[]} cards - the cards which's points are going to be calculated
* @param {keyof typeof StandardCardName} [cardNameToIgnore] - the card that should be ignored(wildcard)
* @returns {number} - total points for the given cards
*/
static calculatePoints(cards: StandardCard[], cardNameToIgnore?: keyof typeof StandardCardName | undefined): number;
/**
* @method
* decides if the given meld is ready to be declared
*
* @param {Meld} meld - the meld who is about to be declared
* @param {keyof typeof StandardCardName} [wildCardName] - optional wild card.
* @returns {RummyDeclareCheck} - returns an instance of RummyDeclareCheck with proper value.
*/
isReadyToDeclare(meld: Meld, wildCardName?: keyof typeof StandardCardName | undefined): RummyDeclareCheck;
/**
* @method
* decides if the given array of cards are in sequence or not
*
* @param {StandardCard[]} cards - array of cards that needs be checked
* @param {keyof typeof StandardCardName} [wildCardName] - optional wild card.
* @returns {RummyDeclareCheck} - returns an instance of RummyDeclareCheck with proper value.
*/
isInSequence(cards: StandardCard[], wildCardName?: keyof typeof StandardCardName | undefined): RummyDeclareCheck;
/**
* @method
* decides if the given array of cards are in sets or not
*
* @param {StandardCard[]} cards - array of cards that needs be checked
* @param {keyof typeof StandardCardName} [wildCardName] - optional wild card.
* @returns {RummyDeclareCheck} - returns an instance of RummyDeclareCheck with proper value.
*/
isInSet(cards: StandardCard[], wildCardName?: keyof typeof StandardCardName | undefined): RummyDeclareCheck;
/**
* @method
* decides if the given array of cards are in pure sequence or not
*
* @param {StandardCard[]} cards - array of cards that needs be checked
* @returns {RummyDeclareCheck} - returns an instance of RummyDeclareCheck with proper value.
*/
isInPureSequence(cards: StandardCard[]): RummyDeclareCheck;
}
//# sourceMappingURL=Rummy.d.ts.map