I have been trying to include this pokerstove library so I could actually include these header files in my simple program so I could calculate some poker hand equities. So far its not going great probably because I'm facing this cmake first time in my life
Ok, so this is what instructions says
In order to build the libraries you'll need the following installed on your platform of choice:
boost, version 1.46 or higher
cmake, version 2.4 or higher
subversion, version 1.7 or higher
I got that and also got git and GNU C++ compiler
Next I'm suposed to do this :
git clone https://github.com/andrewprock/pokerstove.git
mkdir pokerstove/src/build
cd pokerstove/src/build
cmake ..
make
and than I would be able to execute this command line
girts@girts-ThinkPad-E520:~/pokerstove/src/build$ bin/ps-eval
And yes, tnx to this forum "I"(of course that wasnt I really) actually made it work. Here are my previous questions :
Still I was able to compile .cpp file with this code
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/math/special_functions/binomial.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <pokerstove/util/combinations.h>
#include <pokerstove/peval/Card.h>
int main(){
std::cout << "Hello World!" << std::endl;
}
But this on the other hand didn't work
#include <iostream>
#include <pokerstove/peval/CardSet.h>
using pokerstove::CardSet;
using pokerstove::Card;
using pokerstove::Rank;
using pokerstove::Suit;
int main(void)
{
CardSet big_slick(Card(Rank('A'),Suit('s')),
Card(Rank('K'),Suit('s')));
std::cout << big_slick.str() << std::endl;
CardSet dead_mans_hand("AcAs8d8hJs");
std::cout << dead_mans_hand.str() << std::endl;
}
Also why do we actually have to even execute the
cmake ..
make
commands if
git clone https://github.com/andrewprock/pokerstove.git
already creates a lot of folders including those where all the .cpp and .h files are inside. With cmake and make I only create some .run files that are for some kind of tests and if I run them tests shows that evevrything is working excelent but in reality I couldnt say that everything is working at all.
Also there are more than just this one CMakeLists.txt
file and instruction doesnt tell what to do with them
Overall I just dont get why cant there be just normal .cpp and .h files that you can download and everything would work for everybody (on any OS). Why instead there is this great cross platform solution called cmake. What good its actually doing here in my problem? Im i missing some huge picture here?
Thanks for reading through all of this!
EDIT : In some ocasions i have to include
#include <gtest/gtest.h>
and of course compiler tells me that there is no such directory and thats true. But isnt this cmake is supposed to take care of all of this project? This is why I dont get how is it thats its such a great tool.
The big example that wont run
#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 (auto it=_hands.begin(); it!=_hands.end(); it++)
{
string& hand = *it;
_results[hand] = _peval->evaluate(hand, _board);
}
}
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;
}
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"
" 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"
;
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);
// 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();
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;
}