Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PlayOK Hand History: Seeking Regex Guru
#1
So, it's been over 6 months since I have had time to dedicate to development for PowerPinochle.  One of my last projects was the Hand Animator for PlayOK Hand Histories and while I was getting close to finishing it I think the over-all complexity of the project really slowed it down.  During my inactivity, Marek from PlayOK has decided to discontinue collecting his hand histories and making them available for 6 months.  He told me that there was simply not enough interest.  This is no surprise because most people can't process the raw syntax easily.  So the onus is on me!  Marek says when I get something done on my end, he will reconsider archiving the hand histories (with a limited lifespan).

The ball is in my court now.  Rather than struggle through tricky parts of an already over-complicated Hand Animator.  I've decided to take a large step back and just develop a non-animated Deal Revealer.  Mostly I just want to give a life-like visual representation of the hand history, and allow users to switch between different hands in a given game.

The first step is dissecting the .txt file.  I have spent some time sharpening my regex skills to develop a single expression that will allow PHP's preg_match_all() to capture all pertinent values from the hand history.  On the surface, this is easily done, in fact I had a working expression in place for my Hand Animator program; however, it is not as robust as it could be.  I also want to be able to ignore non-matching lines (by capturing an empty value) while still yielding a TRUE from preg_match_all().

If anyone would like to try their hand at this, I welcome you to try.  I just don't have the spare time at this point.  If anyone needs information on websites to trial their work, I can give that.  If anyone wants to see my current attempt, I can give that.  If anyone has any questions just ask.

I really want to get this program into the Resources menu ASAP.  I wish I had more time.  I will cross my fingers that our membership may gain me some ground in this endeavor!

TIA

OH, and I nearly forgot, so you don't have to randomly trek through in-progress pinochle games @ playok.com, I've harvested a few test .txt files and saved them to Power Pinochle.

http://www.powerpinochle.com/playok/PO_test1.txt
http://www.powerpinochle.com/playok/PO_test2.txt
http://www.powerpinochle.com/playok/PO_test3.txt
http://www.powerpinochle.com/playok/PO_test4.txt
http://www.powerpinochle.com/playok/PO_test5.txt
http://www.powerpinochle.com/playok/PO_test6.txt
http://www.powerpinochle.com/playok/PO_test7.txt
http://www.powerpinochle.com/playok/PO_test8.txt
http://www.powerpinochle.com/playok/PO_test9.txt

Bear in mind, I will be stripping all white-spaces from the start and finish of the hand histories before processing them.

Again, the single expression must not fail even if there is as little as one syntax character in the entire.

Here's a sample to help things along.

$txt='% PBN 1.0
% EXPORT
% ID ?
%
[Event "?"]
[Site "PlayOK.com"]
[Date "2015.05.12"]
[West "jadasiahs"]
[North "tap123"]
[East "bird260"]
[South "alvin54"]
[Dealer "W"]
[Deal "W:KKQQQJJJT.AKQJJJ.KJ.ATT KJTT.AKQTT.AKKJT.AAQQJT AKT.AQTT.KQQQQJT.AKKQJJ AAAQ.AKKQJ.AAAJTT.KKQJT"]
[GameScore "0:0"]
[Declarer "E"]
[Contract "50"]
[Melds "10:16"]
[Trump "D"]
[Result "NOMELDS"]
[Score "0:-50"]
{
S KJTT
H AKQTT
D AKKJT
C AAQQJT

S KKQQQJJJT +-------+ S AKT
H AKQJJJ | N | H AQTT
D KJ | W E | D KQQQQJT
C ATT | S | C AKKQJJ
+-------+

S AAAQ
H AKKQJ
D AAAJTT
C KKQJT
}
[Auction "W"]
Pass 50 Pass Pass
';

function nonZeroKeys($array){    // so that array keys = actual pinochle hand number

for($i=count($array); $i>0; --$i){
$array[$i]=$array[$i-1];
}
unset($array[0]);
return $array;
}
$regex[]='(?Sad?:^%\sPBN\s1\.0\r?\n)|(?:.*\r?\n))?'; // Match PBN line, invalid line, or no line 

$regex[]='(?Sad?:%\sEXPORT\r?\n)|(?:.*\r?\n))?'; // Match EXPORT line, invalid line, or no line
$regex[]='(?Sad?:%\sID\s(?P<GameID>.*)\r?\n)|(?:.*\r?\n))?'; // Match GameID line, invalid line, or no line
$regex[]='(?Sad?:%\r?\n)|(?:.*\r?\n))?'; // Match PBN-END line, invalid line, or no line
$rgx="/(?J)".implode("",$regex)."/"; // merge regex components and allow duplicate capture names
if(preg_match_all($rgx,$txt,$got)){

    unset($got[0]);
    foreach($got as $key=>$array){
        if(is_numeric($key)){
            unset($got[$key]);
        }else{
            $got[$key]=nonZeroKeys($array);
        }
    }
    print_r($got);
}else{
    echo "got nothing";
}




... I ran out of time to type and proofread.  Let me know if you can help or if you have questions.
It's unbelievable how much you don't know about the game you've been playing all your life. -- Mickey Mantle
Reply
#2
Nope, never mind, I found a more efficient way to process the hand histories.
Stay tuned for developments...    errrr, rather - please be patient, I promise something good will come!
It's unbelievable how much you don't know about the game you've been playing all your life. -- Mickey Mantle
Reply
#3
Keep working...it is going to be awesome when it is done!
Reply
#4
After continued Game Reviewer program development, I am realizing that while the PlayOK Bridge Notation format offers all the data that is required to completely display games, there are some portions that require me to run time-consuming processes to generate the necessary values.


