Class: AcpcDealerData::HandData
- Inherits:
-
Object
- Object
- AcpcDealerData::HandData
- Defined in:
- lib/acpc_dealer_data/hand_data.rb
Defined Under Namespace
Classes: Turn
Instance Attribute Summary collapse
-
#chip_distribution ⇒ Object
Returns the value of attribute chip_distribution.
-
#data ⇒ Object
Returns the value of attribute data.
-
#match_def ⇒ Object
Returns the value of attribute match_def.
-
#seat ⇒ Object
Returns the value of attribute seat.
-
#turn_number ⇒ Object
Returns the value of attribute turn_number.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #current_match_state(seat = @seat) ⇒ Object
- #final_turn? ⇒ Boolean
- #for_every_turn!(seat = 0) ⇒ Object
-
#initialize(match_def, action_data, result) ⇒ HandData
constructor
A new instance of HandData.
- #last_action ⇒ Object
- #last_match_state(seat = @seat) ⇒ Object
-
#next_action ⇒ ActionMessage
Next action in the hand to be taken in the current turn.
- #set_chip_distribution!(result) ⇒ Object protected
- #set_data!(action_data) ⇒ Object protected
Constructor Details
#initialize(match_def, action_data, result) ⇒ HandData
Returns a new instance of HandData.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 38 def initialize(match_def, action_data, result) @match_def = match_def set_chip_distribution! result set_data! action_data @turn_number = nil @seat = nil end |
Instance Attribute Details
#chip_distribution ⇒ Object
Returns the value of attribute chip_distribution.
17 18 19 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 17 def chip_distribution @chip_distribution end |
#data ⇒ Object
Returns the value of attribute data.
17 18 19 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 17 def data @data end |
#match_def ⇒ Object
Returns the value of attribute match_def.
17 18 19 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 17 def match_def @match_def end |
#seat ⇒ Object
Returns the value of attribute seat.
17 18 19 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 17 def seat @seat end |
#turn_number ⇒ Object
Returns the value of attribute turn_number.
17 18 19 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 17 def turn_number @turn_number end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 52 53 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 49 def ==(other) @match_def == other.match_def && @chip_distribution == other.chip_distribution && @data == other.data end |
#current_match_state(seat = @seat) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 67 def current_match_state(seat=@seat) if @turn_number @data[@turn_number].[seat] else nil end end |
#final_turn? ⇒ Boolean
100 101 102 103 104 105 106 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 100 def final_turn? if @turn_number @turn_number >= @data.length - 1 else nil end end |
#for_every_turn!(seat = 0) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 55 def for_every_turn!(seat=0) @seat = seat @data.each_index do |i| @turn_number = i yield @turn_number end @turn_number = nil self end |
#last_action ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 92 def last_action if @turn_number && @turn_number != 0 @data[@turn_number-1]. else nil end end |
#last_match_state(seat = @seat) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 84 def last_match_state(seat=@seat) if @turn_number && @turn_number != 0 @data[@turn_number-1].[seat] else nil end end |
#next_action ⇒ ActionMessage
Returns Next action in the hand to be taken in the current turn.
76 77 78 79 80 81 82 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 76 def next_action if @turn_number @data[@turn_number]. else nil end end |
#set_chip_distribution!(result) ⇒ Object (protected)
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 110 def set_chip_distribution!(result) @chip_distribution = [] result.each do |player_name, amount| begin @chip_distribution[@match_def.player_names.index(player_name.to_s)] = amount rescue TypeError raise PlayerNamesDoNotMatch end end end |
#set_data!(action_data) ⇒ Object (protected)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/acpc_dealer_data/hand_data.rb', line 121 def set_data!(action_data) = @match_def.game_def.number_of_players @data = [] = 0 while < action_data.length = action_data[..+-1] = += = if action_data.in_bounds?() && action_data[].respond_to?(:action) += 1 action_data[-1] else action_data, , nil end @data << Turn.new(, ) end end |