-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck.ts
74 lines (64 loc) · 1.56 KB
/
deck.ts
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
import times from 'lodash/times'
import { BaseDeck } from './base-deck'
import { Card, Ranks, Suits } from './card'
export class StandardDeck extends BaseDeck {
constructor() {
super()
Object.values(Suits).map((suit) => {
Object.values(Ranks).map((rank) => {
if (rank > 0) this.cards.push(new Card({ rank, suit }))
})
})
}
addJokers(numberOfJokers = 2) {
times(numberOfJokers, () => {
this.cards.push(new Card({ rank: Ranks.JOKER, suit: Suits.SPADES }))
})
}
}
export class DoubleStandardDeck extends StandardDeck {
constructor() {
super()
this.cards = [...this.cards, ...this.cards]
}
}
export class EuchreDeck extends StandardDeck {
constructor() {
super()
this.cards = this.cards.filter((card) => card.rank >= 9)
}
}
export class PinochleDeck extends EuchreDeck {
constructor() {
super()
this.cards = [...this.cards, ...this.cards]
}
}
export class CanastaDeck extends StandardDeck {
constructor() {
super()
this.cards = [...this.cards, ...this.cards]
this.addJokers(4)
}
}
export type DeckClass =
| typeof StandardDeck
| typeof DoubleStandardDeck
| typeof EuchreDeck
| typeof CanastaDeck
| typeof PinochleDeck
export const deckTypeNames = [
'standard',
'double',
'euchre',
'canasta',
'pinochle',
] as const
export type DeckTypeName = (typeof deckTypeNames)[number]
export const DeckClassMap: Record<DeckTypeName, DeckClass> = {
standard: StandardDeck,
double: DoubleStandardDeck,
euchre: EuchreDeck,
canasta: CanastaDeck,
pinochle: PinochleDeck,
}