Permalink
Browse files

Make ps-eval great again

This change makes ps-eval more useful by implementing the command line
arguments it is supposed to have according to README.md. This provides
basic functionality which goes beyond a fixed As6s vs random holdem
evaluation.
  • Loading branch information...
jdoerrie committed Jan 7, 2017
1 parent ed14781 commit 38b8a532820a8991d699908dd2b95775b9887b36
Showing with 65 additions and 22 deletions.
  1. +65 −22 src/programs/ps-eval/main.cpp
View
87 src/programs/ps-eval/main.cpp 100755 → 100644
@@ -1,36 +1,79 @@
#include <iostream>
#include <vector>
+#include <boost/program_options.hpp>
#include <pokerstove/penum/ShowdownEnumerator.h>
-int main() {
-
using namespace pokerstove;
+namespace po = boost::program_options;
using namespace std;
-CardSet completeDeck;
-completeDeck.fill();
-cout << "The whole deck has " << completeDeck.size() << " cards" << endl;
+int main(int argc, char** argv) {
+ po::options_description desc("ps-eval, a poker hand evaluator\n");
+
+ 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>(), "community cards for he/o/o8")
+ ("hand,h", po::value<vector<string>>(), "a hand for evaluation")
+ ("quiet,q", "produces no output");
+
+ // make hand a positional argument
+ 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);
+
+ // check for help
+ if (vm.count("help") || argc == 1) {
+ cout << desc << endl;
+ return 1;
+ }
+
+ // extract the options
+ string game = vm["game"].as<string>();
+ string board = vm.count("board") ? vm["board"].as<string>() : "";
+ vector<string> hands = vm["hand"].as<vector<string>>();
-CardDistribution anyTwo;
-anyTwo.fill(completeDeck, 2);
-cout << "There are " << anyTwo.size() << " two card combinations" << endl;
+ bool quiet = vm.count("quiet") > 0;
-CardDistribution holeCards;
-holeCards.parse("As6s");
-cout << "There are " << holeCards.size() << " two card combinations" << endl;
+ // allocate evaluator and create card distributions
+ boost::shared_ptr<PokerHandEvaluator> evaluator =
+ PokerHandEvaluator::alloc(game);
+ vector<CardDistribution> handDists;
+ for (const string& hand : hands) {
+ handDists.emplace_back();
+ handDists.back().parse(hand);
+ }
-ShowdownEnumerator showdown;
-vector<EquityResult> result = showdown.calculateEquity(
- vector<CardDistribution>{anyTwo, holeCards},
- CardSet(""),
- PokerHandEvaluator::alloc("h")
-);
+ // fill with random if necessary
+ if (handDists.size() == 1) {
+ handDists.emplace_back();
+ handDists.back().fill(evaluator->handSize());
+ }
-double shareRandom = result.at(0).winShares + result.at(0).tieShares;
-double shareHand = result.at(1).winShares + result.at(1).tieShares;
-double total = shareRandom + shareHand;
+ // calcuate the results and print them
+ ShowdownEnumerator showdown;
+ vector<EquityResult> results =
+ showdown.calculateEquity(handDists, CardSet(board), evaluator);
-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;
+ double total = 0.0;
+ for (const EquityResult& result : results) {
+ total += result.winShares + result.tieShares;
+ }
+ if (!quiet) {
+ for (size_t i = 0; i < results.size(); ++i) {
+ double equity = (results[i].winShares + results[i].tieShares) / total;
+ string handDesc =
+ (i < hands.size()) ? "The hand " + hands[i] : "A random hand";
+ cout << handDesc << " has " << equity * 100. << " % equity ("
+ << results[i].str() << ")" << endl;
+ }
+ }
}

1 comment on commit 38b8a53

@buddha314

This comment has been minimized.

Show comment
Hide comment
@buddha314

buddha314 Apr 12, 2018

Make Commit Messages Great Again!

Make Commit Messages Great Again!

Please sign in to comment.