Your Name vor 4 Jahren
Ursprung
Commit
cba9a3e528
2 geänderte Dateien mit 111 neuen und 116 gelöschten Zeilen
  1. 44
    116
      src/util/FootballPrice.js
  2. 67
    0
      src/util/Sports.js

+ 44
- 116
src/util/FootballPrice.js Datei anzeigen

@@ -1,11 +1,8 @@
1
-/* eslint-disable */
2
-import { descartes, combination } from './math'
3
-
4 1
 // 模拟比赛得分
5 2
 const matches = [
6 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 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 8
 const playWayFunc = {
@@ -13,80 +10,14 @@ const playWayFunc = {
13 10
   'ft-wdls': computeWDLS,
14 11
   'ft-score': computeScore,
15 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 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 23
   matches.forEach(match => {
@@ -117,7 +48,6 @@ function GetMinAndMax (allParts, match, rq) {
117 48
         const fn = playWayFunc[wayCode]
118 49
         return fn(grp, match, rq)
119 50
       }).filter(Boolean).reduce((acc, x) => acc * x, 1)
120
-
121 51
     }).reduce((acc, x) => acc + x, 0)
122 52
 
123 53
     if (minPrice === 0 || minPrice > price) {
@@ -139,7 +69,7 @@ function computeWDL (part, match, rq) {
139 69
     case 'ft-win':
140 70
       return x > y ? odds : 0
141 71
     case 'ft-dead':
142
-      return x == y ? odds : 0
72
+      return x === y ? odds : 0
143 73
     default:
144 74
       return x < y ? odds : 0
145 75
   }
@@ -154,7 +84,7 @@ function computeWDLS (part, match, rq) {
154 84
     case 'ft-sp-win':
155 85
       return x + rq > y ? odds : 0
156 86
     case 'ft-sp-dead':
157
-      return x + rq == y ? odds : 0
87
+      return x + rq === y ? odds : 0
158 88
     default:
159 89
       return x + rq < y ? odds : 0
160 90
   }
@@ -167,65 +97,65 @@ function computeScore (part, match, rq) {
167 97
 
168 98
   switch (ruleCode) {
169 99
     case 'ft-w10':
170
-      return x == 1 && y == 0 ? odds : 0
100
+      return x === 1 && y === 0 ? odds : 0
171 101
     case 'ft-w20':
172
-      return x == 2 && y == 0 ? odds : 0
102
+      return x === 2 && y === 0 ? odds : 0
173 103
     case 'ft-w21':
174
-      return x == 2 && y == 1 ? odds : 0
104
+      return x === 2 && y === 1 ? odds : 0
175 105
     case 'ft-w30':
176
-      return x == 3 && y == 0 ? odds : 0
106
+      return x === 3 && y === 0 ? odds : 0
177 107
     case 'ft-w31':
178
-      return x == 3 && y == 1 ? odds : 0
108
+      return x === 3 && y === 1 ? odds : 0
179 109
     case 'ft-w32':
180
-      return x == 3 && y == 2 ? odds : 0
110
+      return x === 3 && y === 2 ? odds : 0
181 111
     case 'ft-w40':
182
-      return x == 4 && y == 0 ? odds : 0
112
+      return x === 4 && y === 0 ? odds : 0
183 113
     case 'ft-w41':
184
-      return x == 4 && y == 1 ? odds : 0
114
+      return x === 4 && y === 1 ? odds : 0
185 115
     case 'ft-w42':
186
-      return x == 4 && y == 2 ? odds : 0
116
+      return x === 4 && y === 2 ? odds : 0
187 117
     case 'ft-w50':
188
-      return x == 5 && y == 0 ? odds : 0
118
+      return x === 5 && y === 0 ? odds : 0
189 119
     case 'ft-w51':
190
-      return x == 5 && y == 1 ? odds : 0
120
+      return x === 5 && y === 1 ? odds : 0
191 121
     case 'ft-w52':
192
-      return x == 5 && y == 2 ? odds : 0
122
+      return x === 5 && y === 2 ? odds : 0
193 123
     case 'ft-w99':
194 124
       return x > 5 && x > y ? odds : 0
195 125
     case 'ft-d00':
196
-      return x == 0 && x == y ? odds : 0
126
+      return x === 0 && x === y ? odds : 0
197 127
     case 'ft-d11':
198
-      return x == 1 && x == y ? odds : 0
128
+      return x === 1 && x === y ? odds : 0
199 129
     case 'ft-d22':
200
-      return x == 2 && x == y ? odds : 0
130
+      return x === 2 && x === y ? odds : 0
201 131
     case 'ft-d33':
202
-      return x == 3 && x == y ? odds : 0
132
+      return x === 3 && x === y ? odds : 0
203 133
     case 'ft-d99':
204
-      return x > 5 && x == y ? odds : 0
134
+      return x > 5 && x === y ? odds : 0
205 135
     case 'ft-l01':
206
-      return x == 0 && y == 1 ? odds : 0
136
+      return x === 0 && y === 1 ? odds : 0
207 137
     case 'ft-l02':
208
-      return x == 0 && y == 2 ? odds : 0
138
+      return x === 0 && y === 2 ? odds : 0
209 139
     case 'ft-l12':
210
-      return x == 1 && y == 2 ? odds : 0
140
+      return x === 1 && y === 2 ? odds : 0
211 141
     case 'ft-l03':
212
-      return x == 0 && y == 3 ? odds : 0
142
+      return x === 0 && y === 3 ? odds : 0
213 143
     case 'ft-l13':
214
-      return x == 1 && y == 3 ? odds : 0
144
+      return x === 1 && y === 3 ? odds : 0
215 145
     case 'ft-l23':
216
-      return x == 2 && y == 3 ? odds : 0
146
+      return x === 2 && y === 3 ? odds : 0
217 147
     case 'ft-l04':
218
-      return x == 0 && y == 4 ? odds : 0
148
+      return x === 0 && y === 4 ? odds : 0
219 149
     case 'ft-l14':
220
-      return x == 1 && y == 4 ? odds : 0
150
+      return x === 1 && y === 4 ? odds : 0
221 151
     case 'ft-l24':
222
-      return x == 2 && y == 4 ? odds : 0
152
+      return x === 2 && y === 4 ? odds : 0
223 153
     case 'ft-l05':
224
-      return x == 0 && y == 5 ? odds : 0
154
+      return x === 0 && y === 5 ? odds : 0
225 155
     case 'ft-l15':
226
-      return x == 1 && y == 5 ? odds : 0
156
+      return x === 1 && y === 5 ? odds : 0
227 157
     case 'ft-l25':
228
-      return x == 2 && y == 5 ? odds : 0
158
+      return x === 2 && y === 5 ? odds : 0
229 159
     default:
230 160
       return x < y && y > 5 ? odds : 0
231 161
   }
@@ -238,19 +168,19 @@ function computePoints (part, match, rq) {
238 168
 
239 169
   switch (ruleCode) {
240 170
     case 'ft-p0':
241
-      return x == 0 && y == 0 ? odds : 0
171
+      return x === 0 && y === 0 ? odds : 0
242 172
     case 'ft-p1':
243
-      return x + y == 1 ? odds : 0
173
+      return x + y === 1 ? odds : 0
244 174
     case 'ft-p2':
245
-      return x + y == 2 ? odds : 0
175
+      return x + y === 2 ? odds : 0
246 176
     case 'ft-p3':
247
-      return x + y == 3 ? odds : 0
177
+      return x + y === 3 ? odds : 0
248 178
     case 'ft-p4':
249
-      return x + y == 4 ? odds : 0
179
+      return x + y === 4 ? odds : 0
250 180
     case 'ft-p5':
251
-      return x + y == 5 ? odds : 0
181
+      return x + y === 5 ? odds : 0
252 182
     case 'ft-p6':
253
-      return x + y == 6 ? odds : 0
183
+      return x + y === 6 ? odds : 0
254 184
     default:
255 185
       return x + y > 6 ? odds : 0
256 186
   }
@@ -269,10 +199,8 @@ function computeDouble (part, match, rq) {
269 199
     case 'ft-wd':
270 200
     case 'ft-dd':
271 201
     case 'ft-ld':
272
-      return x == y ? odds : 0
202
+      return x === y ? odds : 0
273 203
     default:
274 204
       return x < y ? odds : 0
275 205
   }
276 206
 }
277
-
278
-export default GetAllParts

+ 67
- 0
src/util/Sports.js Datei anzeigen

@@ -0,0 +1,67 @@
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
+}