-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_lots_of_changes.go
45 lines (36 loc) · 874 Bytes
/
01_lots_of_changes.go
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
package disadvantages
// Dealer will shuffle a deck of cards and deal them to the players
func DealCards() (player1 []Card, player2 []Card) {
// create a new deck of cards
cards := newDeck()
// shuffle the cards
shuffler := &myShuffler{}
shuffler.Shuffle(cards)
// deal
player1 = append(player1, cards[0])
player2 = append(player2, cards[1])
player1 = append(player1, cards[2])
player2 = append(player2, cards[3])
return
}
// returns a new deck of cards
func newDeck() []Card {
return []Card{
// code removed
}
}
// Shuffler will shuffle (randomize) the supplied cards
type Shuffler interface {
Shuffle(cards []Card)
}
// Card is single Playing Card
type Card struct {
Suit string
Value string
}
// implements Shuffler
type myShuffler struct{}
// Shuffle implements shuffler
func (m *myShuffler) Shuffle(cards []Card) {
// randomize the cards
}