Compare commits
16 Commits
9be66d6cc0
...
master
Author | SHA1 | Date | |
---|---|---|---|
fc55bd2830
|
|||
69f925e0f6
|
|||
2cec666f76
|
|||
4cbdf71f0a
|
|||
e5ca195346
|
|||
bc47818a9d
|
|||
a3be1cb8f1 | |||
890e0ab580
|
|||
6fe4171c00
|
|||
f234fe0a08
|
|||
efd32e69e7
|
|||
20c07af542
|
|||
999c2960fd
|
|||
82230c7dbf
|
|||
a9710113d4
|
|||
5f0cea9cf1
|
10
README.md
10
README.md
@ -1,2 +1,12 @@
|
|||||||
# schmirc
|
# schmirc
|
||||||
|
|
||||||
|
A poker bot for the hirc poker bot by nilscc: https://github.com/nilscc/hirc
|
||||||
|
|
||||||
|
## Installation & Usage
|
||||||
|
npm i
|
||||||
|
|
||||||
|
cp config.example.json config.json
|
||||||
|
|
||||||
|
edit config.json
|
||||||
|
|
||||||
|
npm start
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
{
|
{
|
||||||
|
"bot": {
|
||||||
|
"autojoin": false,
|
||||||
|
"debug": false,
|
||||||
|
"verbose": 3,
|
||||||
|
"pokerbot": "hirc",
|
||||||
|
"channel": "#poker"
|
||||||
|
},
|
||||||
"clients": [{
|
"clients": [{
|
||||||
"type": "irc",
|
"type": "irc",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
Binary file not shown.
@ -7,8 +7,7 @@
|
|||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./src/index.mjs",
|
"start": "node ./src/index.mjs"
|
||||||
"build": "cd ./data && ./generate_table"
|
|
||||||
},
|
},
|
||||||
"author": "Flummi",
|
"author": "Flummi",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
1410
src/inc/constants.mjs
Normal file
1410
src/inc/constants.mjs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,44 +1,84 @@
|
|||||||
import fs from 'node:fs';
|
import constants from './constants.mjs';
|
||||||
|
|
||||||
export default new class handranker {
|
export default new class handranker {
|
||||||
#ranks;
|
rankHands(board, hand) {
|
||||||
|
let bestHand = this.calcBestHand([...board, ...hand].map(c => this.toCard(c)));
|
||||||
|
|
||||||
constructor() {
|
if(bestHand > 6000) bestHand += 2000;
|
||||||
this.#ranks = fs.readFileSync('./data/HandRanks.dat');
|
|
||||||
|
|
||||||
this.handtypes = [
|
|
||||||
"InvalidHand", "HighCard", "Pair",
|
|
||||||
"TwoPairs", "ThreeOfAKind", "Straight",
|
|
||||||
"Flush", "FullHouse", "FourOfAKind",
|
|
||||||
"StraightFlush"
|
|
||||||
];
|
|
||||||
|
|
||||||
this.cards = [''];
|
|
||||||
for(const cv of [..."23456789TJQKA"])
|
|
||||||
for(const cs of [..."CDHS"])
|
|
||||||
this.cards.push(cv + cs);
|
|
||||||
};
|
|
||||||
evalHand(cards) {
|
|
||||||
if(!this.#ranks)
|
|
||||||
throw new Error("HandRanks.dat not loaded, run 'npm run build' first!");
|
|
||||||
|
|
||||||
if(![7,6,5,3].includes(cards.length))
|
|
||||||
throw new Error("Hand must be 3, 5, 6, or 7 cards");
|
|
||||||
|
|
||||||
cards = cards.map(c => this.cards.indexOf(c));
|
|
||||||
|
|
||||||
let p = 53;
|
|
||||||
for(let i = 0; i < cards.length; i++)
|
|
||||||
p = this.#ranks.readUInt32LE((p + cards[i]) * 4);
|
|
||||||
|
|
||||||
if(cards.length == 5 || cards.length == 6)
|
|
||||||
p = this.#ranks.readUInt32LE(p * 4);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handType: p >> 12,
|
rank: bestHand,
|
||||||
handRank: p & 0x00000fff,
|
percentage: (9999 - bestHand) / 100,
|
||||||
value: p,
|
combination: this.toCombination(bestHand)
|
||||||
handName: this.handtypes[p >> 12]
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
toCombination(r) {
|
||||||
|
if(r > 6185) return 'HighCard';
|
||||||
|
if(r > 3325) return 'Pair';
|
||||||
|
if(r > 2467) return 'TwoPairs';
|
||||||
|
if(r > 1609) return 'ThreeOfAKind';
|
||||||
|
if(r > 1599) return 'Straight';
|
||||||
|
if(r > 322) return 'Flush';
|
||||||
|
if(r > 166) return 'FullHouse';
|
||||||
|
if(r > 10) return 'FourOfAKind';
|
||||||
|
return 'StraightFlush';
|
||||||
|
};
|
||||||
|
|
||||||
|
cactusFastRankHand(hand) {
|
||||||
|
const [c0, c1, c2, c3, c4] = hand;
|
||||||
|
if((c0 & c1 & c2 & c3 & c4 & 0xf000) !== 0)
|
||||||
|
return constants.fastFlushes[(c0 | c1 | c2 | c3 | c4) >>> 16];
|
||||||
|
const r = constants.fastUnique5[(c0 | c1 | c2 | c3 | c4) >>> 16];
|
||||||
|
if(r)
|
||||||
|
return r;
|
||||||
|
let u = 0xe91aaa35 + (((c0 & 0xff) * (c1 & 0xff) * (c2 & 0xff) * (c3 & 0xff) * (c4 & 0xff)) | 0);
|
||||||
|
u = u ^ (u >>> 16);
|
||||||
|
u += u << 8;
|
||||||
|
u ^= u >>> 4;
|
||||||
|
return constants.hash[((u + (u << 2)) >>> 19) ^ (constants.hashAdjust[(u >>> 8) & 0x1ff] | 0)];
|
||||||
|
};
|
||||||
|
|
||||||
|
calcBestHand(hand) {
|
||||||
|
if(hand.length === 5)
|
||||||
|
return this.cactusFastRankHand([hand[0], hand[1], hand[2], hand[3], hand[4]])
|
||||||
|
if(hand.length === 6) {
|
||||||
|
const possibleHands = [
|
||||||
|
[hand[0], hand[1], hand[2], hand[3], hand[4]],
|
||||||
|
[hand[0], hand[1], hand[2], hand[3], hand[5]],
|
||||||
|
[hand[0], hand[1], hand[2], hand[4], hand[5]],
|
||||||
|
[hand[0], hand[1], hand[3], hand[4], hand[5]],
|
||||||
|
[hand[0], hand[2], hand[3], hand[4], hand[5]],
|
||||||
|
[hand[1], hand[2], hand[3], hand[4], hand[5]],
|
||||||
|
];
|
||||||
|
const sortedHands = possibleHands.map(h => this.cactusFastRankHand(h)).sort();
|
||||||
|
return sortedHands[0];
|
||||||
|
}
|
||||||
|
if(hand.length === 7) {
|
||||||
|
let r = 0;
|
||||||
|
let rank = 9999;
|
||||||
|
for(let i = 0; i < 21; i++) {
|
||||||
|
const inputHand = [
|
||||||
|
hand[constants.t7c5[i][0]],
|
||||||
|
hand[constants.t7c5[i][1]],
|
||||||
|
hand[constants.t7c5[i][2]],
|
||||||
|
hand[constants.t7c5[i][3]],
|
||||||
|
hand[constants.t7c5[i][4]],
|
||||||
|
];
|
||||||
|
r = this.cactusFastRankHand(inputHand);
|
||||||
|
if(r < rank)
|
||||||
|
rank = r;
|
||||||
|
}
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
throw `Hand ranker doesn't support ${hand.length} cards`;
|
||||||
|
};
|
||||||
|
|
||||||
|
toCard(playingCard) {
|
||||||
|
const rank = constants.runeToRank[playingCard[0]];
|
||||||
|
const suit = constants.runeToSuit[playingCard[1]];
|
||||||
|
if(!suit || rank === undefined)
|
||||||
|
throw `Invalid playing card: ${playingCard}`;
|
||||||
|
return ((1 << rank) << 16) | (suit << 12) | (rank << 8) | constants.PRIMES[rank];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
60
src/inc/helper.mjs
Normal file
60
src/inc/helper.mjs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import { bot } from '../index.mjs';
|
||||||
|
|
||||||
|
let _config;
|
||||||
|
try {
|
||||||
|
_config = JSON.parse(await fs.readFile('config.json'));
|
||||||
|
} catch(err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new class {
|
||||||
|
suits = { "♠": "S", "♣": "C", "♦": "D", "♥": "H" };
|
||||||
|
stripColors = msg => msg.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, '');
|
||||||
|
rand = (max = 1) => ~~(Math.random() * (max - 1) + 1);
|
||||||
|
|
||||||
|
config = {
|
||||||
|
get(k) {
|
||||||
|
return _config.bot[k];
|
||||||
|
},
|
||||||
|
async set(k, v) {
|
||||||
|
_config.bot[k] = v;
|
||||||
|
await this.writeConfig();
|
||||||
|
return this.get(k);
|
||||||
|
},
|
||||||
|
getFull() {
|
||||||
|
return _config;
|
||||||
|
},
|
||||||
|
async writeConfig() {
|
||||||
|
try {
|
||||||
|
await fs.writeFile('config.json', JSON.stringify(_config, null, 2));
|
||||||
|
return true;
|
||||||
|
} catch(err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
debug(msg, level = 2) {
|
||||||
|
const verbose = this.config.get('verbose');
|
||||||
|
if(level < verbose)
|
||||||
|
return;
|
||||||
|
switch(this.config.get('debug')) {
|
||||||
|
case 'chat': this.sendMsg(msg); break;
|
||||||
|
case true:
|
||||||
|
case 'console': console.log(msg); break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
parseCards(msg, output = []) {
|
||||||
|
for(const c of this.stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g))
|
||||||
|
output.push(c.length === 3 ? `T${this.suits[c[2]]}` : `${c[0]}${this.suits[c[1]]}`);
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
|
async sendMsg(msg) {
|
||||||
|
return (await bot.clients.filter(async c => (await c).name == this.config.getFull().clients[0].network)[0])
|
||||||
|
.client.sendmsg("normal", this.config.get('channel'), msg);
|
||||||
|
};
|
||||||
|
};
|
234
src/index.mjs
234
src/index.mjs
@ -1,30 +1,15 @@
|
|||||||
import cuffeo from 'cuffeo';
|
import cuffeo from 'cuffeo';
|
||||||
import handranker from './inc/handranker.mjs';
|
import handranker from './inc/handranker.mjs';
|
||||||
import cfg from '../config.json' assert { type: 'json' };
|
import helper from './inc/helper.mjs';
|
||||||
|
|
||||||
const bot = await new cuffeo(cfg.clients);
|
const cfg = helper.config;
|
||||||
|
export const bot = await new cuffeo(cfg.getFull().clients);
|
||||||
|
|
||||||
const suits = { "♠": "S", "♣": "C", "♦": "D", "♥": "H" };
|
export const env = {
|
||||||
|
gamestate: 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin'),
|
||||||
const stripColors = msg => msg.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, '');
|
|
||||||
const rand = (max = 1) => ~~(Math.random() * (max - 1) + 1);
|
|
||||||
|
|
||||||
const parseCards = msg => {
|
|
||||||
const output = [];
|
|
||||||
for(const c of stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) {
|
|
||||||
if(c.length === 3)
|
|
||||||
output.push(`T${suits[c[2]]}`);
|
|
||||||
else
|
|
||||||
output.push(`${c[0]}${suits[c[1]]}`);
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
const env = {
|
|
||||||
gamestate: 'preflop', // [preflop,flop,turn,river]
|
|
||||||
hand: false,
|
hand: false,
|
||||||
board: false,
|
board: false,
|
||||||
winchance: false,
|
odds: false,
|
||||||
joined: false,
|
joined: false,
|
||||||
callamount: 0,
|
callamount: 0,
|
||||||
pot: 0,
|
pot: 0,
|
||||||
@ -34,25 +19,81 @@ const env = {
|
|||||||
|
|
||||||
bot.on("notice", msg => {
|
bot.on("notice", msg => {
|
||||||
if(msg.match(/^Your hand/)) {
|
if(msg.match(/^Your hand/)) {
|
||||||
env.hand = parseCards(msg);
|
env.hand = helper.parseCards(msg);
|
||||||
console.log('hand:', env.hand);
|
helper.debug('hand: ' + env.hand.join(', '));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on("message", e => {
|
bot.on("message", async e => {
|
||||||
if(e.channel !== '#poker') {
|
if(e.channel !== cfg.get('channel'))
|
||||||
return;
|
return;
|
||||||
|
if(e.message.startsWith('.cards ')) {
|
||||||
|
let cards = [];
|
||||||
|
try {
|
||||||
|
cards = JSON.parse(e.message.slice(7));
|
||||||
|
} catch(err) {
|
||||||
|
return e.reply('That is not an array.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const hand = cards.slice(0, 2);
|
||||||
|
const board = cards.slice(2);
|
||||||
|
|
||||||
|
let rank;
|
||||||
|
|
||||||
|
try {
|
||||||
|
rank = handranker.rankHands(board, hand);
|
||||||
|
} catch(err) {
|
||||||
|
return e.reply(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.reply(JSON.stringify(rank));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(e.message === `.${e.self.me.nickname} help`) {
|
||||||
|
await e.write(`PRIVMSG ${e.user.nick} I always say hirc schmirc, available commands are:`);
|
||||||
|
const commands = [
|
||||||
|
' .pj -- poker join (activates autojoin)',
|
||||||
|
' .pl -- poker leave (deactivates autojoin)',
|
||||||
|
' .bb -- bank balance',
|
||||||
|
' .bl -- bank loan',
|
||||||
|
' .d -- deal',
|
||||||
|
' .deb -- toggle debug',
|
||||||
|
' .aj -- toggle autojoin',
|
||||||
|
'While playing:',
|
||||||
|
' .s -- stack',
|
||||||
|
' .f -- fold',
|
||||||
|
];
|
||||||
|
|
||||||
|
for(const command of commands) {
|
||||||
|
await e.write(`PRIVMSG ${e.user.nick} ${command}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) {
|
if(e.message.match(new RegExp(`^${e.self.me.nickname}: Your bank account`))) {
|
||||||
env.bank = +e.message.match(/is: (\d+) \(/)[1];
|
env.bank = +e.message.match(/is: (\d+) \(/)[1];
|
||||||
}
|
}
|
||||||
if(e.message === ".pj" || e.message === "pj" && !env.hand && !env.joined) {
|
if(e.message.startsWith(".debug")) {
|
||||||
|
const tmp = e.message.match(/\.debug (\w+)/)?.[1];
|
||||||
|
if(!tmp)
|
||||||
|
return e.reply(`debug mode ${await cfg.set('debug', !cfg.get('debug')) ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
|
||||||
|
if(!['console', 'chat'].includes(tmp))
|
||||||
|
return e.reply(`debug mode ${await cfg.set('debug', false) ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
|
||||||
|
return e.reply(`debug mode [color=green]enabled[/color] (${await cfg.set('debug', tmp)})`);
|
||||||
|
}
|
||||||
|
if(e.message === ".aj" || e.message === ".autojoin") {
|
||||||
|
const tmp = await cfg.set('autojoin', !cfg.get('autojoin'));
|
||||||
|
return e.reply(`autojoin ${tmp ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
|
||||||
|
}
|
||||||
|
if(e.message === ".pj" || (e.message === "pj" && cfg.get('autojoin')) && !env.hand && !env.joined) {
|
||||||
env.joined = true;
|
env.joined = true;
|
||||||
|
await cfg.set('autojoin', true);
|
||||||
//return e.reply("pj");
|
//return e.reply("pj");
|
||||||
return e.reply("bb\npj");
|
return e.reply(["bb", "pj"]);
|
||||||
|
|
||||||
}
|
}
|
||||||
if(e.message === ".pl" && !env.hand) {
|
if(e.message === ".pl" && !env.hand) {
|
||||||
env.joined = false;
|
env.joined = false;
|
||||||
|
await cfg.set('autojoin', false);
|
||||||
return e.reply("pl");
|
return e.reply("pl");
|
||||||
}
|
}
|
||||||
if(e.message === ".bb" && !env.hand)
|
if(e.message === ".bb" && !env.hand)
|
||||||
@ -65,117 +106,180 @@ bot.on("message", e => {
|
|||||||
return e.reply("f");
|
return e.reply("f");
|
||||||
if(e.message === ".d" && !env.hand)
|
if(e.message === ".d" && !env.hand)
|
||||||
return e.reply("d");
|
return e.reply("d");
|
||||||
|
if(e.message === ".env") {
|
||||||
|
return helper.debug(env, 5);
|
||||||
|
}
|
||||||
|
|
||||||
if(e.user.nick !== 'hirc' || !env.hand)
|
if(e.user.nick !== cfg.get('pokerbot') || !env.hand)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// tracker
|
// tracker
|
||||||
if(e.message.includes('raises the pot')) {
|
if(e.message.includes('raises the pot')) {
|
||||||
env.callamount = +e.message.match(/raises the pot by (\d+)/)[1];
|
env.callamount = +e.message.match(/raises the pot by (\d+)/)[1];
|
||||||
env.pot += env.callamount;
|
env.pot += env.callamount;
|
||||||
if(e.message.includes(e.self.me.nickname))
|
if(e.message.includes(e.self.me.nickname)) {
|
||||||
env.bank -= env.callamount;
|
env.bank -= env.callamount;
|
||||||
|
helper.debug(`bank: ${env.bank}`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.message.includes('calls')) {
|
if(e.message.includes('calls')) {
|
||||||
env.callamount = +e.message.match(/calls (\d+)\./)[1];
|
env.callamount = +e.message.match(/calls (\d+)\./)[1];
|
||||||
env.pot += env.callamount;
|
env.pot += env.callamount;
|
||||||
if(e.message.includes(e.self.me.nickname))
|
if(e.message.includes(e.self.me.nickname)) {
|
||||||
env.bank -= env.callamount;
|
env.bank -= env.callamount;
|
||||||
|
helper.debug(`bank: ${env.bank}`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.message.endsWith('blind).')) { // blinds
|
if(e.message.endsWith('blind).')) { // blinds
|
||||||
env.callamount = +e.message.match(/pays (\d+) \(/)[1];
|
env.callamount = +e.message.match(/pays (\d+) \(/)[1];
|
||||||
env.pot += env.callamount;
|
env.pot += env.callamount;
|
||||||
|
|
||||||
|
const oldstate = env.gamestate;
|
||||||
env.gamestate = 'preflop';
|
env.gamestate = 'preflop';
|
||||||
if(e.message.includes(e.self.me.nickname))
|
if(oldstate !== env.gamestate)
|
||||||
|
helper.debug(`${oldstate} -> ${env.gamestate}`);
|
||||||
|
|
||||||
|
if(e.message.includes(e.self.me.nickname)) {
|
||||||
env.bank -= env.callamount;
|
env.bank -= env.callamount;
|
||||||
|
helper.debug(`bank: ${env.bank}`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bot is broke :(
|
||||||
|
if(e.message.includes('You don\'t have enough money')) {
|
||||||
|
e.reply(['fugggggg', 'f']);
|
||||||
|
if(env.bank < 100) {
|
||||||
|
e.reply('bank loan');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bot's turn
|
// bot's turn
|
||||||
if(e.message.match(new RegExp(`Current player: ${e.self.me.nickname}( |$)`))) {
|
if(e.message.match(new RegExp(`Current player: ${e.self.me.nickname}( |$)`))) {
|
||||||
let action = 'c'; // default
|
let action = 'c'; // default
|
||||||
if(env.gamestate === 'preflop' || !env.winchance) { // preflop
|
let debug = false;
|
||||||
|
if(env.gamestate === 'preflop' || !env.odds) { // preflop
|
||||||
env.lastaction = action;
|
env.lastaction = action;
|
||||||
|
helper.debug('preflop, (checkcall) :(', 3);
|
||||||
return e.reply(action); // checkcall
|
return e.reply(action); // checkcall
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e.message.endsWith('to call)')) { // callphase
|
if(e.message.includes('to call')) { // callphase
|
||||||
env.callamount = +e.message.match(/\((\d+) to call\)/)[1];
|
env.callamount = +e.message.match(/\((\d+) to call\)/)[1];
|
||||||
|
|
||||||
|
if(env.callamount > env.bank) // not enough money lol
|
||||||
|
return e.reply(['huan!', 'f']);
|
||||||
|
|
||||||
if(env.winchance < 4300) {
|
if(env.odds <= 40) {
|
||||||
if(rand(5) === 1 && env.callamount < 80) { // bad hand, call anyway
|
if(helper.rand(20) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // bad hand, call anyway
|
||||||
action = 'c';
|
action = 'call';
|
||||||
|
debug = `bad hand, call anyway (${env.odds}, callphase, 5%)`;
|
||||||
}
|
}
|
||||||
else { // bad hand, fold
|
else { // bad hand, fold
|
||||||
action = 'f';
|
action = 'fold';
|
||||||
|
debug = `bad hand (${env.odds}, callphase, 95%)`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(env.winchance > 7000) { // decent hand, raise
|
else if(env.odds > 40 && env.odds <= 50) { // decent hand, raise
|
||||||
if(rand(5) === 1) { // 20%
|
if(helper.rand(10) === 1) { // 10%
|
||||||
action = 'r ' + (env.callamount + rand(5) * 10);
|
const toRaise = env.callamount + helper.rand(5) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `decent hand (${env.odds}, callphase, 10%)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(env.winchance > 15000) { // good hand lol
|
else if(env.odds > 50 && env.odds <= 70) { // good hand lol
|
||||||
if(rand(2) === 1) { // 50%
|
if(helper.rand(3) === 1) { // 33%
|
||||||
action = 'r ' + (env.callamount + rand(6) * 10);
|
const toRaise = env.callamount + helper.rand(6) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `good hand lol (${env.odds}, callphase, 33%)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(env.winchance > 20000) { // fuck them all
|
else if(env.odds > 70) { // fuck them all
|
||||||
action = 'r ' + (env.callamount + rand(7) * 10);
|
const toRaise = env.callamount + helper.rand(7) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `fuck them all (${env.odds}, callphase)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // checkphase
|
else { // checkphase
|
||||||
if(env.winchance > 7000) { // decend hand, raise
|
if(env.odds > 55 && env.odds <= 70) { // decend hand, raise
|
||||||
if(rand(5) === 1) { // 20%
|
if(helper.rand(5) === 1) { // 20%
|
||||||
action = 'r ' + (env.callamount + rand(5) * 10);
|
const toRaise = env.callamount + helper.rand(5) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `decent hand (${env.odds}, checkphase, 20%)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(env.winchance > 15000) { // good hand lol
|
else if(env.odds > 70 && env.odds <= 85) { // good hand lol
|
||||||
if(rand(2) === 1) { // 50%
|
if(helper.rand(2) === 1) { // 50%
|
||||||
action = 'r ' + (env.callamount + rand(6) * 10);
|
const toRaise = env.callamount + helper.rand(6) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `good hand lol (${env.odds}, callphase, 50%)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(env.winchance > 20000) { // fuck them all
|
else if(env.odds > 85) { // fuck them all
|
||||||
action = 'r ' + (env.callamount + rand(7) * 10);
|
const toRaise = env.callamount + helper.rand(7) * 10;
|
||||||
|
if(toRaise > env.bank) {
|
||||||
|
action = 'raise ' + toRaise.toString();
|
||||||
|
debug = `fuck them all (${env.odds}, callphase)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(action) {
|
if(action) {
|
||||||
env.lastaction = action;
|
env.lastaction = action;
|
||||||
|
helper.debug(debug ? debug : 'check lol', 3);
|
||||||
return e.reply(action);
|
return e.reply(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// gamestate & board changes
|
// gamestate & board changes
|
||||||
if(e.message.match(/^(Flop|Turn|River)/)) {
|
if(e.message.match(/^(Flop|Turn|River)/)) {
|
||||||
env.board = parseCards(e.message);
|
env.board = helper.parseCards(e.message);
|
||||||
|
const oldstate = env.gamestate;
|
||||||
env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase();
|
env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase();
|
||||||
|
|
||||||
const rank = handranker.evalHand([...env.board, ...env.hand]);
|
helper.debug(`${oldstate} -> ${env.gamestate}`, 2);
|
||||||
env.winchance = rank.value;
|
|
||||||
|
const rank = handranker.rankHands(env.board, env.hand);
|
||||||
|
env.odds = rank.percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of game
|
// end of game
|
||||||
if(e.message.includes('wins the pot') || e.message.includes('Split pot')) {
|
if(e.message.includes('wins the pot') || e.message.includes('Split pot')) {
|
||||||
if(e.message.includes(e.self.me.nickname)) {
|
if(e.message.includes(e.self.me.nickname)) {
|
||||||
const amount = +e.message.match(/size (\d+) /)[1];
|
if(e.message.includes('Split pot')) {
|
||||||
if(e.message.includes('Split pot'))
|
const tmp = e.message.match(/size (\d+) .*: (.*) \(/);
|
||||||
env.bank += ~~(amount / 2);
|
env.bank += ~~(tmp[1] / tmp[2].split(', ').length);
|
||||||
else
|
}
|
||||||
env.bank += amount;
|
else {
|
||||||
|
env.bank += +e.message.match(/pot(: | of size )(\d+)/)[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.debug(`bank: ${env.bank}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
env.gamestate = 'preflop';
|
const oldstate = env.gamestate;
|
||||||
|
env.gamestate = 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin');
|
||||||
|
helper.debug(`${oldstate} -> ${env.gamestate}`, 2);
|
||||||
|
|
||||||
env.hand = false;
|
env.hand = false;
|
||||||
env.board = false;
|
env.board = false;
|
||||||
env.winchance = false;
|
env.odds = false;
|
||||||
env.joined = false;
|
env.joined = false;
|
||||||
env.pot = 0;
|
env.pot = 0;
|
||||||
env.lastaction = false;
|
env.lastaction = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(env);
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user