Permalink
Browse files

- fix namespace issues when compiling with -stc=c++11

- add sample driver program
- add external checkout of google test
  • Loading branch information...
andrewprock committed May 11, 2013
1 parent cc3a659 commit 3e6ca5cc157345e2d47c17306444d96d2b08a83b
View
0 android/PokerStoveDemo.apk 100755 → 100644
No changes.
@@ -1171,7 +1171,7 @@ static inline bool badugiless (int c1, int c2)
PokerEvaluation CardSet::evaluateBadugi () const
{
// get our ranks orgainzed in lowball order by suit
array<int,4> suits =
boost::array<int,4> suits =
{{
LOWBALL_ROTATE_RANKS(C()),
LOWBALL_ROTATE_RANKS(D()),
@@ -1182,7 +1182,7 @@ PokerEvaluation CardSet::evaluateBadugi () const
// We try to save some time by being smart about which suits we loop
// over. Empty suits are ignored, and suits with one rank are used
// as is. At the end we sort to make next_permutation to work properly.
array<int,4> ind;
boost::array<int,4> ind;
int bmust = 0;
size_t k=0;
for (size_t i=0; i<suits.size(); i++)
@@ -96,7 +96,7 @@ namespace pokerstove
return evaluateHand(hand, board);
}
virtual size_t handSize () const = 0; //!< return the maximum size of a players hand
virtual size_t boardSize () const = 0; //!< return the maximum size of the community cards
virtual size_t boardSize () const = 0; //!< return the maximum size of the board
virtual size_t evaluationSize () const = 0; //!< return 1 for high only, 2 for high low
virtual size_t numDraws () const { return 0; } //!< return the maximum size of a players hand
@@ -18,12 +18,11 @@
#include "UniversalHandEvaluator.h"
using namespace std;
using namespace boost;
using namespace pokerstove;
shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & strid)
boost::shared_ptr<PokerHandEvaluator> PokerHandEvaluator::alloc (const string & strid)
{
shared_ptr<PokerHandEvaluator> ret;
boost::shared_ptr<PokerHandEvaluator> ret;
switch (strid[0])
{
case 'h': // hold'em
View
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.6)
project(programs)
set (BOOST_LIBRARYDIR "/usr/local/lib/")
add_subdirectory(../libs libs)
include_directories(../libs)
add_subdirectory (eval)
@@ -0,0 +1,9 @@
project(eval)
add_executable(eval main.cpp)
add_definitions ("-ansi -Wall -std=c++0x")
target_link_libraries(eval
peval
boost_program_options
)
View
@@ -0,0 +1,125 @@
#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>
using namespace std;
namespace po = boost::program_options;
using namespace pokerstove;
class EvalDriver
{
public:
EvalDriver(const string& game,
const vector<string>& hands,
const string& board)
: _peval(PokerHandEvaluator::alloc (game))
, _hands(hands)
, _board(board)
{
}
void evaluate()
{
for (string& hand: _hands)
{
_results[hand] = _peval->evaluate(hand, _board);
}
}
string str() const
{
string ret;
for (const string& hand: _hands)
{
ret += (boost::format("%10s: %s\n") % hand % _results.at(hand).str()).str();
}
return ret;
}
private:
boost::shared_ptr<PokerHandEvaluator> _peval;
vector<string> _hands;
string _board;
map<string,PokerHandEvaluation> _results;
};
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"
" t triple draw lowball (2-7)\n"
" T triple draw lowball (A-5)\n"
" b badugi\n"
" 3 three-card poker\n"
"\n"
" examples:\n"
" ./pstove/eval acas\n"
" ./pstove/eval AcAs Kh4d --board 5c8s9h\n"
" ./pstove/eval AcAs Kh4d --board 5c8s9h\n"
" ./pstove/eval --game l 7c5c4c3c2c\n"
" ./pstove/eval --game k 7c5c4c3c2c\n"
" ./pstove/eval --game kansas-city-lowball 7c5c4c3c2c\n"
"\n"
;
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")
;
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 << extendedHelp << endl;
return 1;
}
// extract the options
EvalDriver driver(vm["game"].as<string>(),
vm["hand"].as< vector<string> >(),
vm["board"].as<string>());
driver.evaluate();
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 3e6ca5c

Please sign in to comment.