Your Name 4 years ago
parent
commit
cba9a3e528
2 changed files with 111 additions and 116 deletions
  1. 44
    116
      src/util/FootballPrice.js
  2. 67
    0
      src/util/Sports.js

+ 44
- 116
src/util/FootballPrice.js View File

1
-/* eslint-disable */
2
-import { descartes, combination } from './math'
3
-
4
 // 模拟比赛得分
1
 // 模拟比赛得分
5
 const matches = [
2
 const matches = [
6
   [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],
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],
7
   [0, 0], [1, 1], [2, 2], [3, 3], [99, 99],
4
   [0, 0], [1, 1], [2, 2], [3, 3], [99, 99],
8
-  [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],
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]
9
 ]
6
 ]
10
 
7
 
11
 const playWayFunc = {
8
 const playWayFunc = {
13
   'ft-wdls': computeWDLS,
10
   'ft-wdls': computeWDLS,
14
   'ft-score': computeScore,
11
   'ft-score': computeScore,
15
   'ft-points': computePoints,
12
   'ft-points': computePoints,
16
-  'ft-double': computeDouble,
17
-}
18
-
19
-/**
20
- * 依据投注列表,生成所有可能的排列组合
21
- * @param {*} noteList 投注列表
22
- * @param {*} passDict 过关字典
23
- */
24
-function GetAllParts (noteList, passDict) {
25
-  // 转换过关字典
26
-  const passArr = [
27
-    passDict.level1,
28
-    passDict.level2,
29
-    passDict.level3,
30
-    passDict.level4,
31
-    passDict.level5,
32
-    passDict.level6,
33
-    passDict.level7,
34
-    passDict.level8,
35
-  ]
36
-
37
-  // 整理数据
38
-  // [a, b, c, d] => [[a], [b1, b2], [c1, c2], [d]] == [A, B, C, D]
39
-  const noteArr = noteList.map(x => x.detailList.map(y => ({ ...x, detail: y })))
40
-
41
-  // 从投注场次中, 选择过关场次组合
42
-  // 比如投注4场比赛, 过关方式为3串4
43
-  // [A, B, C, D] =>
44
-  // [[A, B, C],
45
-  //  [A, B, D],
46
-  //  [A, C, D],
47
-  //  [B, C, D]]
48
-  const composeNote = combination(noteArr, passDict.unitNum)
49
-
50
-  // 拆分场次组合
51
-  const disposeNote = composeNote.reduce((acc, note) => {
52
-    // [A, B, C] =>
53
-    //  [a, b1, c1],
54
-    //  [a, b1, c2],
55
-    //  [a, b2, c1],
56
-    //  [a, b2, c2]
57
-    const unpack = descartes(...note)
58
-    return [
59
-      ...acc,
60
-      ...unpack
61
-    ]
62
-  }, [])
63
-
64
-  // 组合过关场景
65
-  const allParts = disposeNote.map(noteGrp => {
66
-    // 比如 3串4 = 3个2串1 + 1个3串1
67
-    // [a, b, c] =>
68
-    // [[a, b],
69
-    //  [a, c],
70
-    //  [b, c],
71
-    //  [a, b, c]]
72
-    return passArr.map((passNum, inx) => {
73
-      // 当前关卡不需要场次
74
-      if (!passNum) return undefined
75
-      
76
-      const requreNum = inx + 1
77
-      return combination(noteGrp, requreNum)
78
-    }).filter(Boolean).reduce((acc, grp) => ([...acc, ...grp]), [])
79
-  })
80
-
81
-  const sum = allParts.reduce((s, x) => s + x.length, 0)
82
-  return { sum, allParts }
13
+  'ft-double': computeDouble
83
 }
14
 }
84
 
15
 
85
 // 遍历模拟比赛获取最大, 最小奖金
16
 // 遍历模拟比赛获取最大, 最小奖金
86
 // rq 让球数
17
 // rq 让球数
