Image Image Image




Post new topic Reply to topic  [ 239 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next
Author Message
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Tue Nov 23, 2010 2:18 am 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
First off, it looks like you're missing the header files from poker source. You need to add poker_defs.h, enumerate.h, inlines/eval.h and inlines/eval_type.h to your search path (or just copy them into the PSim directory).

Then in your second listing you're using gcc. gcc only does C code to my knowledge. PSim is C++ code, so you need to use g++. If you're making a static library, you don't add in libpoker.a (which I assume is the pokersource library). Rather libpoker.a is added to your final application along with psim.a (the linking order will be important).

I'm not sure what the "-static" option does. You should probably compile with the "-c" option, with outputs to .o files. Then you use "ar" to put the object files (.o) into a library (.a).

Why do you want this to run on Linux anyway? Don't all the poker clients run on Windows?

Anyway, give it another shot. If you're still not getting it I can compile it for you. Who knows, maybe someone else is waiting for a Linux library too.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Tue Nov 23, 2010 2:26 am 
Offline
Senior member
User avatar

Posts: 251
Favourite Bot: The Crushinator
gcc will compile C++ files if they have .cpp, .cxx or similar filename extension. You only need to use g++ if the file doesn't look like a c++ file (for instance, the source is from a pipe, or has only .c extension). You can also force the c++ compilation with option -std=gnu++98.

g++ will also include the c++ libraries in the link step. This has no effect if you are using a makefile and invoke the linker explicitly.


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Thu Dec 02, 2010 6:09 am 
Offline
Junior member
User avatar

Posts: 28
Favourite Bot: Full Ring NL
I have been using AutoIt with Psim. I now seem to have a problem. My code looks like this:

Code:
#Include <Array.au3>;

Global $Result, $HeroHand, $TopRange, $Board, $BottomRange
$HeroHand = "7h7d"
$Board = "2h3d4d"
$TopRange = 1
$BottomRange = 0.3
Equity_Range($HeroHand, $TopRange, $BottomRange, $Board)

;This function calculates our calculates our equity against a single villian % range
Func Equity_Range($HeroHand, $TopRange, $BottomRange, $Board)
   
   Local $dll, $simResultsStruct, $simResults, $hand, $Equity
   
   $dll = DllOpen ("psim.dll")
   $simResultsStruct = "float win; float tie; float lose; float winSd; float tieSd; float loseSd; float d94; float d90; int evaluations"
   $simResults = DllStructCreate($simResultsStruct)
   
   $hand = $HeroHand &" "&$Board
   
   $Result = DllCall($dll, "none", "SimulateHand", "str", $hand, "ptr", DllStructGetPtr($simResults), "float", $BottomRange, "float", $TopRange, "uint", 0)
   
   $Equity = (DllStructGetData($simResults, "winSd") + DllStructGetData($simResults, "tieSd")/2)*100
   Return $Equity
   DllClose($dll)
EndFunc

This works but if I try to calculate my preflop equity against the range, by making the $Board variable = “”, then the code hangs.

I looked at the source code and I noticed that the first parameter of the function I am calling, “SimulateHand”, is “const Hand& shand”. Am I correct that none of the Psim functions can be called preflop because you always have to define the common cards?


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Thu Dec 02, 2010 8:48 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
want2learn wrote:
This works but if I try to calculate my preflop equity against the range, by making the $Board variable = “”, then the code hangs.

I looked at the source code and I noticed that the first parameter of the function I am calling, “SimulateHand”, is “const Hand& shand”. Am I correct that none of the Psim functions can be called preflop because you always have to define the common cards?


You're looking in the wrong file for definitions. Check out psim.hpp:

Code:
EXPORT void SimulateHand(const char* hand, SimResults* results, float lowRange = 0, float highRange = 1, unsigned int boards = 0);


The functions in simulate.hpp are internal; they aren't exported.


Now, you say the code hangs, but what is your definition of hangs? How long are you waiting? A full simulation should probably take a minute or more.

If that's too slow, change the last "0" in the DllCall to the number of simulations you want to do (e.g. 1000). In that case the code will complete quickly, but you'll lose accuracy. Run it a few times in a row to get a feel for the accuracy.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Fri Dec 03, 2010 8:45 am 
Offline
Junior member
User avatar

Posts: 28
Favourite Bot: Full Ring NL
ty timmy now it works fine


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Dec 05, 2010 1:53 pm 
Offline
New member
User avatar

Posts: 3
Favourite Bot: none
i'm kinda new to this c++ world...
just learned how to use dlls

tried to make the psim.dll part of my program explicitly.. but without success
so i wrote this piece of code for loading it...

I want to use the option of eval a hand strength by int[7]...
but it returns always... 118272000

had success with passing a string... but int are preferable

Code:
///Ranks a hand, a higher ranked hand beats any lower ranked hand.
EXPORT unsigned int RankHand(const char* hand);
unsigned int RankHand(const int* hand);


does the fact that only func(char*) is EXPORT should matter?

Code:
#include <windows.h>

#define MAXMODULE 50

typedef int (WINAPI*cfunc2)(const int*);

cfunc2 RankHand2;


int DllRankHand(const int* hand) {
   
     int rank;
     HINSTANCE hLib;
     char mod[MAXMODULE];

     hLib=LoadLibrary("psim.dll");

      if(hLib==NULL) {

          // cout << "Unable to load library!" << endl;
          // getch();
           return -1;
      }

      GetModuleFileName((HMODULE)hLib, (LPTSTR)mod, MAXMODULE);
     // cout << "Library loaded: " << mod << endl;

      RankHand2=(cfunc2)GetProcAddress((HMODULE)hLib, "RankHand");

      if(RankHand2==NULL) {

         //  cout << "Unable to load function(s)." << endl;
           FreeLibrary((HMODULE)hLib);
           return -1;
      }
//---------------------------test------------------------
     int hand2[7] = {12, 11, 20, 45, 8, 0, 13};
      rank=RankHand2(hand2);
//------------------------end test-------------------
      //rank=RankHand2(hand);
      FreeLibrary((HMODULE)hLib);

     return rank;

}


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Dec 05, 2010 1:56 pm 
Offline
New member
User avatar

Posts: 3
Favourite Bot: none
forgot to mention i use VS c++ 2010


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Dec 05, 2010 7:31 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
Unfortunately, only the functions marked EXPORT in psim.hpp are available through the DLL interface. If you really need the int interface, you'll need to recompile psim. For someone kinda new to C++, I wouldn't recommend it.

Why can't you just use the string interface?


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Mon Dec 06, 2010 6:06 pm 
Offline
New member
User avatar

Posts: 3
Favourite Bot: none
i'm trying to make my own simulation with special stuff that i do in my game... i only wanna use the rankhand func cause its so nitly written...

after i finish building the engine of my simulation i found it to be very slow... so now i'm learning on how to make it faster... and although it say in the doc that those two type of func (handrank(*int)...(*char)) take almost the same amount of time, it take me a lot of time to actually build the string.

if i mentioned it already can u pls give me some reference to post or some useful material on how to make those kind of simulation very fast...


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Thu Dec 09, 2010 7:23 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
papa05 wrote:
i'm trying to make my own simulation with special stuff that i do in my game... i only wanna use the rankhand func cause its so nitly written...
If you're only in it for the RankHand function, you would be much better off using a different library. e.g. poker-eval.

PSim's whole purpose is to allow an easy interface for the really common calculations. If you need something special, there's no advantage to using it over a lower level alternative.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Apr 10, 2011 12:14 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: Botage
I wonder if anyone can explain something to me about GetHandState?

I have these holes

"Ah Kd" and board is "3d 3c 3s 7h 9c"

GetHandState works, in that it correctly identifies Trips, but it also reports that my hand uses both holes.
I understand this might be that my whole 5 card hand would include both hole cards, but I was expecting
2 of those to be part of the trips (two 3s)

The same is true for two pair...

"Ah Kd" board "As 4s Td Tc 7h" its reported two pair and using both, where I would expect that the actual two pair, only one of my holes are included, the ace.

How could I achieve what Im expectiing?


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Apr 10, 2011 3:26 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
GetHandState is (correctly) reporting that both of your hole cards are used to make your actual poker hand. It doesn't have functionality to determine whether your hole cards are used as part of a pair, or just the kicker. If a hole card is used, it means you would have a weaker hand by not using it. This is what GetHandState reports.

As a workaround, you could call GetHandState again, but leave out your actual hole cards (or call it with one hole card at a time). From there you can use a little logic to determine what you're after.


Example:

I have "Ah Kd" and board is "3d 3c 3s 7h 9c".

First call to GetHandState says "Ah Kd 3d 3c 3s 7h 9c" is three of a kind.
Second call to GetHandState says "3d 3c 3s 7h 9c" is still three of a kind, therefor the hole cards were only used as kickers.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Sun Apr 10, 2011 4:34 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: Botage
Thank you for the suggestion Timmy.

I have used some logic in my code (after your library has detected one pair) to determine if any of my holes are part of it.
I think I have that covered with two pair, and trips also.

But getting a little headache thinking about logic regarding straight, full house, quads etc...
so your suggestion may come into play there.

Appreciate you time.
Your PSim rocks.

Thanks.


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Mon Apr 11, 2011 1:56 am 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
Uh, with straights, flushes, and full houses, GetHandState will report the hole cards the way you were expecting. Those hand types take all 5 cards, so there is really only one way about it. Or maybe I was misunderstanding you. You do know that a poker hand is only 5 cards, right?

You'll still have to take care of quads though.

Just to reiterate, GetHandState will indicate if your hole cards are used in your best 5 card poker hand.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Mon Apr 11, 2011 9:42 am 
Offline
New member
User avatar

Posts: 8
Favourite Bot: Botage
Indeed, I'm all boxed off now.

In my code logic I already tested if the community cards are tripped or paired, so that covers quads, and like you say, the others are fine.

Thanks again Timmy.


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Fri Apr 22, 2011 9:33 am 
Offline
New member
User avatar

Posts: 2
Favourite Bot: N/A
Hi Timmy. First, thanks for sharing your work, it's really interesting!

I tested it and it works very well. I've noticed that if you run it with only your hole cards it can be very slow due to the number of calculations to run. So, I was looking in the code to check if it's possible to add some sort of flag to allow to interrupt the calculation loop without having to wait the end or just without killing the program. I was thinking of adding a sort of "stop simulation" button in an UI like the one created with Autohotkey.

However, I'm quite confused by the C++ code and macro substitution used. Could you be so kindly to provide me some directions where to look exactly?

Moreover, what is a reasonable parameter to use for the "opponent range" in the case of evaluating only the hole cards?

Thanks in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Fri Apr 22, 2011 5:30 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
Simulating with just the hole cards takes a long time because it deals out every possible combination of the 5 common cards. A stop button (or flag) doesn't really make sense, because the cards aren't dealt randomly, but rather in specifically ordered permutations. If the simulation was stopped prematurely, the results could be greatly skewed.

If you want a quick random simulation, just use the Monte Carlo simulation provided. Example for 5,000 random boards:
SimulateHand("Ah Kd", &results, 0, 1, 5000); /* Example in C, only simulate 5k different boards at random */

You'll probably usually want the opponent range to be the defaults, from 0 to 1. If you're making a bot, you can re-run the simulation with a different value, for example, .9 to 1.0 to simulate an opponent who folds all but the best 10% of his starting hands. Generally, you'll want some average or combination of several simulations.

For example, if the flop is "2h 2d 7h", and you simulate with an opponent range of .9 to 1.0, it will assume that nobody has a flush (and therefor might indicate your hand as the nuts when it's not).

By the way, if you look in simDefs.hpp, there is a table that includes all 1,326 combinations of hole cards. These are the cut-off values used by the opponent range. If you really need accurate hole card simulations often, it would make the most sense to just generate a look-up table on time, and then refer to that.

I'm not sure what you're confused about by the C++ code and macros. If you have specific questions, feel free to ask.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Tue Apr 26, 2011 11:36 am 
Offline
New member
User avatar

Posts: 8
Favourite Bot: Botage
This might seem a somwhat noob question, but what does the 3flush and 4flush mean, I've been looking at the community cards what 3flush or 4flush has been reported, but I cannot see any pattern.

I wonder if you would be so kind as to explain what these represent?


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Tue Apr 26, 2011 6:11 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
3Flush is set if you have three cards of the same suite. 4Flush is the same thing, but with four.


Top
 Profile  
 
 Post subject: Re: Timmy's Poker Sim Library (PSim) Examples in C, Java, AutoIt
PostPosted: Tue Apr 26, 2011 7:51 pm 
Offline
New member
User avatar

Posts: 2
Favourite Bot: N/A
Timmy wrote:
Simulating with just the hole cards takes a long time because it deals out every possible combination of the 5 common cards. A stop button (or flag) doesn't really make sense, because the cards aren't dealt randomly, but rather in specifically ordered permutations. If the simulation was stopped prematurely, the results could be greatly skewed.

If you want a quick random simulation, just use the Monte Carlo simulation provided. Example for 5,000 random boards:
SimulateHand("Ah Kd", &results, 0, 1, 5000); /* Example in C, only simulate 5k different boards at random */

You'll probably usually want the opponent range to be the defaults, from 0 to 1. If you're making a bot, you can re-run the simulation with a different value, for example, .9 to 1.0 to simulate an opponent who folds all but the best 10% of his starting hands. Generally, you'll want some average or combination of several simulations.

For example, if the flop is "2h 2d 7h", and you simulate with an opponent range of .9 to 1.0, it will assume that nobody has a flush (and therefor might indicate your hand as the nuts when it's not).

By the way, if you look in simDefs.hpp, there is a table that includes all 1,326 combinations of hole cards. These are the cut-off values used by the opponent range. If you really need accurate hole card simulations often, it would make the most sense to just generate a look-up table on time, and then refer to that.

I'm not sure what you're confused about by the C++ code and macros. If you have specific questions, feel free to ask.


Thanks for the explanations. I tried with a fixed value for random boards and that is fast.

Great and interesting work. Again thanks for sharing!


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 239 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: