Skip to content

Commit

Permalink
add evBot
Browse files Browse the repository at this point in the history
  • Loading branch information
tostercx committed Sep 28, 2016
1 parent 86f90f1 commit 6701e8c
Showing 1 changed file with 80 additions and 8 deletions.
88 changes: 80 additions & 8 deletions players/challengerBot.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,89 @@
module.exports = function () {

var info = {
name: "Nameless Challenger",
email: "",
btcWallet: ""
name: "evBot",
email: "[email protected]",
btcWallet: "nil"
};


// I hope these don't count as "external modules"?
// they seem to come with the game engine
var Hand = require('hoyle').Hand;
var deck = new (require('hoyle').Deck)().cards;

// increadably bad card dealer
function randCard(used) {
while(true) {
var card = deck[Math.floor(Math.random()*deck.length)].toString();
if(used.indexOf(card) == -1)
{
used.push(card);
return card;
}
}
}

// slowest game simulator on the planet
// needs serious optimizations
function simulate(hand, community, opponents, iterations) {
var wins = 0;
var games = 0;
var used = hand.concat(community);

for(games=0; games<iterations; games++) {
var _community = community.slice();
var _used = used.slice();

while(_community.length < 5) _community.push(randCard(_used));

var hero = Hand.make([].concat(hand).concat(_community));
var players = [hero];

for(var op=0; op<opponents; op++)
players.push(Hand.make([].concat(_community).concat([randCard(_used), randCard(_used)])));

var winners = Hand.pickWinners(players);
if(winners.length == 1 && winners[0] == hero)
wins++;
}

return wins / games;
}

function update(game) {
if (game.state !== "complete") {
return game.betting.call

// settings
// I can't believe it still works with these
// simulation results are just above random
var aggression = 1;
var opponent_cap = 1;
var sim_iterations = 20;

// if you have a proper simulator... these will do much better
//var aggression = 1.25;
//var opponent_cap = 2;
//var sim_iterations = 1000;

// calculate pot size
var pot = 0;
game.players.map(p => pot += parseFloat(p.wagered));

// compensate for horrible pre-flop and flop
// reducing opponent count increases simulation winning odds
var num_opponents = game.players.filter(p => p.state == 'active').length;
var sim_opponents = Math.min(num_opponents, opponent_cap);

// calculate winning odds
var odds = simulate(game.self.cards, game.community, sim_opponents, sim_iterations);

// set bet
// I have no idea if this is actually a good strategy or
// if it's just good against these basic bots
return pot * odds * aggression;
}
}

return { update: update, info: info }

}
return { update: update, info: info };
};

0 comments on commit 6701e8c

Please sign in to comment.