-
Notifications
You must be signed in to change notification settings - Fork 7
/
RangeEquity.js
49 lines (40 loc) · 1.21 KB
/
RangeEquity.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
import Range, { groups } from './Range'
import { combination } from 'js-combinatorics'
import * as pokerTools from 'poker-tools'
/**
* The RangeEquity class calculates the showdown equity
* of multiple hand ranges.
*/
export class RangeEquity {
constructor(ranges = []) {
this.ranges = ranges.map(not => new Range(not))
}
get equityCalculators() {
return this.matchups.map((matchup) => () => {
try {
const oddsCalculator = pokerTools.OddsCalculator.calculateEquity(
matchup.map(i => pokerTools.CardGroup.fromString(i.name))
)
return {
matchup,
equities: oddsCalculator.equities
}
} catch(error) {
throw new Error(`Error with matchup: ${matchup.join(',')}`)
}
})
}
get matchups() {
const r1 = this.ranges[0].chain.get('combos').uniqBy('name').value()
const r2 = this.ranges[1].chain.get('combos').uniqBy('name').value()
const matchups = []
r1.forEach((h1) => {
r2.filter(h2 => !!h1.map(i => i.rank).find(i => h2.map(h => h.rank).indexOf(i) === -1)).forEach(h2 => {
const matchup = [h1,h2]
matchups.push(matchup)
})
})
return matchups
}
}
export default RangeEquity