Guest User

Untitled

a guest
Jun 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. module Phander::Parsers
  2. class Pokerstars < Base
  3. Stages = {
  4. :hole => 'HOLE CARDS',
  5. :flop => 'FLOP',
  6. :turn => 'TURN',
  7. :river => 'RIVER'}
  8.  
  9. def self.this_parser?(string)
  10. string[0..9] == 'PokerStars'
  11. end
  12.  
  13. def go
  14. @data[:title] = title
  15. @data[:seats] = seats
  16. @data[:title][:number_of_players] = @data[:seats].size
  17. @data[:blinds] = blinds
  18. @data[:stages] = stages
  19. @data[:summary] = summary
  20. @data
  21. end
  22.  
  23. def title
  24. @s.scan(/PokerStars Game #(\d+): (.+) -/)
  25. {:hand_id => @s[1], :table_type => @s[2]}
  26. end
  27.  
  28. def seats
  29. @s.skip_until(/is the button\s*\n/)
  30. seats = []
  31. while @s.check(/Seat/)
  32. @s.scan(/Seat (\d): (.+) \(\$([\d\.]+) in chips\)/)
  33. seats << {:seat_number => @s[1], :name => @s[2], :chips => @s[3].to_f}
  34. @s.skip_until(/\s*\n/)
  35. end
  36. seats
  37. end
  38.  
  39. def blinds
  40. @s.scan(/(.+): posts small blind \$([\d\.]+)\s+/)
  41. small = {:name => @s[1], :amount => @s[2].to_f}
  42. @s.scan(/(.+): posts big blind \$([\d\.]+)\s+/)
  43. big = {:name => @s[1], :amount => @s[2].to_f}
  44.  
  45. {:small => small, :big => big}
  46. end
  47.  
  48. def stages
  49. stages_ar = Stages.map{|v| v[1]}
  50. @s.skip_until(/\*\*\* /)
  51. stages = []
  52. while @s.check(/[^\*]+/) && stages_ar.include?(@s.matched.strip)
  53. stage_name = @s.matched
  54. @s.pos += @s.matched_size
  55. @s.skip(/\*\*\*/)
  56. if @s.check(/ \[(.+?)\]/)
  57. stage_cards = @s[1]
  58. @s.pos += @s.matched_size
  59. if @s.check(/ \[(.+?)\]/)
  60. stage_cards << " #{@s[1]}"
  61. @s.pos += @s.matched_size
  62. end
  63. else
  64. stage_cards = nil
  65. end
  66. @s.skip_until(/\s*\n/)
  67. stage_actions = []
  68. while !@s.check(/\*\*\*/)
  69. unless @s.check(/Uncalled/)
  70. action = {:name => @s.scan(/[^:]+/)}
  71. @s.skip(/[\s:]+/)
  72. ActionParsers.detect do |k, v|
  73.  
  74. if @s.check(v[:pattern])
  75. action[:type] = k
  76. v.reject{|k2, v2| k2 == :pattern}.each {|k2, v2| action[k2] = @s[v2].to_f}
  77. true
  78. else
  79. false
  80. end
  81. end
  82. stage_actions << action
  83. end
  84. @s.skip_until(/\s*\n/)
  85. end
  86. stages << {:name => stage_name, :cards => (stage_cards ? Phander.hand(stage_cards) : nil), :actions => stage_actions}
  87. @s.skip_until(/\*\*\* /)
  88. end
  89. stages
  90. end
  91.  
  92. def summary
  93. @s.skip_until(/\*\*\* SUMMARY \*\*\*/)
  94. @s.skip_until(/\s*\n/)
  95. @s.scan(/Total pot \$([\d\.]+) \| Rake \$([\d\.]+)/)
  96. pot = @s[1].to_f
  97. rake = @s[2].to_f
  98. @s.skip_until(/\s*\n/)
  99. @s.scan(/Board \[(.+?)\]/)
  100. board = @s[1]
  101.  
  102. winner = {}
  103. showers = []
  104. while @s.skip_until(/\s*\n/) && !@s.eos?
  105. N
  106. end
  107. {:pot => pot, :rake => rake, :board => Phander.hand(board), :winner => winner, :showers => showers}
  108. end
  109.  
  110. end
  111.  
  112. end
Add Comment
Please, Sign In to add comment