pokerai.org
http://www.pokerai.org/pf3/

Timmy's DLL RankHand() Bugged
http://www.pokerai.org/pf3/viewtopic.php?f=3&t=4826
Page 1 of 1

Author:  rocketboy [ Fri Mar 01, 2013 3:57 am ]
Post subject:  Timmy's DLL RankHand() Bugged

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

Author:  longfields [ Fri Mar 01, 2013 5:46 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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?

Author:  Timmy [ Fri Mar 01, 2013 7:12 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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.

Author:  rocketboy [ Fri Mar 01, 2013 11:15 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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

Author:  longfields [ Sat Mar 02, 2013 4:11 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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!

Author:  Timmy [ Sat Mar 02, 2013 6:32 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

I just meant give the higher level functions a try, like the SimulateHand function.

Author:  longfields [ Sun Mar 03, 2013 12:45 am ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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?

Author:  Timmy [ Sun Mar 03, 2013 6:01 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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.

Author:  longfields [ Sun Mar 03, 2013 11:18 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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.

Author:  longfields [ Thu Mar 07, 2013 10:46 pm ]
Post subject:  Re: Timmy's DLL RankHand() Bugged

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

Page 1 of 1
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/