Skip to content

Commit

Permalink
comit some changes to ps-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewprock committed Jan 30, 2016
1 parent 0f057ff commit 97e8a3d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 117 deletions.
1 change: 1 addition & 0 deletions src/programs/ps-eval/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ add_definitions ("-std=c++0x")

target_link_libraries(ps-eval
peval
penum
${Boost_LIBRARIES}
)
141 changes: 24 additions & 117 deletions src/programs/ps-eval/main.cpp
Original file line number Diff line number Diff line change
@@ -1,129 +1,36 @@
#include <iostream>
#include <vector>
#include <string>
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/format.hpp>
#include <pokerstove/peval/PokerHandEvaluator.h>
#include <pokerstove/penum/ShowdownEnumerator.h>

using namespace std;
namespace po = boost::program_options;
using namespace pokerstove;
int main() {

class EvalDriver
{
public:
EvalDriver(const string& game,
const vector<string>& hands,
const string& board)
: _peval(PokerHandEvaluator::alloc (game))
, _hands(hands)
, _board(board)
{
}
using namespace pokerstove;
using namespace std;

void evaluate()
{
for (auto it=_hands.begin(); it!=_hands.end(); it++)
{
string& hand = *it;
_results[hand] = _peval->evaluate(hand, _board);
}
}
CardSet completeDeck;
completeDeck.fill();
cout << "The whole deck has " << completeDeck.size() << " cards" << endl;

string str() const
{
string ret;
for (auto it=_hands.begin(); it!=_hands.end(); it++)
{
const string& hand = *it;
ret += boost::str(boost::format("%10s: %s\n")
% hand
% _results.at(hand).str());
}
return ret;
}
CardDistribution anyTwo;
anyTwo.fill(completeDeck, 2);
cout << "There are " << anyTwo.size() << " two card combinations" << endl;

private:
boost::shared_ptr<PokerHandEvaluator> _peval;
vector<string> _hands;
string _board;
map<string,PokerHandEvaluation> _results;
};
CardDistribution holeCards;
holeCards.parse("As6s");
cout << "There are " << holeCards.size() << " two card combinations" << endl;

int main (int argc, char ** argv)
{
string extendedHelp = "\n"
" For the --game option, one of the follwing games may be specified.\n"
" h hold'em\n"
" o omaha/8\n"
" O omaha high\n"
" r razz\n"
" s stud\n"
" e stud/8\n"
" q stud high/low no qualifier\n"
" d draw high\n"
" l lowball (A-5)\n"
" k Kansas City lowball (2-7)\n"
" b badugi\n"
" 3 three-card poker\n"
"\n"
" examples:\n"
" ps-eval acas\n"
" ps-eval AcAs Kh4d --board 5c8s9h\n"
" ps-eval AcAs Kh4d --board 5c8s9h\n"
" ps-eval --game l 7c5c4c3c2c\n"
" ps-eval --game k 7c5c4c3c2c\n"
" ps-eval --game kansas-city-lowball 7c5c4c3c2c\n"
"\n"
;
ShowdownEnumerator showdown;
vector<EquityResult> result = showdown.calculateEquity(
vector<CardDistribution>{anyTwo, holeCards},
CardSet(""),
PokerHandEvaluator::alloc("h")
);

try
{
// set up the program options, handle the help case, and extract the values
po::options_description desc("Allowed options");
desc.add_options()
("help,?", "produce help message")
("game,g", po::value<string>()->default_value("h"), "game to use for evaluation")
("board,b", po::value<string>()->default_value(""), "community cards for he/o/o8")
("hand,h", po::value< vector<string> >(), "a hand for evaluation")
("quiet,q", "produce no output")
;

po::positional_options_description p;
p.add("hand", -1);
po::variables_map vm;
po::store (po::command_line_parser(argc, argv)
.style(po::command_line_style::unix_style)
.options(desc)
.positional(p)
.run(), vm);
po::notify (vm);
double shareRandom = result.at(0).winShares + result.at(0).tieShares;
double shareHand = result.at(1).winShares + result.at(1).tieShares;
double total = shareRandom + shareHand;

// check for help
if (vm.count("help") || argc == 1)
{
cout << desc << extendedHelp << endl;
return 1;
}
cout << "A random hand has " << shareRandom / total * 100 << " % equity (" << result.at(0).str() << ")" << endl;
cout << "The hand As6s has " << shareHand / total * 100 << " % equity (" << result.at(1).str() << ")" << endl;

// extract the options
EvalDriver driver(vm["game"].as<string>(),
vm["hand"].as< vector<string> >(),
vm["board"].as<string>());
driver.evaluate();
if (vm.count("quiet") == 0)
cout << driver.str();
}
catch(std::exception& e)
{
cerr << "-- caught exception--\n" << e.what() << "\n";
return 1;
}
catch(...)
{
cerr << "Exception of unknown type!\n";
return 1;
}
return 0;
}

0 comments on commit 97e8a3d

Please sign in to comment.