Actually able to guess expansions used during game
This commit is contained in:
71
parse.php
Normal file
71
parse.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
|
||||
if( ! isset( $_SERVER["HTTP_HOST"])) {
|
||||
parse_str($argv[1], $_POST);
|
||||
}
|
||||
if( $_POST["called"] != 1 ) {
|
||||
print "Copy SR log below" ;
|
||||
$self = "$_SERVER[PHP_SELF]";
|
||||
$form= <<<EOF
|
||||
<form method="POST" action="$self">
|
||||
<textarea style="width:200px; height:600px;" name="log">Paste log Here</textarea>
|
||||
<input type="submit" name="Ok"/>
|
||||
<input type="hidden" name="called" value="1"/>
|
||||
</form>
|
||||
EOF;
|
||||
print $form ;
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
$ext=array() ;
|
||||
$cards=array() ;
|
||||
$csvfile = fopen('cards.csv', "r") or die( "unable to open card file" ) ;
|
||||
while( $line = fgetcsv( $csvfile ) ){
|
||||
array_push( $ext, $line[0] );
|
||||
array_push( $cards, $line[2] ) ;
|
||||
}
|
||||
|
||||
$turns = 0 ;
|
||||
$winner = "" ;
|
||||
$first = "" ;
|
||||
$data = trim( $_POST["log"] ) ;
|
||||
$data_ar = preg_split("/\r\n|\n|\r/", $data);
|
||||
|
||||
foreach ($data_ar as $line ) {
|
||||
if( strpos( $line, "ends turn" ) ) {
|
||||
static $turns ;
|
||||
$turns++ ;
|
||||
}
|
||||
|
||||
if ( strpos( $line, "ends turn 1" ) ) {
|
||||
$line_a = explode( " ", "$line" ) ;
|
||||
$winner = $line_a[0] ;
|
||||
}
|
||||
|
||||
if( preg_match( '/^Played <color=#[A-Z0-9]+>(.*)<\/color>/', $line, $match ) ) {
|
||||
guessExpansion( $match[1], $cards, $ext ) ;
|
||||
}
|
||||
|
||||
if ( strpos( $line, "===" ) ) {
|
||||
$line_a = explode( " ", "$line" ) ;
|
||||
$first = $line_a[9] ;
|
||||
}
|
||||
|
||||
}
|
||||
echo "<br />" ;
|
||||
echo "\n";
|
||||
echo "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "first player is: $first <br />";
|
||||
echo "winner is: $winner<br />" ;
|
||||
echo "num of turns: $turns<br />" ;
|
||||
|
||||
}
|
||||
function guessExpansion( $card, $cards, $ext ) {
|
||||
if( $key = array_search( $card, $cards)){
|
||||
print( $ext[$key]."<br />" ) ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user