|
@@ -0,0 +1,210 @@
|
|
1
|
+import { descartes } from './math'
|
|
2
|
+
|
|
3
|
+// 模拟比赛得分
|
|
4
|
+const matches = [
|
|
5
|
+ [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],
|
|
6
|
+ [0, 0], [1, 1], [2, 2], [3, 3], [99, 99],
|
|
7
|
+ [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],
|
|
8
|
+]
|
|
9
|
+
|
|
10
|
+const playWayFunc = {
|
|
11
|
+ 'ft-wdl': computeWDL,
|
|
12
|
+ 'ft-wdls': computeWDLS,
|
|
13
|
+ 'ft-score': computeScore,
|
|
14
|
+ 'ft-points': computePoints,
|
|
15
|
+ 'ft-double': computeDouble,
|
|
16
|
+}
|
|
17
|
+
|
|
18
|
+// 遍历模拟比赛获取最大, 最小奖金
|
|
19
|
+// rq 让球数
|
|
20
|
+function getPrice(allParts, rq) {
|
|
21
|
+ let minPrice = undefined
|
|
22
|
+ let maxPrice = undefined
|
|
23
|
+
|
|
24
|
+ // 遍历模拟比赛的各种可能
|
|
25
|
+ matches.forEach(match => {
|
|
26
|
+ const [min, max] = getMinAndMax(allParts, match, rq)
|
|
27
|
+ if (min < minPrice || minPrice === undefined) {
|
|
28
|
+ minPrice = min
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ if (max > maxPrice || maxPrice === undefined) {
|
|
32
|
+ maxPrice = max
|
|
33
|
+ }
|
|
34
|
+ })
|
|
35
|
+
|
|
36
|
+ return [minPrice, maxPrice]
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+function getMinAndMax(allParts, match, rq) {
|
|
40
|
+ let minPrice = 0
|
|
41
|
+ let maxPrice = 0
|
|
42
|
+
|
|
43
|
+ // 所有组合
|
|
44
|
+ allParts.forEach(parts => {
|
|
45
|
+ // 每种组合 比如 3串4 是 3个2串1, 1个3串1
|
|
46
|
+ const price = parts.map(part => {
|
|
47
|
+ // 场次组合 比如 2串1
|
|
48
|
+ return part.map(grp => {
|
|
49
|
+ const { wayCode } = grp.rules
|
|
50
|
+ const fn = playWayFunc[wayCode]
|
|
51
|
+ return fn(grp, match, rq)
|
|
52
|
+ }).filter(Boolean).reduce((acc, x) => acc * x, 1)
|
|
53
|
+
|
|
54
|
+ }).reduce((acc, x) => acc + x, 0)
|
|
55
|
+
|
|
56
|
+ if (minPrice === 0 || minPrice > price) {
|
|
57
|
+ minPrice = price
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ maxPrice += maxPrice
|
|
61
|
+ })
|
|
62
|
+
|
|
63
|
+ return [minPrice, maxPrice]
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+// 胜平负
|
|
67
|
+function computeWDL(part, match, rq) {
|
|
68
|
+ const [x, y] = match
|
|
69
|
+ const {ruleCode, odds} = part.rules
|
|
70
|
+
|
|
71
|
+ switch (ruleCode) {
|
|
72
|
+ case 'ft-win':
|
|
73
|
+ return x > y ? odds : 0
|
|
74
|
+ case 'ft-dead':
|
|
75
|
+ return x == y ? odds : 0
|
|
76
|
+ default:
|
|
77
|
+ return x < y ? odds : 0
|
|
78
|
+ }
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+// 让球胜平负
|
|
82
|
+function computeWDLS(part, match, rq) {
|
|
83
|
+ const [x, y] = match
|
|
84
|
+ const {ruleCode, odds} = part.rules
|
|
85
|
+
|
|
86
|
+ switch (ruleCode) {
|
|
87
|
+ case 'ft-sp-win':
|
|
88
|
+ return x + rq > y ? odds : 0
|
|
89
|
+ case 'ft-sp-dead':
|
|
90
|
+ return x + rq == y ? odds : 0
|
|
91
|
+ default:
|
|
92
|
+ return x + rq < y ? odds : 0
|
|
93
|
+ }
|
|
94
|
+}
|
|
95
|
+
|
|
96
|
+// 比分
|
|
97
|
+function computeScore(part, match, rq) {
|
|
98
|
+ const [x, y] = match
|
|
99
|
+ const {ruleCode, odds} = part.rules
|
|
100
|
+
|
|
101
|
+ switch (ruleCode) {
|
|
102
|
+ case 'ft-w10':
|
|
103
|
+ return x == 1 && y == 0 ? odds : 0
|
|
104
|
+ case 'ft-w20':
|
|
105
|
+ return x == 2 && y == 0 ? odds : 0
|
|
106
|
+ case 'ft-w21':
|
|
107
|
+ return x == 2 && y == 1 ? odds : 0
|
|
108
|
+ case 'ft-w30':
|
|
109
|
+ return x == 3 && y == 0 ? odds : 0
|
|
110
|
+ case 'ft-w31':
|
|
111
|
+ return x == 3 && y == 1 ? odds : 0
|
|
112
|
+ case 'ft-w32':
|
|
113
|
+ return x == 3 && y == 2 ? odds : 0
|
|
114
|
+ case 'ft-w40':
|
|
115
|
+ return x == 4 && y == 0 ? odds : 0
|
|
116
|
+ case 'ft-w41':
|
|
117
|
+ return x == 4 && y == 1 ? odds : 0
|
|
118
|
+ case 'ft-w42':
|
|
119
|
+ return x == 4 && y == 2 ? odds : 0
|
|
120
|
+ case 'ft-w50':
|
|
121
|
+ return x == 5 && y == 0 ? odds : 0
|
|
122
|
+ case 'ft-w51':
|
|
123
|
+ return x == 5 && y == 1 ? odds : 0
|
|
124
|
+ case 'ft-w52':
|
|
125
|
+ return x == 5 && y == 2 ? odds : 0
|
|
126
|
+ case 'ft-w99':
|
|
127
|
+ return x > 5 && x > y ? odds : 0
|
|
128
|
+ case 'ft-d00':
|
|
129
|
+ return x == 0 && x == y ? odds : 0
|
|
130
|
+ case 'ft-d11':
|
|
131
|
+ return x == 1 && x == y ? odds : 0
|
|
132
|
+ case 'ft-d22':
|
|
133
|
+ return x == 2 && x == y ? odds : 0
|
|
134
|
+ case 'ft-d33':
|
|
135
|
+ return x == 3 && x == y ? odds : 0
|
|
136
|
+ case 'ft-d99':
|
|
137
|
+ return x > 5 && x == y ? odds : 0
|
|
138
|
+ case 'ft-l01':
|
|
139
|
+ return x == 0 && y == 1 ? odds : 0
|
|
140
|
+ case 'ft-l02':
|
|
141
|
+ return x == 0 && y == 2 ? odds : 0
|
|
142
|
+ case 'ft-l12':
|
|
143
|
+ return x == 1 && y == 2 ? odds : 0
|
|
144
|
+ case 'ft-l03':
|
|
145
|
+ return x == 0 && y == 3 ? odds : 0
|
|
146
|
+ case 'ft-l13':
|
|
147
|
+ return x == 1 && y == 3 ? odds : 0
|
|
148
|
+ case 'ft-l23':
|
|
149
|
+ return x == 2 && y == 3 ? odds : 0
|
|
150
|
+ case 'ft-l04':
|
|
151
|
+ return x == 0 && y == 4 ? odds : 0
|
|
152
|
+ case 'ft-l14':
|
|
153
|
+ return x == 1 && y == 4 ? odds : 0
|
|
154
|
+ case 'ft-l24':
|
|
155
|
+ return x == 2 && y == 4 ? odds : 0
|
|
156
|
+ case 'ft-l05':
|
|
157
|
+ return x == 0 && y == 5 ? odds : 0
|
|
158
|
+ case 'ft-l15':
|
|
159
|
+ return x == 1 && y == 5 ? odds : 0
|
|
160
|
+ case 'ft-l25':
|
|
161
|
+ return x == 2 && y == 5 ? odds : 0
|
|
162
|
+ default:
|
|
163
|
+ return x < y && y > 5 ? odds : 0
|
|
164
|
+ }
|
|
165
|
+}
|
|
166
|
+
|
|
167
|
+// 进球数
|
|
168
|
+function computePoints(part, match, rq) {
|
|
169
|
+ const [x, y] = match
|
|
170
|
+ const {ruleCode, odds} = part.rules
|
|
171
|
+
|
|
172
|
+ switch (ruleCode) {
|
|
173
|
+ case 'ft-p0':
|
|
174
|
+ return x == 0 && y == 0 ? odds : 0
|
|
175
|
+ case 'ft-p1':
|
|
176
|
+ return x + y == 1 ? odds : 0
|
|
177
|
+ case 'ft-p2':
|
|
178
|
+ return x + y == 2 ? odds : 0
|
|
179
|
+ case 'ft-p3':
|
|
180
|
+ return x + y == 3 ? odds : 0
|
|
181
|
+ case 'ft-p4':
|
|
182
|
+ return x + y == 4 ? odds : 0
|
|
183
|
+ case 'ft-p5':
|
|
184
|
+ return x + y == 5 ? odds : 0
|
|
185
|
+ case 'ft-p6':
|
|
186
|
+ return x + y == 6 ? odds : 0
|
|
187
|
+ default:
|
|
188
|
+ return x + y > 6 ? odds : 0
|
|
189
|
+ }
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+// 半全场
|
|
193
|
+function computeDouble(part, match, rq) {
|
|
194
|
+ const [x, y] = match
|
|
195
|
+ const {ruleCode, odds} = part.rules
|
|
196
|
+
|
|
197
|
+ switch (ruleCode) {
|
|
198
|
+ case 'ft-ww':
|
|
199
|
+ case 'ft-dw':
|
|
200
|
+ case 'ft-lw':
|
|
201
|
+ return x > y ? odds : 0
|
|
202
|
+ case 'ft-wd':
|
|
203
|
+ case 'ft-dd':
|
|
204
|
+ case 'ft-ld':
|
|
205
|
+ return x == y ? odds : 0
|
|
206
|
+ default:
|
|
207
|
+ return x < y ? odds : 0
|
|
208
|
+ }
|
|
209
|
+}
|
|
210
|
+
|