我有一个棘手的问题,似乎我被卡住了。我知道如何继续但不知道如何在实践中这样做。
我想要做的是将.txt文件中的字符串转换为另一种格式(使用正则表达式和变量?)。主要问题是当我需要转换那些标有//注释的行时。
注意:“... villainx调用$ x”的原始版本和应转换为的格式不同。这就是我需要一些认真帮助的问题。
实施例: 这需要转换......
HERO posts small blind $0.50.
villain4 posts big blind $1.00.
** Dealing down cards **
Dealt to HERO [ 7s 8c 5d 8d ]
villain1 calls $1.00
villain2 raises to $3.00 // total sum a player raises to
villain3 calls $3.00
HERO calls $3.00
villain4 calls $3.00
villain1 calls $3.00 // total sum a player calls whether he has put money in to the pot before (as he has -- $1 call, first to act)
** Dealing Flop ** [ 9c, Ah, Jh ]
......对此:
HERO posts small blind [$0.50 USD].
villain4 posts big blind [$1.00 USD].
** Dealing down cards **
Dealt to HERO [ 7s 8c 5d 8d ]
villain1 calls [$1.00 USD]
villain2 raises [$3.00 USD] // total sum a player raises to
villain3 calls [$3.00 USD]
HERO calls [$2.50 USD] // a sum player calls = last raise ($3) - money put in (=$0.50 small blind)
villain4 calls [$2.00 USD] // $3 - $1 (big blind)
villain1 calls [$2.00 USD] // $3 - $1 (the call first to act)
** Dealing Flop ** [ 9c, Ah, Jh ]
另一个例子:
HERO posts small blind $0.50.
villain4 posts big blind $1.00.
** Dealing down cards **
Dealt to HERO [ 7s 8c 5d 8d ]
villain1 bets $5.50
villain2 raises to $20.00
villain3 raises to $40.00
villain1 calls $40.00 //THIS NEEDS TO BE "calls $34.50"
villain2 calls $40.00 //THIS NEEDS TO BE "calls $20.00"
** Dealing Flop ** [ 9c, Ah, Jh ]
这里是完整的例子,整个手应该如何看待。 Txt文件可能包含数百手。我已经设法preg_replace基本上所有其他问题,但上面。我迷路了。请帮我! :d
***** Hand History for Game 335502358 ***** (Full Tilt)
$100.00 USD PL Omaha - Thursday, October 15, 01:32:21 ET 2009
Table Foxtrot (Real Money)
Seat 3 is the button
Seat 1: villain1 ( $38.50 USD )
Seat 2: villain2 ( $99.65 USD )
Seat 3: villain3 ( $415.55 USD )
Seat 4: HERO ( $99.00 USD )
Seat 6: villain4 ( $171.20 USD )
HERO posts small blind [$0.50 USD].
villain4 posts big blind [$1.00 USD].
** Dealing down cards **
Dealt to HERO [ 7s 8c 5d 8d ]
villain1 calls [$1.00 USD]
villain2 raises [$3.00 USD]
villain3 calls [$3.00 USD]
HERO calls [$2.50 USD]
villain4 calls [$2.00 USD]
villain1 calls [$2.00 USD]
** Dealing Flop ** [ 9c, Ah, Jh ]
HERO checks
villain4 checks
villain1 checks
villain2 bets [$8.00 USD]
villain3 folds
HERO folds
villain4 calls [$8.00 USD]
villain1 folds
** Dealing Turn ** [ Th ]
villain4 checks
villain2 bets [$13.00 USD]
villain4 calls [$13.00 USD]
** Dealing River ** [ 3c ]
villain4 checks
villain2 checks
villain2 shows [Qc, Js 8s Qd ]
villain4 shows [Kh, Tc 7h Kd ]
villain4 wins $54.15 USD from main pot
编辑1:添加注释以澄清我的真实问题
编辑2:添加了另一个例子
答案 0 :(得分:1)
您是否可以使用preg_match取出美元值并使用preg_replace重新排列字符串?
$regex = '/(\$[0-9.]+)/';
$matched = preg_match($regex, $stringToMatch, $matches);
if($matched > 0)
{
$output string = preg_replace($regex, '['.$matches[0].' USD]', $stringToMatch);
}
唯一不做的就是忽略你声明每个'座位'的开头的行,这样你可能需要首先过滤掉那些[简单的strpos($ stringToMatch,'Seat')就足够了,虽然不是很优雅。
答案 1 :(得分:0)
while($line = get the next line)
{
if($line contains 'seat')
{
$player = get player from $line
$pool = get player pool from $line
$bettingMatrix[$player]['pool'] = $pool;
}
else if($line contains 'blind')
{
$player = get player from $line
$betValue = get blind value from $line
$bettingMatrix[$player]['betTotal'] = $betValue
$bettingMatrix['pot'] += $betValue //keep a sum of the pot
}
else if($line contains 'raises')
{
$player = get player from $line
$betValue = get value from $line
$betMade = $betValue - $bettingMatrix[$player]['betTotal']; //actual amount raised by
$bettingMatrix[$player]['betTotal'] = $betValue //$line contains total bet this hand (shortcut)
$bettingMatrix['raiseValue'] = $betMade
$bettingMatrix['pot'] += $betMade //keep a sum of the pot
}
else if($line contains 'calls')
{
$player = get player from $line
//if player has called, can work out bet from raiseValue
$betMade = $bettingMatrix['raiseValue']
$bettingMatrix[$player]['betTotal'] += $betMade
$bettingMatrix['pot'] += $betMade //keep a sum of the pot
}
else if(substr($line, 0, 3) == ' Wins ') //probably do something about players named Wins :)
{
//assume all bets resolved
foreach($bettingMatrix[$player])
{
update pool.
zero betTotal
}
zero pot, zero raiseValue
}
}
嗯,它非常粗糙和准备好了,我可能不会把它当作Parser这样,但它确实能够计算出你需要的所有值,无论如何我想。 2 $ betMade变量应该以您想要的值结束。
编辑:我刚刚注意到,如果没有人加注并且每个人都只是打电话或弃牌(如果每个人都只是折叠或其他什么的话,可能会死得很厉害),它就不会起作用了。它确实需要更多的工作,但它是一般的要点 - 称之为半答案。遗憾。