#!/bin/bash toggle() { if [ "$1" == "$2" ]; then echo $3 else echo $2 fi } code_to_action_str() { local actorposition=$1 local code=$2 local street=$3 local type=`echo $code | cut -b 1` local player=`eval echo '$'"${actorposition}player"` local player_cip=`eval echo '$'"${actorposition}_cip"` local otherplayer_cip=`toggle $player_cip $sb_cip $bb_cip` local player_cip_ts=`eval echo '$'"${actorposition}_cip_thisstreet"` local otherplayer_cip_ts=`toggle $player_cip_ts $sb_cip_thisstreet $bb_cip_thisstreet` case $type in c) if [ $player_cip_ts -eq $otherplayer_cip_ts ]; then echo ${player}: checks elif [ $player_cip_ts -lt $otherplayer_cip_ts ]; then echo ${player}: calls $((otherplayer_cip_ts - player_cip_ts)) sb_cip=$otherplayer_cip bb_cip=$otherplayer_cip sb_cip_thisstreet=$otherplayer_cip_ts bb_cip_thisstreet=$otherplayer_cip_ts else echo ERROR: shouldnt get here in code_to_action_str:check 1>&2 echo $stateline 1>&2 fi ;; f) echo ${player}: folds ;; r) local size=`echo $code | sed 's/r\(.*\)/\1/'` if [ $otherplayer_cip_ts -eq 0 ]; then local betsize=$((size-player_cip)) echo "${player}: bets $betsize" eval ${actorposition}_cip_thisstreet=$betsize eval ${actorposition}_cip=$size elif [ $otherplayer_cip_ts -gt $player_cip_ts ] || [ $otherplayer_cip_ts -eq $player_cip_ts -a $street == preflop ] ; then local raisesize=$((size - otherplayer_cip)) local totalraise=$((size-otherplayer_cip+otherplayer_cip_ts)) echo "${player}: raises $raisesize to $totalraise" eval ${actorposition}_cip=$size eval ${actorposition}_cip_thisstreet=$totalraise else echo ERROR: shouldnt get here in code_to_action_str:raise 1>&2 echo $stateline 1>&2 fi ;; *) echo ERROR:SHOULD NOT GET HERE, code: $code 1>&2 ;; esac } play_street() { local actor=$1 local action=$2 local street=$3 while read a do code_to_action_str $actor $a $street actor=`toggle $actor sb bb` done < <(echo $action | cut -d / -f 1 | sed 's/\([crf]\)/\n\1/g'|grep -vE '^$' ) } play_hand() { local line="$1" local p1stack=$2 local p2stack=$3 local resultvar=$4 local handnum=`echo $line | cut -d : -f 2` local action=`echo $line | cut -d : -f 3` local pf_action=`echo /$action | cut -d / -f 2` local f_action=`echo /$action | cut -d / -f 3` local t_action=`echo /$action | cut -d / -f 4` local r_action=`echo /$action | cut -d / -f 5` local cards=`echo $line | cut -d : -f 4` local bbcards=`echo $cards | tr '/' '|' | cut -d \| -f 1` local sbcards=`echo $cards | tr '/' '|' | cut -d \| -f 2` local flop=`echo $cards | tr '/' '|' | cut -d \| -f 3` local turn=`echo $cards | tr '/' '|' | cut -d \| -f 4` local river=`echo $cards | tr '/' '|' | cut -d \| -f 5` local profits=`echo $line | cut -d : -f 5` local bbprofit=`echo $profits | cut -d \| -f 1` local sbprofit=`echo $profits | cut -d \| -f 2` local finalpot=`echo $bbprofit|sed 's/-//'` local players=`echo $line | cut -d : -f 6` local bbplayer=`echo $players | cut -d \| -f 1` local sbplayer=`echo $players | cut -d \| -f 2` echo PokerStars Game \#$handnum: Tournament \#1, $line echo "Seat 1: $P1 ($p1stack in chips)" echo "Seat 2: $P2 ($p2stack in chips)" echo ${sbplayer}: posts small blind $sbsize echo ${bbplayer}: posts big blind $bbsize echo "*** HOLE CARDS ***" echo Dealt to $sbplayer [$sbcards] echo Dealt to $bbplayer [$bbcards] # preflop play sb_cip_thisstreet=$sb_cip bb_cip_thisstreet=$bb_cip play_street sb $pf_action preflop # flop play sb_cip_thisstreet=0 bb_cip_thisstreet=0 if [ -n "$f_action" ]; then echo "*** FLOP *** [$flop]" play_street bb $f_action flop fi # turn play sb_cip_thisstreet=0 bb_cip_thisstreet=0 if [ -n "$t_action" ]; then echo "*** TURN *** [$flop] [$turn]" play_street bb $t_action turn fi # river play sb_cip_thisstreet=0 bb_cip_thisstreet=0 if [ -n "$r_action" ]; then echo "*** RIVER *** [$flop$turn] [$river]" play_street bb $r_action river fi echo "*** SUMMARY ***" echo "Total pot $finalpot | Rake 0" if [ -n "$flop$turn$river" ]; then echo "Board [$flop$turn$river]" fi if [ "$P1" == "$bbplayer" -a "$P2" == "$sbplayer" ]; then echo "Seat 1: $bbplayer collected ($bbprofit)" echo "Seat 2: $sbplayer collected ($sbprofit)" elif [ "$P1" == "$sbplayer" -a "$P2" == "$bbplayer" ]; then echo "Seat 1: $sbplayer collected ($sbprofit)" echo "Seat 2: $bbplayer collected ($bbprofit)" else echo ERROR: players dont match up in summar 1>&2 fi eval $resultvar=$p1profit } ##file="2012/logs/2p_nolimit/2012-2p-nolimit.hyperborean.hugh.run-1.perm-0.log" P1="hugh" P2="hyperborean" p1stack=20000 p2stack=20000 sbsize=50 bbsize=100 for file in 2012/logs/2p_nolimit/2012-2p-nolimit.hyperborean.hugh* do echo parsing $file 1>&2 cat $file | grep STATE | while read stateline do sb_cip=$sbsize bb_cip=$bbsize play_hand "$stateline" $p1stack $p2stack p1prof # doyle's game: don't update the stack sizes # p1stack=`echo $p1stack + $p1prof | bc` # p2stack=`echo $p2stack - $p1prof | bc` echo "" done done