Compare commits

..

No commits in common. "4cbdf71f0ac505f972b513982f618d8a2865398e" and "a3be1cb8f12984b47513c06541d0b97b2b8199cb" have entirely different histories.

4 changed files with 54 additions and 68 deletions

View File

@ -2,7 +2,6 @@
"bot": { "bot": {
"autojoin": false, "autojoin": false,
"debug": false, "debug": false,
"verbose": 3,
"pokerbot": "hirc", "pokerbot": "hirc",
"channel": "#poker" "channel": "#poker"
}, },

6
package-lock.json generated
View File

@ -12,9 +12,15 @@
], ],
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@xpressit/winning-poker-hand-rank": "^0.1.6",
"cuffeo": "^1.2.2" "cuffeo": "^1.2.2"
} }
}, },
"node_modules/@xpressit/winning-poker-hand-rank": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@xpressit/winning-poker-hand-rank/-/winning-poker-hand-rank-0.1.6.tgz",
"integrity": "sha512-l7b8GAKOT6k79qKF/SesCgQLvCjHZkhihf5QhgcL9w3hiya2JeCVyg07TVayoyO8PzDq56MH+yKk5rcbDMYScw=="
},
"node_modules/cuffeo": { "node_modules/cuffeo": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.2.2.tgz", "resolved": "https://registry.npmjs.org/cuffeo/-/cuffeo-1.2.2.tgz",

View File

@ -35,18 +35,6 @@ export default new class {
} }
}; };
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 = []) { parseCards(msg, output = []) {
for(const c of this.stripColors(msg).match(/(\w+)([♠♣️♦♥️️])/g)) 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]]}`); output.push(c.length === 3 ? `T${this.suits[c[2]]}` : `${c[0]}${this.suits[c[1]]}`);

View File

@ -20,19 +20,20 @@ export const env = {
bot.on("notice", msg => { bot.on("notice", msg => {
if(msg.match(/^Your hand/)) { if(msg.match(/^Your hand/)) {
env.hand = helper.parseCards(msg); env.hand = helper.parseCards(msg);
helper.debug('hand: ' + env.hand.join(', ')); if(cfg.get('debug'))
console.log('hand:', env.hand);
} }
}); });
bot.on("message", async e => { bot.on("message", async e => {
if(e.channel !== cfg.get('channel')) if(e.channel !== cfg.get('channel'))
return; return;
if(e.message.startsWith('.cards ')) { if(e.message.startsWith(".cards ")) {
let cards = []; let cards = [];
try { try {
cards = JSON.parse(e.message.slice(7)); cards = JSON.parse(e.message.slice(7));
} catch(err) { } catch(err) {
return e.reply('That is not an array.'); return e.reply('das ist kein Array du Pflaumennase');
} }
const hand = cards.slice(0, 2); const hand = cards.slice(0, 2);
@ -72,13 +73,9 @@ bot.on("message", async e => {
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.startsWith(".debug")) { if(e.message === ".debug") {
const tmp = e.message.match(/\.debug (\w+)/)?.[1]; const tmp = await cfg.set('debug', !cfg.get('debug'));
if(!tmp) return e.reply(`debug mode ${tmp ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
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") { if(e.message === ".aj" || e.message === ".autojoin") {
const tmp = await cfg.set('autojoin', !cfg.get('autojoin')); const tmp = await cfg.set('autojoin', !cfg.get('autojoin'));
@ -119,7 +116,8 @@ bot.on("message", async e => {
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}`); if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -128,7 +126,8 @@ bot.on("message", async e => {
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}`); if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -138,12 +137,13 @@ bot.on("message", async e => {
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = 'preflop'; env.gamestate = 'preflop';
if(oldstate !== env.gamestate) if(cfg.get('debug') && oldstate !== env.gamestate)
helper.debug(`${oldstate} -> ${env.gamestate}`); e.reply(`${oldstate} -> ${env.gamestate}`);
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}`); if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
} }
return; return;
} }
@ -160,70 +160,57 @@ bot.on("message", async e => {
// 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
let debug = false;
if(env.gamestate === 'preflop' || !env.odds) { // preflop 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.includes('to call')) { // callphase if(e.message.endsWith('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 if(env.callamount > env.bank) // not enough money lol
return e.reply(['huan!', 'f']); return e.reply(['huan!', 'f']);
if(env.odds <= 30) { if(env.odds < 6500) {
console.log('callphase', env); if(helper.rand(5) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // 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 = 'fold'; action = 'f';
debug = `bad hand (${env.odds}, callphase, 95%)`;
} }
} }
else if(env.odds > 30 && env.odds <= 50) { // decent hand, raise else if(env.odds > 55) { // decent hand, raise
if(helper.rand(10) === 1) { // 10%
action = 'raise ' + (env.callamount + helper.rand(5) * 10);
debug = `decent hand (${env.odds}, callphase, 20%)`;
}
}
else if(env.odds > 50 && env.odds <= 70) { // good hand lol
if(helper.rand(2) === 1) { // 50%
action = 'raise ' + (env.callamount + helper.rand(6) * 10);
debug = `good hand lol (${env.odds}, callphase, 70%)`;
}
}
else if(env.odds > 70) { // fuck them all
action = 'raise ' + (env.callamount + helper.rand(7) * 10);
debug = `fuck them all (${env.odds}, callphase)`;
}
}
else { // checkphase
console.log('checkphase', env);
if(env.odds > 55 && env.odds <= 70) { // decend hand, raise
if(helper.rand(5) === 1) { // 20% if(helper.rand(5) === 1) { // 20%
action = 'raise ' + (env.callamount + helper.rand(5) * 10); action = 'r ' + (env.callamount + helper.rand(5) * 10);
debug = `decent hand (${env.odds}, checkphase, 20%)`;
} }
} }
else if(env.odds > 70 && env.odds <= 85) { // good hand lol else if(env.odds > 70) { // good hand lol
if(helper.rand(2) === 1) { // 50% if(helper.rand(2) === 1) { // 50%
action = 'r ' + (env.callamount + helper.rand(6) * 10); action = 'r ' + (env.callamount + helper.rand(6) * 10);
debug = `good hand lol (${env.odds}, callphase, 50%)`;
} }
} }
else if(env.odds > 85) { // fuck them all else if(env.odds > 85) { // fuck them all
action = 'raise ' + (env.callamount + helper.rand(7) * 10); action = 'r ' + (env.callamount + helper.rand(7) * 10);
debug = `fuck them all (${env.odds}, callphase)`; }
}
else { // checkphase
if(env.odds > 55) { // decend hand, raise
if(helper.rand(5) === 1) { // 20%
action = 'r ' + (env.callamount + helper.rand(5) * 10);
}
}
else if(env.odds > 70) { // good hand lol
if(helper.rand(2) === 1) { // 50%
action = 'r ' + (env.callamount + helper.rand(6) * 10);
}
}
else if(env.odds > 85) { // fuck them all
action = 'r ' + (env.callamount + helper.rand(7) * 10);
} }
} }
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);
} }
} }
@ -234,7 +221,8 @@ bot.on("message", async e => {
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase(); env.gamestate = e.message.match(/(\w+): /)[1].toLowerCase();
helper.debug(`${oldstate} -> ${env.gamestate}`, 2); if(cfg.get('debug'))
e.reply(`${oldstate} -> ${env.gamestate}`);
const rank = handranker.rankHands(env.board, env.hand); const rank = handranker.rankHands(env.board, env.hand);
env.odds = rank.percentage; env.odds = rank.percentage;
@ -251,12 +239,14 @@ bot.on("message", async e => {
env.bank += +e.message.match(/pot(: | of size )(\d+)/)[2]; env.bank += +e.message.match(/pot(: | of size )(\d+)/)[2];
} }
helper.debug(`bank: ${env.bank}`); if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
} }
const oldstate = env.gamestate; const oldstate = env.gamestate;
env.gamestate = 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin'); env.gamestate = 'not started, ' + (cfg.get('autojoin') ? 'autojoin' : 'no autojoin');
helper.debug(`${oldstate} -> ${env.gamestate}`, 2); if(cfg.get('debug'))
e.reply(`${oldstate} -> ${env.gamestate}`);
env.hand = false; env.hand = false;
env.board = false; env.board = false;
@ -266,4 +256,7 @@ bot.on("message", async e => {
env.lastaction = false; env.lastaction = false;
return; return;
} }
if(cfg.get('debug'))
console.log(env);
}); });