From 0e36b095fa46f84f0c2fd234904b6a8c07fb702e Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Sat, 12 Aug 2023 10:55:48 +0200 Subject: [PATCH] guess Opp --- parse.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/parse.php b/parse.php index d6dc534..24320b5 100644 --- a/parse.php +++ b/parse.php @@ -30,6 +30,7 @@ else { $turns = 0 ; $winner = "" ; + $opp = ""; $first = "" ; $data = htmlspecialchars(trim( $_POST["log"] ) ) ; $data_ar = preg_split("/\r\n|\n|\r/", $data); @@ -40,9 +41,13 @@ else { $turns++ ; } - if ( strpos( $line, "ends turn 1" ) ) { - $line_a = explode( " ", "$line" ) ; - $winner = $line_a[0] ; + if ( preg_match( '/^([a-zA-Z0-9]+) ends turn 1$/', $line, $match ) ) { + $first = $match[1] ; + } + if( $opp==='') { + if( preg_match( '/^Attacked ([a-zA-Z0-9]+) for/', $line, $match ) ) { + $opp=$match[1] ; + } } if( preg_match( '/^Played <color=#[A-Z0-9]+>(.*)<\/color>/', $line, $match ) ) { @@ -51,9 +56,16 @@ else { if ( strpos( $line, "===" ) ) { $line_a = explode( " ", "$line" ) ; - $first = $line_a[9] ; + $winner = $line_a[9] ; } + if( preg_match( '/^Acquired <color=#[A-Z0-9]+>(.*)<\/color>/', $line, $match ) ) { + $acLine = explode( " ", $previousLine ) ; + $p=$acLine[8] ; + echo "$$p buy $match[1]" ; + } + + $previousLine=$line ; } echo "
" ; echo "\n"; @@ -63,13 +75,14 @@ else { $result = array( "first player" => $first, "winner" => $winner, + "opp" => $opp, "num_turns" => $turns , "expansions" => array_values( array_unique($usedExt) ), ) ; print json_encode( $result, JSON_PRETTY_PRINT ); print "

in csv format:

" ; - print "1st player, winner, #turns, expansions
" ; - print "$first,$winner,$turns, " . implode( " ", array_values( array_unique($usedExt) ) ); + print "1st player, winner, opponent, #turns, expansions
" ; + print "$first,$winner, $opp,$turns, " . implode( " ", array_values( array_unique($usedExt) ) ); } function guessExpansion( $card, $cards, $ext ) {