87
-function GetPrice (allParts, rq) {
88
-  let minPrice = undefined
89
-  let maxPrice = undefined
18
+export function GetPrice (allParts, rq) {
19
+  let minPrice
20
+  let maxPrice
90
 
21
 
91
   // 遍历模拟比赛的各种可能
22
   // 遍历模拟比赛的各种可能
92
   matches.forEach(match => {
23
   matches.forEach(match => {
117
         const fn = playWayFunc[wayCode]
48
         const fn = playWayFunc[wayCode]
118
         return fn(grp, match, rq)
49
         return fn(grp, match, rq)
119
       }).filter(Boolean).reduce((acc, x) => acc * x, 1)
50
       }).filter(Boolean).reduce((acc, x) => acc * x, 1)
120
-
121
     }).reduce((acc, x) => acc + x, 0)
51
     }).reduce((acc, x) => acc + x, 0)
122
 
52
 
123
     if (minPrice === 0 || minPrice > price) {
53
     if (minPrice === 0 || minPrice > price) {
139
     case 'ft-win':
69
     case 'ft-win':
140
       return x > y ? odds : 0
70
       return x > y ? odds : 0
141
     case 'ft-dead':
71
     case 'ft-dead':
142
-      return x == y ? odds : 0
72
+      return x === y ? odds : 0
143
     default:
73
     default:
144
       return x < y ? odds : 0
74
       return x < y ? odds : 0
145
   }
75
   }
154
     case 'ft-sp-win':
84
     case 'ft-sp-win':
155
       return x + rq > y ? odds : 0
85
       return x + rq > y ? odds : 0
156
     case 'ft-sp-dead':
86
     case 'ft-sp-dead':
157
-      return x + rq == y ? odds : 0
87
+      return x + rq === y ? odds : 0
158
     default:
88
     default:
159
       return x + rq < y ? odds : 0
89
       return x + rq < y ? odds : 0
160
   }
90
   }
167
 
97
 
