-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck.go
48 lines (37 loc) · 935 Bytes
/
deck.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
package main
import (
"fmt"
"math/rand"
"time"
)
type deck []string
func newDeck() deck {
cards := deck{}
cardSuits := []string{"Spades", "club", "Heart", "Diamond", "Ruby"}
cardValue := []string{"Ace", "two", "three", "Four", "five", "six", "seven", "Eight", "nine ", "ten", "king", "queen", "jack"}
for _, suit := range cardSuits {
for _, value := range cardValue {
cards = append(cards, value+" of "+suit)
}
}
return cards
}
func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}
func deal(d deck, handSize int) (deck, deck) {
if handSize < 0 {
fmt.Println("this is not going to work")
}
return d[:handSize], d[handSize:]
}
func (d deck) shuffle() {
source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)
for i := range d {
newposition := r.Intn(len(d) - 1)
d[i], d[newposition] = d[newposition], d[i]
}
}