Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > Internet Gambling > Software
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2005, 08:10 PM
donger donger is offline
Junior Member
 
Join Date: Apr 2004
Posts: 5
Default a little perl help, please

Hi,
I'm working on fixing the bisonbison converter so that it works with the new absolute hand history format. Right now, everything is working except you have to reorder the seat numbers numerically before pasting in the hand:

Seat 6 - DAWGNWNUTS69 ($196 in chips)
Seat 7 - JERKSTORE ($181.50 in chips)
Seat 9 - NEOND ($104 in chips)
Seat 5 - STANSFIELD ($49 in chips)

has to become:

Seat 5 - STANSFIELD ($49 in chips)
Seat 6 - DAWGNWNUTS69 ($196 in chips)
Seat 7 - JERKSTORE ($181.50 in chips)
Seat 9 - NEOND ($104 in chips)

in order for the converter to work.

I was wondering if someone could help me write the piece of code to sort this $Players object by the PlayerSeatNumber property?

Here's the relevant code where the object is filled:

<font class="small">Code:</font><hr /><pre>
while ($Message =~ s/Seat (\d+) - (.*?) \(((\$)?\d+(\.\d+)?) in chips\)//)
{
$Players{"$j"}-&gt;{"PlayerSeatNumber"} = $1;
$Players{"$j"}-&gt;{"PlayerName"} = $2;
$Players{"$j"}-&gt;{"PlayerStack"} = $3;

###SORT $Players here so the following code doesn't break

#name the seats, starting at the button
if ($Players{"$j"}-&gt;{"PlayerSeatNumber"} == $SeatButton)
{
$Players{"$j"}-&gt;{"PlayerTitle"} = "Button";
$Players{"$j"}-&gt;{"PlayerTitleDisplay"} = "Button";
}
elsif (($Players{"$j"}-&gt;{"PlayerSeatNumber"} &gt; $SeatButton) &amp;&amp; ($j &lt;= $PlayerCount))
{
$Players{"$j"}-&gt;{"PlayerTitle"} = pop @SeatTitleList;
$Players{"$j"}-&gt;{"PlayerTitleDisplay"} = pop @SeatTitleDisplayList;

}
$j++;
}
</pre><hr />



THANKS!
donger
Reply With Quote
  #2  
Old 10-17-2005, 09:15 AM
jba jba is offline
Senior Member
 
Join Date: Feb 2005
Posts: 672
Default Re: a little perl help, please

why are you sorting in the middle of that loop? I'm not really sure what you're getting at but you can sort @Players with something like:

@sorted = sort { $a-&gt;{"PlayerSeatNumber"} &lt;=&gt; $b-&gt;{"PlayerSeatNumber"} } @Players
Reply With Quote
  #3  
Old 10-17-2005, 01:13 PM
SheridanCat SheridanCat is offline
Member
 
Join Date: Sep 2002
Location: Chicago
Posts: 86
Default Re: a little perl help, please

I tried working with the original code and found it very, very difficult and prone to breakage and utter confusion. It's pretty terrible stuff. If you're planning to submit a patch to bisonbison to handle Absolute properly, I wish you luck.

I decided to just reimplement a converter for kicks. If you're interested, you can find the latest here:

http://www.pokergeek.com/software

It doesn't currently support Absolute, but adding that support is fairly trivial.

Anyway....

I'm a little puzzled by the code snippet. Perhaps a little more context for the code would be helpful. Specifically, where is $j coming from? If you're actually trying to sort %Players within that while loop while populating %Players, something is wrong with the logic.

If the j$ scalar is just a counter, which it might be based on the $j++ at the end, then I would suggest you use the seat number ($1) as the hash key instead. In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

Good luck,

T
Reply With Quote
  #4  
Old 10-17-2005, 01:33 PM
zram21 zram21 is offline
Junior Member
 
Join Date: Dec 2003
Posts: 0
Default Re: a little perl help, please

[ QUOTE ]
In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

[/ QUOTE ]

That won't work on a 10 seat table. (I can't remember if Absolute is 9 handed or 10 handed tables.) That will produce a sorted list of 1,10,2,3,4,5,6,7,8,9.

for (sort { $a &lt;=&gt; $b } keys %Players) would do what he was looking for though.
Reply With Quote
  #5  
Old 10-17-2005, 02:18 PM
SheridanCat SheridanCat is offline
Member
 
Join Date: Sep 2002
Location: Chicago
Posts: 86
Default Re: a little perl help, please

[ QUOTE ]
[ QUOTE ]
In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

[/ QUOTE ]

That won't work on a 10 seat table. (I can't remember if Absolute is 9 handed or 10 handed tables.) That will produce a sorted list of 1,10,2,3,4,5,6,7,8,9.

for (sort { $a &lt;=&gt; $b } keys %Players) would do what he was looking for though.

[/ QUOTE ]

Oh, yeah, forgot about that wrinkle. The default sort is to sort them as strings.

T
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.