@kakegurui/shuffle
Version:
Shuffle utilities for Kakegurui Games
45 lines (43 loc) • 1.9 kB
TypeScript
/**
* Performs a simple shuffle using the Fisher-Yates algorithm.
* @param array Array of elements to shuffle.
* @returns The given array, which has also been modified in place.
*/
declare function shuffle<T>(array: T[]): T[];
/**
* Gets a random number within the given range.
* @param start The start range.
* @param end The end range (inclusive).
* @returns A random number within the given range.
*/
declare function randomNumber(start: number, end: number): number;
/**
* Performs a riffle shuffle to combine two decks.
* @param deck1 The first deck
* @param deck2 The second deck
* @returns The two decks combined with a riffle shuffle.
*/
declare function riffleShuffle<T>(deck1: T[], deck2: T[]): T[];
/**
* Deals the specified number of cards onto a seperate pile.
* From top to bottom, hence the new pile will be in reverse.
* @param cards Deck of cards.
* @param numCards Number of cards to deal, must not exceed cards.length
* @returns A new pile containing the dealt cards, the original array has also been modified and the cards have been removed.
*/
declare function deal<T>(cards: T[], numCards: number): T[];
/**
* Shuffles a deck by cutting it by the specified amount of times.
* @param cards Deck of cards.
* @param cuts How many times to cut.
* @returns The deck shuffled by cutting the specified number of times, the array is also modified in place.
*/
declare function cutDeck<T>(cards: T[], cuts: number): T[];
/**
* Performs a Gilbreath shuffle as seen in Nim Type Zero in Kakegurui XX.
* @param cards Deck of cards
* @param split How many cards should be dealt onto a separate pile.
* @returns The pile of cards, dealt into two piles and riffle shuffled. The array is also modified in place.
*/
declare function gilbreathShuffle<T>(cards: T[], split: number): T[];
export { cutDeck, deal, gilbreathShuffle, randomNumber, riffleShuffle, shuffle };