Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 102235x 1x 13x 53244x 1x 2x 1x 2x 1x 2x 1x 105x 1x 1x 1x 218747x 7408x 1022x 1022x 4088x 53144x 53144x 1x 1x 1x 54366x 1x 102447x 1x 2x 104x 104x 104x 104x 1x 2x 1x 1x 26x 26x 12x 12x 14x 14x 1x 1x 2x 1x 1x 26x 26x 1x 1x 1002x 1x 1001x 1001x 1001x 1001x 1001x 1001x 1001x 6405x 6405x 6405x 6405x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 58x 1x 57x 1x 58x 1x 7510x 1x 26x 1x 4x 2x 2x 2x 2x 2x 1x 1x 4x 1x 5x 1x 2x 1x 1x 1x 3x 2x 1x 1x 1x | export enum Suits { CLUBS = "Clubs", HEARTS = "Hearts", SPADES = "Spades", DIAMONDS = "Diamonds" } export enum Faces { ACE = "Ace", TWO = "Two", THREE = "Three", FOUR = "Four", FIVE = "Five", SIX = "Six", SEVEN = "Seven", EIGHT = "Eight", NINE = "Nine", TEN = "Ten", JACK = "Jack", QUEEN = "Queen", KING = "King" } const FaceValues: { [key in Faces]: number } = { [Faces.ACE]: 1, [Faces.TWO]: 2, [Faces.THREE]: 3, [Faces.FOUR]: 4, [Faces.FIVE]: 5, [Faces.SIX]: 6, [Faces.SEVEN]: 7, [Faces.EIGHT]: 8, [Faces.NINE]: 9, [Faces.TEN]: 10, [Faces.JACK]: 11, [Faces.QUEEN]: 12, [Faces.KING]: 13, }; export class Card { public get index(): number { return this._index; } public get value(): number { return FaceValues[this.face]; } constructor(public suit: Suits, public face: Faces, private _index: number = -1) { } isAce(): boolean { return this.face == Faces.ACE; } isKing(): boolean { return this.face == Faces.KING; } isInDeck(): boolean { return this.index >= 0; } toString(): string { return `The ${this.face} of ${this.suit}` } } export class StandardDeck { private _cards: Array<Card>; get cards(): Array<Card> { return this._cards; } protected set cards(value: Array<Card>) { this._cards = value; } constructor() { this._cards = new Array<Card>(); let index: number = 0; for (const suitKey of Object.keys(Suits)) { for (const faceKey of Object.keys(Faces)) { this.cards.push(new Card(Suits[suitKey], Faces[faceKey], index++)); } } } toString(): string { return this.cards.join('\n') } numberOfCards(): number { return this.cards.length; } cardAt(index: number): Card { return this.cards[index]; } randomShuffle(): void { for (let i = 0; i < this.numberOfCards(); i++) { const swapIndex = this.getRandomIndex(0, this.numberOfCards() - 1); const temp = this.cardAt(i); this.cards[i] = this.cardAt(swapIndex); this.cards[swapIndex] = temp; } } riffleShuffle(): void { const [top, bottom] = this.splitDeck() const cards = [] for (let i = 0; i < top.length; i++) { const flip = this.coinFlip(); if (flip == 1) { cards.push(top[i]) cards.push(bottom[i]) } else { cards.push(bottom[i]) cards.push(top[i]) } } this.cards = cards; } faroShuffle(): void { const [top, bottom] = this.splitDeck() const cards = []; for (let i = 0; i < top.length; i++) { cards.push(top[i]) cards.push(bottom[i]) } this.cards = cards; } runningCutsShuffle(): void { if (this.numberOfCards() % 4 != 0) throw new TypeError('Only a full deck can be shuffled'); const cutSizes = [4, 5, 6, 7, 8]; const quarter = this.numberOfCards() / 4; const halfQuarter = quarter / 2; const cutStart = quarter + this.getRandomIndex(-1 * halfQuarter, halfQuarter - 1); let toCut = this.cards.slice(cutStart); this.cards = this.cards.slice(0, cutStart); while (toCut.length > 0) { const cutIndex = this.getRandomIndex(0, cutSizes.length - 1); const cutSize = cutSizes[cutIndex]; this.cards = toCut.slice(0, cutSize).concat(this.cards); toCut = toCut.slice(cutSize); } } fullShuffle(): void { this.randomShuffle(); this.riffleShuffle(); this.riffleShuffle(); this.riffleShuffle(); this.runningCutsShuffle(); this.riffleShuffle(); this.riffleShuffle(); this.riffleShuffle(); this.runningCutsShuffle(); } dealCard(): Card { if (this.isEmpty()) throw new TypeError('Cannot deal card, deck is empty'); return this.cards.shift(); } protected isEmpty(): boolean { return this.cards.length <= 0; } protected getRandomIndex(min: number, max: number): number { return Math.ceil(Math.random() * (max - min) + min); } protected coinFlip(): number { return Math.floor(Math.random() * 100) % 2; } protected splitDeck(): Array<Array<Card>> { if (this.numberOfCards() % 2 != 0) { throw new TypeError('Invalid number of cards to shuffle.'); } const midpoint = this.cards.length / 2; const top = [...this.cards.slice(0, midpoint)]; const bottom = [...this.cards.slice(midpoint)]; return [top, bottom]; } } export abstract class CardHand { protected constructor(private _cards: Array<Card>) { } get cards(): Array<Card> { return this._cards; } abstract calculateScore(): number; addCards(cards: Array<Card>) { this.cards.push(...cards) } } export abstract class CardPlayer { get hand(): CardHand { return this._hand; } protected constructor(private _hand: CardHand) { } abstract scoreHand(); takeCards(cards: Array<Card>) { this.hand.addCards(cards); } } |