解析txt文件的方法
我希望为扑克手牌历史创建一个解析器。我想提取诸如按钮是谁?之类的信息,
我该如何处理?这是一个示例历史文件:
#Game No : 11460450069
***** Hand History for Game 11460450069 *****
NL Texas Hold'em $1 USD Buy-in Trny:67308896 Level:8 Blinds-Antes(600/1.200 -50) - Wednesday, February 22, 05:48:56 EST 2012
Table Turbo #2533048 (Real Money)
Seat 5 is the button
Total number of players : 2/10
Seat 5: NAME( 2,898 )
Seat 2: NAME( 17,102 )
Trny:67308896 Level:8
Blinds-Antes(600/1.200 -50)
NAMEposts ante [50]
NAMEposts ante [50]
** Dealing down cards **
Dealt to NAME[ Th Js ]
NAME is all-In [2,248]
NAME calls [1,648]
** Dealing Flop ** [ 3h, 2d, 9s ]
** Dealing Turn ** [ Jd ]
** Dealing River ** [ Ad ]
NAME shows [ 5s, Kc ]high card Ace.
NAME shows [ Th, Js ]a pair of Jacks.
NAME wins 5,796 chips from the main pot with a pair of Jacks.
NAME finished in 2 place and won $2.55 USD.
I wish to create a parser for poker hand history. I want to extract information like who is the button?
How might I approach this? Here's a sample history file:
#Game No : 11460450069
***** Hand History for Game 11460450069 *****
NL Texas Hold'em $1 USD Buy-in Trny:67308896 Level:8 Blinds-Antes(600/1.200 -50) - Wednesday, February 22, 05:48:56 EST 2012
Table Turbo #2533048 (Real Money)
Seat 5 is the button
Total number of players : 2/10
Seat 5: NAME( 2,898 )
Seat 2: NAME( 17,102 )
Trny:67308896 Level:8
Blinds-Antes(600/1.200 -50)
NAMEposts ante [50]
NAMEposts ante [50]
** Dealing down cards **
Dealt to NAME[ Th Js ]
NAME is all-In [2,248]
NAME calls [1,648]
** Dealing Flop ** [ 3h, 2d, 9s ]
** Dealing Turn ** [ Jd ]
** Dealing River ** [ Ad ]
NAME shows [ 5s, Kc ]high card Ace.
NAME shows [ Th, Js ]a pair of Jacks.
NAME wins 5,796 chips from the main pot with a pair of Jacks.
NAME finished in 2 place and won $2.55 USD.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件格式是文件结构的规范。它们通常是二进制的,但在您的情况和许多其他情况下,它们是文本。您需要做的第一件事是确定文档的结构,然后逐行阅读。您还可以使用使此过程变得更加容易的工具,例如基于解析语法规则的工具。我认为 ANTLR,正如 Philip 在他的回答中提到的,是这些工具之一......
File formats are specification of structure of a file. They're usually in binary but in your case and in many other cases, they're text. The first thing you need to do is decide on the structure of your document and then read it like by line. You can also use tools that make this process much easier, like those based on Parse Grammar rules. I think ANTLR, as mentioned by Philip in his answer, is one of those tools...