1

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 :

question 1

question 2

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;
}

1 Answer 1

2

It is not surprising that there are difficulties. Authors haven't provided the install scripts.

So, we have to specify header and library locations manually:

g++ -o programma ggg.cpp -I/home/girts/pokerstove/src/lib -l{peval,penum} -L/home/girts/pokerstove/src/build/lib/pokerstove/{peval,penum}

And there is an error in the code of ggg.cpp, I think: CardSet can't be created with two cards like that.

Example that compiles:

#include <iostream>
#include <pokerstove/peval/CardSet.h>
#include <pokerstove/peval/Card.h>

using pokerstove::CardSet;
using pokerstove::Card;
using pokerstove::Rank;
using pokerstove::Suit;

int main(void)
{
    CardSet big_slick(Card(Rank('A'),Suit('s')));
    std::cout << big_slick.str() << std::endl;

    CardSet dead_mans_hand("AcAs8d8hJs");
    std::cout << dead_mans_hand.str() << std::endl;
}
5
  • Thanks for your answer man :) This is really supposed the line how I should compile this project? :D I have never seen this long command :) Going to check it out
    – etrusks
    Apr 27, 2015 at 18:48
  • Actually, you are supposed to write your own CMakeLists.txt and do it with cmake. But if you are lazy, one dirty thing you can do is to place your program alongside with the others in pokerstove/src/programs and edit pokerstove/src/programs/CMakeLists.txt and pokerstove/src/programs/programma/CMakeLists.txt. That way it will compile with the library when you run make.
    – Velkan
    Apr 27, 2015 at 18:57
  • Tried to compile 1 more example and got full terminal of errors. Is there any other maybe slower way but that could work that could make these libraries actualy work? All this cmake is big mystery to me
    – etrusks
    Apr 27, 2015 at 19:06
  • Thanks man, I will check it out. Did you install this on your computer as well?
    – etrusks
    Apr 27, 2015 at 19:24
  • You are right it did compile but if I'm trying to compile some bigger samples I keep getting some huge errors. I will edit my post and show you example but no worries if you dont want to look at it :D I just would love to know how to aactually calculate 1 equity (1 poker hand against another)
    – etrusks
    Apr 27, 2015 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .