05-15-2015, 12:44 AM
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[]='(?
?:^%\sPBN\s1\.0\r?\n)|(?:.*\r?\n))?'; // Match PBN line, invalid line, or no line
$regex[]='(?
?:%\sEXPORT\r?\n)|(?:.*\r?\n))?'; // Match EXPORT line, invalid line, or no line
$regex[]='(?
?:%\sID\s(?P<GameID>.*)\r?\n)|(?:.*\r?\n))?'; // Match GameID line, invalid line, or no line
$regex[]='(?
?:%\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.
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[]='(?

$regex[]='(?

$regex[]='(?

$regex[]='(?

$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