Your Name пре 4 година
родитељ
комит
6372f34a26
2 измењених фајлова са 0 додато и 230 уклоњено
  1. 0
    210
      src/util/football_price.js
  2. 0
    20
      src/util/math.js

+ 0
- 210
src/util/football_price.js Прегледај датотеку

@@ -1,210 +0,0 @@
1
-import { descartes } from './math'
2
-
3
-// 模拟比赛得分
4
-const matchResultMockes = [
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
-  matchResultMockes.forEach(matchResultMock => {
26
-    const [min, max] = getMinAndMax(allParts, matchResultMock, 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, matchResultMock, 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, matchResultMock, 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, matchResultMock, rq) {
68
-  const [x, y] = matchResultMock
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, matchResultMock, rq) {
83
-  const [x, y] = matchResultMock
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, matchResultMock, rq) {
98
-  const [x, y] = matchResultMock
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, matchResultMock, rq) {
169
-  const [x, y] = matchResultMock
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, matchResultMock, rq) {
194
-  const [x, y] = matchResultMock
195
-
196
-  const {ruleCode, odds} = part.rules
197
-
198
-  switch (ruleCode) {
199
-    case 'ft-ww':
200
-    case 'ft-dw':
201
-    case 'ft-lw':
202
-      return x > y ? odds : 0
203
-    case 'ft-wd':
204
-    case 'ft-dd':
205
-    case 'ft-ld':
206
-      return x == y ? odds : 0
207
-    default:
208
-      return x < y ? odds : 0
209
-  }
210
-}

+ 0
- 20
src/util/math.js Прегледај датотеку

@@ -1,20 +0,0 @@
1
-
2
-// 笛卡尔积
3
-export function descartes(...args) {
4
-  if (args.length < 2) return args
5
-
6
-  if (args.length === 2) {
7
-    const [a, b] = args
8
-    return a.map(x => ([x, b])).reduce((acc, x) => {
9
-      const [i, j] = x
10
-      return [
11
-        ...acc,
12
-        ...(j.map(y => ([i, y])))
13
-      ]
14
-    }, [])
15
-  } else {
16
-    const [a, ...b] = args
17
-    const tmp = descartes(...b)
18
-    return descartes(a, tmp).map(([a, b]) => ([a, ...b]))
19
-  }
20
-}