168
   switch (ruleCode) {
98
   switch (ruleCode) {
169
     case 'ft-w10':
99
     case 'ft-w10':
170
-      return x == 1 && y == 0 ? odds : 0
100
+      return x === 1 && y === 0 ? odds : 0
171
     case 'ft-w20':
101
     case 'ft-w20':
172
-      return x == 2 && y == 0 ? odds : 0
102
+      return x === 2 && y === 0 ? odds : 0
173
     case 'ft-w21':
103
     case 'ft-w21':
174
-      return x == 2 && y == 1 ? odds : 0
104
+      return x === 2 && y === 1 ? odds : 0
175
     case 'ft-w30':
105
     case 'ft-w30':
176
-      return x == 3 && y == 0 ? odds : 0
106
+      return x === 3 && y === 0 ? odds : 0
177
     case 'ft-w31':
107
     case 'ft-w31':
178
-      return x == 3 && y == 1 ? odds : 0
108
+      return x === 3 && y === 1 ? odds : 0
179
     case 'ft-w32':
109
     case 'ft-w32':
180
-      return x == 3 && y == 2 ? odds : 0
110
+      return x === 3 && y === 2 ? odds : 0
181
     case 'ft-w40':
111
     case 'ft-w40':
182
-      return x == 4 && y == 0 ? odds : 0
112
+      return x === 4 && y === 0 ? odds : 0
183
     case 'ft-w41':
113
     case 'ft-w41':
184
-      return x == 4 && y == 1 ? odds : 0
114
+      return x === 4 && y === 1 ? odds : 0
185
     case 'ft-w42':
115
     case 'ft-w42':
186
-      return x == 4 && y == 2 ? odds : 0
116
+      return x === 4 && y === 2 ? odds : 0
187
     case 'ft-w50':
117
     case 'ft-w50':
188
-      return x == 5 && y == 0 ? odds : 0
118
+      return x === 5 && y === 0 ? odds : 0
189
     case 'ft-w51':
119
     case 'ft-w51':
190
-      return x == 5 && y == 1 ? odds : 0
120
+      return x === 5 && y === 1 ? odds : 0
191
     case 'ft-w52':
121
     case 'ft-w52':
192
-      return x == 5 && y == 2 ? odds : 0
122
+      return x === 5 && y === 2 ? odds : 0
193
     case 'ft-w99':
123
     case 'ft-w99':
194
       return x > 5 && x > y ? odds : 0
124
       return x > 5 && x > y ? odds : 0
195
     case 'ft-d00':
125
     case 'ft-d00':
196
-      return x == 0 && x == y ? odds : 0
126
+      return x === 0 && x === y ? odds : 0
197
     case 'ft-d11':
127
     case 'ft-d11':
198
-      return x == 1 && x == y ? odds : 0
128
+      return x === 1 && x === y ? odds : 0
199
     case 'ft-d22':
129
     case 'ft-d22':
200
-      return x == 2 && x == y ? odds : 0
130
+      return x === 2 && x === y ? odds : 0
201
     case 'ft-d33':
131
     case 'ft-d33':
202
-      return x == 3 && x == y ? odds : 0
132
+      return x === 3 && x === y ? odds : 0
203
     case 'ft-d99':
133
     case 'ft-d99':
204
-      return x > 5 && x == y ? odds : 0
134
+      return x > 5 && x === y ? odds : 0
205
     case 'ft-l01':
135
     case 'ft-l01':
206
-      return x == 0 && y == 1 ? odds : 0
136
+      return x === 0 && y === 1 ? odds : 0
207
     case 'ft-l02':
137
     case 'ft-l02':
208
-      return x == 0 && y == 2 ? odds : 0
138
+      return x === 0 && y === 2 ? odds : 0
209
     case 'ft-l12':
139
     case 'ft-l12':
210
-      return x == 1 && y == 2 ? odds : 0
140
+      return x === 1 && y === 2 ? odds : 0
211
     case 'ft-l03':
141
     case 'ft-l03':
212
-      return x == 0 && y == 3 ? odds : 0
142
+      return x === 0 && y === 3 ? odds : 0
213
     case 'ft-l13':
143
     case 'ft-l13':
214
-      return x == 1 && y == 3 ? odds : 0
144
+      return x === 1 && y === 3 ? odds : 0
215
     case 'ft-l23':
145
     case 'ft-l23':
216
-      return x == 2 && y == 3 ? odds : 0
146
+      return x === 2 && y === 3 ? odds : 0
217
     case 'ft-l04':
147
     case 'ft-l04':
218
-      return x == 0 && y == 4 ? odds : 0
148
+      return x === 0 && y === 4 ? odds : 0
219
     case 'ft-l14':
149
     case 'ft-l14':
220
-      return x == 1 && y == 4 ? odds : 0
150
+      return x === 1 && y === 4 ? odds : 0
221
     case 'ft-l24':
151
     case 'ft-l24':
222
-      return x == 2 && y == 4 ? odds : 0
152
+      return x === 2 && y === 4 ? odds : 0
223
     case 'ft-l05':
153
     case 'ft-l05':
224
-      return x == 0 && y == 5 ? odds : 0
154
+      return x === 0 && y === 5 ? odds : 0
225
     case 'ft-l15':
155
     case 'ft-l15':
226
-      return x == 1 && y == 5 ? odds : 0
156
+      return x === 1 && y === 5 ? odds : 0
227
     case 'ft-l25':
157
     case 'ft-l25':
228
-      return x == 2 && y == 5 ? odds : 0
158
+      return x === 2 && y === 5 ? odds : 0
229
     default:
159
     default:
230
       return x < y && y > 5 ? odds : 0
160
       return x < y && y > 5 ? odds : 0
231
   }
161
   }
238
 
168
 
