Image Image Image




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Timmy's DLL RankHand() Bugged
PostPosted: Fri Mar 01, 2013 3:57 am 
Offline
New member
User avatar

Posts: 2
Favourite Bot: AI bot
Hi all! For some time i decided to use the Tim's library because mine is very slow written in VB6 but it seems like the RankHand() function is totally messed up. I don't know if i maked a mistake in my code or is just the function bugged.

Code:
Here is the numbers i get when i try to get the ranks of two players:
Player1 = JdKh, Player2=9d9s, Board=Kd3s3cAhQc | result=handRank() returns 7168 for both players but Player1 is Winner
Player1 = 5sAs, Player2=9dQd, Board=JhQc4s2dKs | result=handRank() returns -17773 for 'Player1' and -18096 for 'Player2', making the first player winner instead of the second player


Please anyone if could help me to solve this i will appreciate very much.
Code:
Public Declare Function RankHand Lib "dlls\psim.dll" (ByVal hand As String) As Integer


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Fri Mar 01, 2013 5:46 pm 
Offline
Senior member
User avatar

Posts: 131
I've been having similar problems, and I haven't full solved it. But I have a couple of suggestions:

1. I'm pretty sure that 'As Integer' should be 'As Long' at the end of your 'Public Declare' statement.

2. In the same statement, you might try 'ByRef' instead of 'ByVal' in relation to the hand.

I'd be interested to know if you manage to get it to work. Have you tried any of the other functions?

_________________
http://www.pokerspreadsheets.com


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Fri Mar 01, 2013 7:12 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
RankHand is exported as an unsigned 32-bit integer. In VB6, I believe an "Integer" is a signed 16-bit value.

ASAIK, VB6 doesn't have unsigned types. If you're still getting negative numbers using "As Long", I'm sure you can do a work around with bitwise operators and a more nuanced comparison.

If you're using RankHand to ultimately do some sort of equity calculation, you're probably much better of just having PSIM do that directly and forgetting about RankHand.


Top
 Profile  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Fri Mar 01, 2013 11:15 pm 
Offline
New member
User avatar

Posts: 2
Favourite Bot: AI bot
Problem solved. It seems like VB doesen't like this function in a module or class. If you try this your application will crash or you will get 'Too complex expression' error. You have to put it inside your project form to avoid the problem.

The function now works fine if i return a long as the Longfields said but i still pass the argument ByVal because i get 0 if i use ByRef.

Code:
Private Declare Function RankHand Lib "dlls\psim.dll" (ByVal hand As String) As Long

Public Sub Command1_Click()
    Dim strAllCards as String
    strAllCards = "AhKh Td5hJh"

    'Should return '833923' if not then you're in trouble
    MsgBox "Timmy's DLL-->RankHand=Your hand ranks to '" & RankHand(strAllCards) & "'"
End Sub


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Sat Mar 02, 2013 4:11 pm 
Offline
Senior member
User avatar

Posts: 131
Glad that rocketboy solved his problem.

Timmy wrote:
I'm sure you can do a work around with bitwise operators and a more nuanced comparison........you're probably much better of just having PSIM do that directly and forgetting about RankHand.


Timmy, I'd really appreciate some pointers here, because this is beyond my expertise and I can't find much about it in relation to VB. Thanks!

_________________
http://www.pokerspreadsheets.com


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Sat Mar 02, 2013 6:32 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
I just meant give the higher level functions a try, like the SimulateHand function.


Top
 Profile  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Sun Mar 03, 2013 12:45 am 
Offline
Senior member
User avatar

Posts: 131
Timmy wrote:
I just meant give the higher level functions a try, like the SimulateHand function.


I'd be grateful for some help with this, too. My VB code looks like this (extract):

Code:
Type simResultsStruct
    win As Single
    tie As Single
    lose As Single
    winSd As Single
    tieSd As Single
    loseSd As Single
    d94 As Single
    d90 As Single
    evaluations As Integer
End Type

Private Declare Function SimulateHand Lib "C:\Documents\Poker\psim.dll" (ByVal hand As String, ByRef simResults As simResultsStruct, ByVal par1 As Single, ByVal par2 As Single, ByVal par3 As Long)

Public Sub Command()
    Dim results As simResultsStruct
    Cards = "AhKh"
    Run = SimulateHand(Cards, results, 0, 1, 0)
    HandSimulate = results.winSd * 100
End Sub


But it doesn't work. Maybe there's a concept that I don't understand - I certainly wouldn't claim to be a programmer, I'm just trying to learn enough to get to the next step. Any ideas?

_________________
http://www.pokerspreadsheets.com


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Sun Mar 03, 2013 6:01 pm 
Offline
PokerAI fellow
User avatar

Posts: 686
Location: Midwest, USA
Favourite Bot: N/A
I think you're missing dNow in your struct (should be after loseSd). evaluations should probably be a long (32-bit).

SimulateHand doesn't return anything, so maybe you need to declare it as a sub instead of a function (it's been a long time since I've used VB6). I think you can maybe replace "Run = " with "Call".

Maybe make those changes and see what you get. If it's still not working give your code again and an example of the output.


Top
 Profile  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Sun Mar 03, 2013 11:18 pm 
Offline
Senior member
User avatar

Posts: 131
Timmy wrote:
I think you're missing dNow in your struct (should be after loseSd).


Are you sure? I copied the struct from the AutoIT equivalent:

Code:
$simResultsStruct = "float win; float tie; float lose; float winSd; float tieSd; float loseSd; float d94; float d90; int evaluations"


I can't see where 'dNow' comes from.

_________________
http://www.pokerspreadsheets.com


Top
 Profile E-mail  
 
 Post subject: Re: Timmy's DLL RankHand() Bugged
PostPosted: Thu Mar 07, 2013 10:46 pm 
Offline
Senior member
User avatar

Posts: 131
Just in case anyone should read this thread in the future and wonder about the outcome:

It turns out that the code I had was incorrect, in that I was trying to call the variables used in psim directly, but the 'HandState' - type functions use pointers. It is possible to use pointers in this kind of function in VB6, using the 'AddressOf' keyword. However, I was trying to call psim from an Excel module - and this you cannot do. You can only use pointers in this way from a standard .BAS module.

For more information, see these links:

http://msdn.microsoft.com/en-us/library/aa263532%28v=VS.60%29.aspx
http://msdn.microsoft.com/en-us/library/aa263529%28v=vs.60%29.aspx

_________________
http://www.pokerspreadsheets.com


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


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: