|
@@ -0,0 +1,135 @@
|
|
1
|
+// 模拟比赛得分
|
|
2
|
+const matches = [
|
|
3
|
+ [1, 0], [2, 0], [2, 1], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1], [5, 2], [99, 0],
|
|
4
|
+ [0, 0], [1, 1], [2, 2], [3, 3], [99, 99],
|
|
5
|
+ [0, 1], [0, 2], [1, 2], [0, 3], [1, 3], [2, 3], [0, 4], [1, 4], [2, 4], [0, 5], [1, 5], [2, 5], [0, 99]
|
|
6
|
+]
|
|
7
|
+
|
|
8
|
+const playWayFunc = {
|
|
9
|
+ 'bst-wl': computeWDL,
|
|
10
|
+ 'bst-wls': computeWDLS,
|
|
11
|
+ 'bst-score': computeScore,
|
|
12
|
+ 'bst-points': computePoints
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+// 遍历模拟比赛获取最大, 最小奖金
|
|
16
|
+// rq 让球数
|
|
17
|
+// ys 预设总分
|
|
18
|
+export function GetPrice (allParts, rq, ys) {
|
|
19
|
+ let minPrice
|
|
20
|
+ let maxPrice
|
|
21
|
+
|
|
22
|
+ // 遍历模拟比赛的各种可能
|
|
23
|
+ matches.forEach(match => {
|
|
24
|
+ const [min, max] = GetMinAndMax(allParts, match, rq, ys)
|
|
25
|
+ if (min < minPrice || minPrice === undefined) {
|
|
26
|
+ minPrice = min
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ if (max > maxPrice || maxPrice === undefined) {
|
|
30
|
+ maxPrice = max
|
|
31
|
+ }
|
|
32
|
+ })
|
|
33
|
+
|
|
34
|
+ return [minPrice, maxPrice]
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+function GetMinAndMax (allParts, match, rq, ys) {
|
|
38
|
+ let minPrice = 0
|
|
39
|
+ let maxPrice = 0
|
|
40
|
+
|
|
41
|
+ // 所有组合
|
|
42
|
+ allParts.forEach(parts => {
|
|
43
|
+ // 每种组合 比如 3串4 是 3个2串1, 1个3串1
|
|
44
|
+ const price = parts.map(part => {
|
|
45
|
+ // 场次组合 比如 2串1
|
|
46
|
+ return part.map(grp => {
|
|
47
|
+ const { wayCode } = grp.detail
|
|
48
|
+ const fn = playWayFunc[wayCode]
|
|
49
|
+ return fn(grp, match, rq, ys)
|
|
50
|
+ }).filter(Boolean).reduce((acc, x) => acc * x, 1)
|
|
51
|
+ }).reduce((acc, x) => acc + x, 0)
|
|
52
|
+
|
|
53
|
+ if (minPrice === 0 || minPrice > price) {
|
|
54
|
+ minPrice = price
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ maxPrice += maxPrice
|
|
58
|
+ })
|
|
59
|
+
|
|
60
|
+ return [minPrice, maxPrice]
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+// 胜平负
|
|
64
|
+function computeWDL (part, match) {
|
|
65
|
+ const [x, y] = match
|
|
66
|
+ const { ruleCode, odds } = part.detail
|
|
67
|
+
|
|
68
|
+ switch (ruleCode) {
|
|
69
|
+ case 'bst-win':
|
|
70
|
+ return x > y ? odds : 0
|
|
71
|
+ default:
|
|
72
|
+ return x < y ? odds : 0
|
|
73
|
+ }
|
|
74
|
+}
|
|
75
|
+
|
|
76
|
+// 让球胜平负
|
|
77
|
+function computeWDLS (part, match, rq) {
|
|
78
|
+ const [x, y] = match
|
|
79
|
+ const { ruleCode, odds } = part.rules
|
|
80
|
+
|
|
81
|
+ switch (ruleCode) {
|
|
82
|
+ case 'bst-sp-win':
|
|
83
|
+ return x + rq > y ? odds : 0
|
|
84
|
+ default:
|
|
85
|
+ return x + rq < y ? odds : 0
|
|
86
|
+ }
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+// 比分
|
|
90
|
+function computeScore (part, match, rq, ys) {
|
|
91
|
+ const [x, y] = match
|
|
92
|
+ const { ruleCode, odds } = part.detail
|
|
93
|
+
|
|
94
|
+ switch (ruleCode) {
|
|
95
|
+ case 'bst-big':
|
|
96
|
+ return x + y > ys ? odds : 0
|
|
97
|
+ default:
|
|
98
|
+ return x + y < ys ? odds : 0
|
|
99
|
+ }
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+// 进球数
|
|
103
|
+function computePoints (part, match) {
|
|
104
|
+ const [x, y] = match
|
|
105
|
+ const { ruleCode, odds } = part.rules
|
|
106
|
+
|
|
107
|
+ switch (ruleCode) {
|
|
108
|
+ case 'bst-w15':
|
|
109
|
+ return x - y >= 1 && x - y <= 5 ? odds : 0
|
|
110
|
+ case 'bst-w610':
|
|
111
|
+ return x - y >= 6 && x - y <= 10 ? odds : 0
|
|
112
|
+ case 'bst-w1115':
|
|
113
|
+ return x - y >= 11 && x - y <= 15 ? odds : 0
|
|
114
|
+ case 'bst-w1620':
|
|
115
|
+ return x - y >= 16 && x - y <= 20 ? odds : 0
|
|
116
|
+ case 'bst-w2125':
|
|
117
|
+ return x - y >= 21 && x - y <= 25 ? odds : 0
|
|
118
|
+ case 'bst-w99':
|
|
119
|
+ return x - y >= 26 ? odds : 0
|
|
120
|
+ case 'bst-l15':
|
|
121
|
+ return y - x >= 1 && y - x <= 5 ? odds : 0
|
|
122
|
+ case 'bst-l610':
|
|
123
|
+ return y - x >= 6 && y - x <= 10 ? odds : 0
|
|
124
|
+ case 'bst-l1115':
|
|
125
|
+ return y - x >= 11 && y - x <= 15 ? odds : 0
|
|
126
|
+ case 'bst-l1620':
|
|
127
|
+ return y - x >= 16 && y - x <= 20 ? odds : 0
|
|
128
|
+ case 'bst-l2125':
|
|
129
|
+ return y - x >= 21 && y - x <= 25 ? odds : 0
|
|
130
|
+ case 'bst-l99':
|
|
131
|
+ return y - x >= 26 ? odds : 0
|
|
132
|
+ default:
|
|
133
|
+ return 0
|
|
134
|
+ }
|
|
135
|
+}
|