-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandout.go
57 lines (50 loc) · 1.12 KB
/
handout.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
53
54
55
56
57
package main
import (
"math/rand"
"time"
"github.com/usthooz/oozlog/go"
)
var (
pockers []string
)
// InitPockers 初始化得到所有牌
func InitPockers(confPockers []string) {
pockers = confPockers
}
// Handout 发牌
func Handout() {
// 取出三张地主牌
for i := 0; i < 3; i++ {
index := genRandCountForDiff(pockers)
lordTokers = append(lordTokers, pockers[index])
// 从牌库移除地主牌
pockers = append(pockers[:index], pockers[index+1:]...)
}
length := len(pockers)
// 发放普通牌
for i := 0; i < length; i++ {
// 随机获取一张牌
index := genRandCountForDiff(pockers)
if i%3 == 0 {
// 主玩家
MainPlayer <- pockers[index]
} else if i%2 == 0 {
// 玩家2
SecondPlayer <- pockers[index]
} else {
// 玩家1
FirstPlayer <- pockers[index]
}
// 从牌库移除地主牌
pockers = append(pockers[:index], pockers[index+1:]...)
}
ozlog.Infof("发牌任务完成.")
return
}
var (
r = rand.New(rand.NewSource(time.Now().Unix()))
)
// genRandCountForDiff 获取数组长度内的数字
func genRandCountForDiff(keys []string) int {
return r.Intn(len(keys))
}