239
   switch (ruleCode) {
169
   switch (ruleCode) {
240
     case 'ft-p0':
170
     case 'ft-p0':
241
-      return x == 0 && y == 0 ? odds : 0
171
+      return x === 0 && y === 0 ? odds : 0
242
     case 'ft-p1':
172
     case 'ft-p1':
243
-      return x + y == 1 ? odds : 0
173
+      return x + y === 1 ? odds : 0
244
     case 'ft-p2':
174
     case 'ft-p2':
245
-      return x + y == 2 ? odds : 0
175
+      return x + y === 2 ? odds : 0
246
     case 'ft-p3':
176
     case 'ft-p3':
247
-      return x + y == 3 ? odds : 0
177
+      return x + y === 3 ? odds : 0
248
     case 'ft-p4':
178
     case 'ft-p4':
249
-      return x + y == 4 ? odds : 0
179
+      return x + y === 4 ? odds : 0
250
     case 'ft-p5':
180
     case 'ft-p5':
251
-      return x + y == 5 ? odds : 0
181
+      return x + y === 5 ? odds : 0
252
     case 'ft-p6':
182
     case 'ft-p6':
253
-      return x + y == 6 ? odds : 0
183
+      return x + y === 6 ? odds : 0
254
     default:
184
     default:
255
       return x + y > 6 ? odds : 0
185
       return x + y > 6 ? odds : 0
256
   }
186
   }
269
     case 'ft-wd':
199
     case 'ft-wd':
270
     case 'ft-dd':
200
     case 'ft-dd':
271
     case 'ft-ld':
201
     case 'ft-ld':
272
-      return x == y ? odds : 0
202
+      return x === y ? odds : 0
273
     default:
203
     default:
274
       return x < y ? odds : 0
204
       return x < y ? odds : 0
275
   }
205
   }
276
 }
206
 }
277
-
278
-export default GetAllParts

+ 67
- 0
src/util/Sports.js View File

1
+import { descartes, combination } from './math'
2
+
3
+/**
4
+ * 依据投注列表,生成所有可能的排列组合
5
+ * @param {*} noteList 投注列表
6
+ * @param {*} passDict 过关字典
7
+ */
8
+export function GetAllParts (noteList, passDict) {
9
+  // 转换过关字典
10
+  const passArr = [
11
+    passDict.level1,
12
+    passDict.level2,
13
+    passDict.level3,
14
+    passDict.level4,
15
+    passDict.level5,
16
+    passDict.level6,
17
+    passDict.level7,
18
+    passDict.level8,
19
+  ]
20
+
21
+  // 整理数据
22
+  // [a, b, c, d] => [[a], [b1, b2], [c1, c2], [d]] == [A, B, C, D]
23
+  const noteArr = noteList.map(x => x.detailList.map(y => ({ ...x, detail: y })))
24
+
25
+  // 从投注场次中, 选择过关场次组合
26
+  // 比如投注4场比赛, 过关方式为3串4
27
+  // [A, B, C, D] =>
28
+  // [[A, B, C],
29
+  //  [A, B, D],
30
+  //  [A, C, D],
31
+  //  [B, C, D]]
32
+  const composeNote = combination(noteArr, passDict.unitNum)
33
+
34
+  // 拆分场次组合
35
+  const disposeNote = composeNote.reduce((acc, note) => {
36
+    // [A, B, C] =>
37
+    //  [a, b1, c1],
38
+    //  [a, b1, c2],
39
+    //  [a, b2, c1],
40
+    //  [a, b2, c2]
41
+    const unpack = descartes(...note)
42
+    return [
43
+      ...acc,
44
+      ...unpack
45
+    ]
46
+  }, [])
47
+
48
+  // 组合过关场景
49
+  const allParts = disposeNote.map(noteGrp => {
50
+    // 比如 3串4 = 3个2串1 + 1个3串1
51
+    // [a, b, c] =>
52
+    // [[a, b],
53
+    //  [a, c],
54
+    //  [b, c],
55
+    //  [a, b, c]]
56
+    return passArr.map((passNum, inx) => {
57
+      // 当前关卡不需要场次
58
+      if (!passNum) return undefined
59
+      
60
+      const requreNum = inx + 1
61
+      return combination(noteGrp, requreNum)
62
+    }).filter(Boolean).reduce((acc, grp) => ([...acc, ...grp]), [])
63
+  })
64
+
65
+  const sum = allParts.reduce((s, x) => s + x.length, 0)
66
+  return { sum, allParts }
67
+}