-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.go
52 lines (41 loc) · 854 Bytes
/
player.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
46
47
48
49
50
51
52
package main
type Player struct {
name string
hand Deck
score int
}
func (player *Player) giveCards(rank string) (cards Deck) {
var cardsToGive Deck
var remainingCards Deck
for _, card := range player.hand {
if card.Rank == rank {
cardsToGive = append(cardsToGive, card)
} else {
remainingCards = append(remainingCards, card)
}
}
player.hand = remainingCards
return cardsToGive
}
func (player *Player) hasFourOfKind(rank string) bool {
counter := 0
for _, card := range player.hand {
if card.Rank == rank {
counter += 1
}
}
if counter == 4 {
return true
} else {
return false
}
}
func (player *Player) removeCards(rank string) {
var remainingCards Deck
for _, card := range player.hand {
if card.Rank != rank {
remainingCards = append(remainingCards, card)
}
}
player.hand = remainingCards
}