thlorenz / pec

Poker equity calculator. Compares two combos or one combo against a range to compute winning equity.
https://thlorenz.github.io/pec
MIT License
18 stars 6 forks source link

pec build status

Poker equity calculator. Compares two combos or one combo against a range to compute winning equity.

const { raceRange, rates } = require('pec')

const combo = [ 'Jh', 'Js' ]
const range = [
  [ 'Kh', 'Ks' ], [ 'Kh', 'Kd' ], [ 'Kh', 'Kc' ],
  [ 'Ks', 'Kd' ], [ 'Ks', 'Kc' ], [ 'Kd', 'Kc' ],
  [ 'Qh', 'Qs' ], [ 'Qh', 'Qd' ], [ 'Qh', 'Qc' ],
  [ 'Qs', 'Qd' ], [ 'Qs', 'Qc' ], [ 'Qd', 'Qc' ]
]

const { win, loose, tie } = raceRange(combo, range, 1E4)
const { winRate, looseRate, tieRate } = rates({ win, loose, tie })

console.log('JJ performs as follows vs. [ KK, QQ ]')
console.log('win: %d%% (%d times)', winRate, win)
console.log('loose: %d%% (%d times)', looseRate, loose)
console.log('tie: %d%% (%d times)', tieRate, tie)
JJ performs as follows vs. [ KK, QQ ]
win: 18.13% (21750 times)
loose: 81.43% (97718 times)
tie: 0.44% (532 times)

For more examples see the tests and the webworker example.

You can launch the web worker via npm install && npm run demo.

Installation

npm install pec

API

BackgroundWorker.raceRange

Parameters

Returns Number the uid generated to identify this background job, the same uid will be included in the message the result to identify it with the job

BackgroundWorker.stop

Stops any races in progress.

createBackgroundWorker

Creates a background worker which uses a web worker under the hood to process race requests.

Parameters

Returns BackgroundWorker backgroundWorker

raceCodesForBoard

Same as @see raceCombosForBoard, except that the combo cards are given as their codes obtained via phe cardCodes.

Parameters

raceCodes

Same as @see raceCombos, except that the combo cards are given as their codes obtained via phe cardCodes.

Parameters

raceRangeCodesForBoard

Same as @see raceRangeForBoard, except that the combo, range cards and board are given as their codes obtained via phe cardCodes.

Parameters

raceRangeCodes

Same as @see raceRange, except that the combo and range cards are given as their codes obtained via phe cardCodes.

Parameters

raceCombosForBoard

Races two combos against each other.

Parameters

Returns any count of how many times combo1 wins, looses or ties, i.e. { win, loose, tie }

raceCombos

Races two combos against each other.

Parameters

Returns any count of how many times combo1 wins, looses or ties, i.e. { win, loose, tie }

raceRangeForBoard

Race the given combo vs. the given combo to count number of wins, losses and ties. The boards created for the race will include all cards of the given board.

Parameters

Returns any count of how many times the combo wins, looses or ties, i.e. { win, loose, tie }

raceRange

Race the given combo vs. the given combo to count number of wins, losses and ties.

Parameters

Returns any count of how many times the combo wins, looses or ties, i.e. { win, loose, tie }

rates

Given win, loose and tie count it converts those to winning rates in percent.

Parameters

Returns Object win rates `{ winRate, looseRate, tieRate, combos? }

License

MIT