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": {
"autojoin": false,
"debug": false,
"verbose": 3,
"pokerbot": "hirc",
"channel": "#poker"
},

6
package-lock.json generated
View File

@ -12,9 +12,15 @@
],
"license": "ISC",
"dependencies": {
"@xpressit/winning-poker-hand-rank": "^0.1.6",
"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": {
"version": "1.2.2",
"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 = []) {
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]]}`);

View File

@ -20,19 +20,20 @@ export const env = {
bot.on("notice", msg => {
if(msg.match(/^Your hand/)) {
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 => {
if(e.channel !== cfg.get('channel'))
return;
if(e.message.startsWith('.cards ')) {
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.');
return e.reply('das ist kein Array du Pflaumennase');
}
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`))) {
env.bank = +e.message.match(/is: (\d+) \(/)[1];
}
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 === ".debug") {
const tmp = await cfg.set('debug', !cfg.get('debug'));
return e.reply(`debug mode ${tmp ? '[color=green]enabled[/color]' : '[color=red]disabled[/color]'}`);
}
if(e.message === ".aj" || e.message === ".autojoin") {
const tmp = await cfg.set('autojoin', !cfg.get('autojoin'));
@ -119,7 +116,8 @@ bot.on("message", async e => {
env.pot += env.callamount;
if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount;
helper.debug(`bank: ${env.bank}`);
if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
}
return;
}
@ -128,7 +126,8 @@ bot.on("message", async e => {
env.pot += env.callamount;
if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount;
helper.debug(`bank: ${env.bank}`);
if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
}
return;
}
@ -138,12 +137,13 @@ bot.on("message", async e => {
const oldstate = env.gamestate;
env.gamestate = 'preflop';
if(oldstate !== env.gamestate)
helper.debug(`${oldstate} -> ${env.gamestate}`);
if(cfg.get('debug') && oldstate !== env.gamestate)
e.reply(`${oldstate} -> ${env.gamestate}`);
if(e.message.includes(e.self.me.nickname)) {
env.bank -= env.callamount;
helper.debug(`bank: ${env.bank}`);
if(cfg.get('debug'))
e.reply(`bank: ${env.bank}`);
}
return;
}
@ -160,70 +160,57 @@ bot.on("message", async e => {
// bot's turn
if(e.message.match(new RegExp(`Current player: ${e.self.me.nickname}( |$)`))) {
let action = 'c'; // default
let debug = false;
if(env.gamestate === 'preflop' || !env.odds) { // preflop
env.lastaction = action;
helper.debug('preflop, (checkcall) :(', 3);
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];
if(env.callamount > env.bank) // not enough money lol
return e.reply(['huan!', 'f']);
if(env.odds <= 30) {
console.log('callphase', env);
if(helper.rand(20) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // bad hand, call anyway
action = 'call';
debug = `bad hand, call anyway (${env.odds}, callphase, 5%)`;
if(env.odds < 6500) {
if(helper.rand(5) === 1 && env.callamount < (helper.rand(2, 6) * 10)) { // bad hand, call anyway
action = 'c';
}
else { // bad hand, fold
action = 'fold';
debug = `bad hand (${env.odds}, callphase, 95%)`;
action = 'f';
}
}
else if(env.odds > 30 && env.odds <= 50) { // 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
else if(env.odds > 55) { // decent hand, raise
if(helper.rand(5) === 1) { // 20%
action = 'raise ' + (env.callamount + helper.rand(5) * 10);
debug = `decent hand (${env.odds}, checkphase, 20%)`;
action = 'r ' + (env.callamount + helper.rand(5) * 10);
}
}
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%
action = 'r ' + (env.callamount + helper.rand(6) * 10);
debug = `good hand lol (${env.odds}, callphase, 50%)`;
}
}
else if(env.odds > 85) { // fuck them all
action = 'raise ' + (env.callamount + helper.rand(7) * 10);
debug = `fuck them all (${env.odds}, callphase)`;
action = 'r ' + (env.callamount + helper.rand(7) * 10);
}
}
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) {
env.lastaction = action;
helper.debug(debug ? debug : 'check lol', 3);
return e.reply(action);
}
}
@ -234,7 +221,8 @@ bot.on("message", async e => {
const oldstate = env.gamestate;
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);
env.odds = rank.percentage;
@ -251,12 +239,14 @@ bot.on("message", async e => {
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;
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.board = false;
@ -266,4 +256,7 @@ bot.on("message", async e => {
env.lastaction = false;
return;
}
if(cfg.get('debug'))
console.log(env);
});