forked from teemutoikkanen/pec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webworker.js
66 lines (58 loc) · 1.55 KB
/
webworker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
const { rates } = require('../')
const assert = require('assert')
const backgroundWorker = require('../pec.background')
const { expandRange, arryifyCombo } = require('../test/util/util')
const worker = backgroundWorker(onupdate)
const range = 'TT+, AK+, AQs+'
const combo = 'JhJs'
const expandedRange = expandRange(range)
const expandedCombo = arryifyCombo(combo)
const div = document.createElement('div')
document.body.append(div)
const trackCombos = true
const raceId = worker.raceRange(expandedCombo, expandedRange, 1E6, trackCombos)
function onupdate({ win, loose, tie, iterations, combos, uid }) {
assert.equal(raceId, uid, 'uid in response needs to match id of initiated race')
const { winRate, looseRate, tieRate, combos: comboRates } = rates({
win
, loose
, tie
, combos
})
var comboRows = ''
for (const [ k, { winRate, looseRate, tieRate } ] of comboRates) {
comboRows += (
`<tr>
<td>${k}
<td>${winRate}%</td>
<td>${looseRate}%</td>
<td>${tieRate}%</td>
</tr>`
)
}
div.innerHTML = `
<h5>Combo: ${combo} vs. Range: ${range}</h5>
<table>
<thead>
<tr>
<td>Combo</td>
<td>Win</td>
<td>Loose</td>
<td>Tie</td>
<td>Iterations</td>
</tr>
</thead>
<tbody>
<tr>
<td>All</td>
<td>${winRate}%</td>
<td>${looseRate}%</td>
<td>${tieRate}%</td>
<td>${iterations}</td>
</tr>
${comboRows}
</tbody>
</table>
`
}