zholdem
Version:
A library for computing holdem hands
142 lines (141 loc) • 5.19 kB
JavaScript
"use strict";
var simulator_1 = require("./simulator");
var card_1 = require("./card");
var PercentageEntry = (function () {
function PercentageEntry() {
}
return PercentageEntry;
}());
var generateCsvSheet = function (numberOfPlayer, simTimes) {
if (numberOfPlayer === void 0) { numberOfPlayer = 9; }
if (simTimes === void 0) { simTimes = 1000; }
/**
* a 13x13 rows [rol][col] as shown in http://i35.tinypic.com/anmufp.jpg, topleft is AA
* bottom right is 22.
* First index is the row, and second index is the column
* @type {Array}
*/
var sheet = [];
var percentageSheet = [];
for (var i = 0; i < 13; i++) {
var row = new Array(13);
sheet.push(row);
percentageSheet.push(new Array(13));
}
// Suited
for (var n1 = 12; n1 >= 0; n1--) {
for (var n2 = n1 - 1; n2 >= 0; n2--) {
var cardIndex1 = n1 * 4;
var cardIndex2 = n2 * 4;
var param = new simulator_1.SimulationParameter();
param.simulationTimes = simTimes;
param.knownPlayerCardIndices = [
[cardIndex1, cardIndex2],
];
param.knownCommunityCardIndices = [];
param.numOfPlayers = numberOfPlayer;
var result = simulator_1.Simulator.simulate(param);
sheet[12 - n1][12 - n2] = result;
}
console.log('XXX computed a line of suited odds, row card number = ' + n1);
}
// Off suited
for (var n1 = 12; n1 >= 0; n1--) {
for (var n2 = 12; n2 >= n1; n2--) {
var cardIndex1 = n1 * 4 + 1;
var cardIndex2 = n2 * 4;
var param = new simulator_1.SimulationParameter();
param.simulationTimes = simTimes;
param.knownPlayerCardIndices = [
[cardIndex1, cardIndex2],
];
param.knownCommunityCardIndices = [];
param.numOfPlayers = numberOfPlayer;
var result = simulator_1.Simulator.simulate(param);
sheet[12 - n1][12 - n2] = result;
}
console.log('XXX computed a line of off suited odds, row card number = ' + n1);
}
console.log(''); // newline
console.log('Total Equity');
for (var i = 0; i < 13; i++) {
var row = '';
for (var j = 0; j < 13; j++) {
row = row + sheet[i][j].totalEquityByPlayers[0].toFixed(4) + ',';
}
console.log(row);
}
console.log(''); // newline
console.log('Total Equity Confidential Interval of 95% (2*Sigma)');
for (var i = 0; i < 13; i++) {
var row = '';
for (var j = 0; j < 13; j++) {
row = row + (sheet[i][j].totalEquityStdByPlayers[0] * 2).toFixed(4) + ',';
}
console.log(row);
}
console.log(''); // newline
console.log('Total Equity Over Average Of Players');
for (var i = 0; i < 13; i++) {
var row = '';
for (var j = 0; j < 13; j++) {
row = row + ((sheet[i][j].totalEquityByPlayers[0] * numberOfPlayer - 1) * 100.0).toFixed(2) + '%,';
}
console.log(row);
}
// Compute top percentage;
var handRanks = [];
for (var i = 0; i < 13; i++) {
for (var j = 0; j < 13; j++) {
var p = new PercentageEntry();
p.positionInSheetI = i;
p.positionInSheetJ = j;
if (i == j)
p.numberOfEquivalentHands = 6;
else if (j > i)
p.numberOfEquivalentHands = 4;
else if (j < i)
p.numberOfEquivalentHands = 12;
p.simulationResult = sheet[i][j];
handRanks.push(p);
percentageSheet[i][j] = p;
}
}
handRanks.sort(function (p1, p2) {
return p1.simulationResult.totalEquityStdByPlayers[0] -
p2.simulationResult.totalEquityByPlayers[0];
}).reverse();
var currentHandsBeat = 1326;
for (var _i = 0, handRanks_1 = handRanks; _i < handRanks_1.length; _i++) {
var p = handRanks_1[_i];
p.handsBeat = currentHandsBeat - p.numberOfEquivalentHands;
currentHandsBeat -= p.numberOfEquivalentHands;
}
console.log(''); // newline
console.log('Percentage Map');
for (var i = 0; i < 13; i++) {
var row = '';
for (var j = 0; j < 13; j++) {
row = row + (percentageSheet[i][j].handsBeat / 1326 * 100).toFixed(2) + '%,';
}
console.log(row);
}
};
var computeAAvKK = function () {
console.log("Start 1s");
var param = new simulator_1.SimulationParameter();
param.simulationTimes = 1000;
param.knownPlayerCardIndices = [
[card_1.Cards.cardAs, card_1.Cards.cardAh],
[card_1.Cards.cardKs, card_1.Cards.cardKh],
];
param.knownCommunityCardIndices = [card_1.Cards.card2s, card_1.Cards.card3s, card_1.Cards.cardQh];
param.numOfPlayers = 2;
var result = simulator_1.Simulator.simulate(param);
console.log("Simulation result of 9 players in AA v KK color crush is: " +
(result.totalEquityByPlayers + ", split is " + result.splitEquitiesByPlaysers + "."));
};
var main = function () {
computeAAvKK();
};
main();