I have decided to construct our own in-house Power Pinochle Notation for recording/creating game histories.
My changes includes:
  • Shifting static tags to the game heading section (beginning with %) 
  • Consolidating tags
  • Removing the textual Deal diagram
  • Re-sequencing tags to mirror game flow
  • Altering tag values to require no additional game rule processing, simply extract & display
  • Converting dot-separated hand notation to suit-letter-separated hand notation
  • Defaulting all seat-related values to NESW
  • Arranging suit ranks from AKQJT to the more appropriate ATKQJ
  • Arranging suit order from SHDC to CDSH which is what Power Pinochle currently uses elsewhere, *adopted from Yahoo! for alternating coloration
  • Reversing Play Phase card naming from SuitRank to RankSuit, which is what Power Pinochle currently uses elsewhere and is how card names are spoken (e.g. "King of Spades" = "KS")
  • Appending Trick results: Winning Seat Letter and Counters in Trick 
  • Improving the Result value options from NOMARRIAGE|NOMELDS to SAVED|SET|NO BOARD|NO TRUMP
What does this mean?  This means for my development of the Game Reviewer program, I will need to carry out an extra step.  PlayOK Notation will need to be converted to Power Pinochle Notation before it can be processed.

Why bother?  This will shrink file size slightly, decrease Game Reviewer processing some, simplify program development, allow users to transport data from one PP tool to another, AND eventually allow PP members to create their own hands from scratch!

[EDIT] Also, this will set PP up to offer incomplete hand histories as quizzes!  I could write a program to allow users to finish a hand.  What a great tool for teaching and learning.  All these simple, powerful tools will rely on a robust foundation.  I believe we are onto something good and important here![/EDIT]

The Game Reviewer program is initially to be used to review PlayOK games, but will be flexible enough to allow teachers and learners to go step by step through a real or fabricated hand.
I am optimistic that this will launch brand new and highly details discussions in the forum.

Again, I must warn that I am very time poor at the moment, so I will ask for your patience.

  
PlayOK Notation looks like this:
% PBN 1.0
% EXPORT
% ID ?
%
[Event "?"]
[Site "PlayOK.com"]
[Date "2015.05.12"]
[West "chris1395"]
[North "clhday"]
[East "iambbl"]
[South "wanda0405"]
[Dealer "S"]
[Deal "S:KKJJ.AKKQQJTT.AKQJJT.QQ AAAQQ.KJ.KKQJTT.AKQJJTT AKQJTT.AKJTT.QJT.AKJJTT KQJTT.AAQQJ.AAAKQ.AAKKQ"]
[GameScore "0:0"]
[Declarer "W"]
[Contract "56"]
[Melds "16:35"]
[Trump "C"]
[Result "72"]
[Score "0:72"]
{
           S AKQJTT
           H AKJTT
           D QJT
           C AKJJTT

S AAAQQ    +-------+  S KQJTT
H KJ       |   N   |  H AAQQJ
D KKQJTT   | W   E |  D AAAKQ
C AKQJJTT  |   S   |  C AAKKQ
           +-------+

           S KKJJ
           H AKKQQJTT
           D AKQJJT
           C QQ
}
[Auction "S"]
50 Pass Pass 51
52 - - 53
54 - - 55
56 - - Pass
[Play "W"]
CJ CA CQ CQ
SA SJ SK SQ
HA HJ HK HJ
DQ DA DJ DK
HA HJ HK HJ
HA HQ CK HT
CQ CK CA CQ
DA DJ DK DJ
DA DQ DT DT
HQ HK CT HT
SA SJ SK SJ
DQ CT DQ DK
SK ST SJ SA
DJ CT DK DT
HK HQ HT CT
CA CJ CK HQ
DT CJ CK DA
SQ SK SA SQ
SQ ST ST HT
ST CA HA CJ


Power Pinochle Notation will look like this:
% Format "PPN 1.0"
% Site "PlayOK.com"
% Date "2015.05.12"
% ID "135846"
% Players "chris1395 clhday iambbl wanda0405"

[GameScores "0:0"]
[Deal "S:CATTKJJDTQJSATTKQJHATTKJ CAAKKQDAAAKQSTTKQJHAAQQJ CQQDATKQJJSKKJJHATTKKQQJ CATTKQJJDTTKKQJSAAAQQHKJ"]
[Auction "W:50 Pass Pass 51 52 - - 53 54 - - 55 56 - - Pass"]
[Contract "W 56 C"]
[Melds "10:CJDJSKQJHJ 14:CKQDKQSKQHQ 6:CDKQSHKKQQ 21:CATKQJDKQJSQH"]
[Play "W"]
JC AC QC QC N1
AS JS KS QS N2
AH JH KH JH N2
QD AD JD KD E2
AH JH KH JH E2
AH QH KC TH W3
QC KC AC QC E2
AD JD KD JD E2
AD QD TD TD E3
QH KH TC TH W3
AS JS KS JS W2
QD TC QD KD N2
KS TS JS AS W3
JD TC KD TD N3
KH QH TH TC W3
AC JC KC QH W2
TD JC KC AD E3
QS KS AS QS W2
QS TS TS TH N3
TS AC AH JC E5
[MeldScores "0:35"]
[PlayScores "0:37"]
[Result "SAVED"]
[HandScores "0:72"]
It's unbelievable how much you don't know about the game you've been playing all your life. -- Mickey Mantle
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)