Class: AcpcTableManager::Proxy
- Inherits:
-
Object
- Object
- AcpcTableManager::Proxy
- Includes:
- AcpcPokerTypes, SimpleLogging
- Defined in:
- lib/acpc_table_manager/proxy.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(match_id, match_name, dealer_information, users_seat, game_definition, player_names = 'user p2', number_of_hands = 1, must_send_ready = false) ⇒ Proxy
constructor
A new instance of Proxy.
- #match_ended? ⇒ Boolean
- #next_hand! ⇒ Object
-
#play!(action, fast_forward = false) ⇒ Object
Player action interface.
- #play_check_fold! ⇒ Object
- #users_turn_to_act? ⇒ Boolean
Methods included from SimpleLogging
Constructor Details
#initialize(match_id, match_name, dealer_information, users_seat, game_definition, player_names = 'user p2', number_of_hands = 1, must_send_ready = false) ⇒ Proxy
TODO:
Reduce the # of params
Returns a new instance of Proxy.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/acpc_table_manager/proxy.rb', line 53 def initialize( match_id, match_name, dealer_information, users_seat, game_definition, player_names='user p2', number_of_hands=1, must_send_ready=false ) @logger = AcpcTableManager.new_log File.join('proxies', "#{match_name}.#{match_id}.#{users_seat}.log") log __method__, { dealer_information: dealer_information, users_seat: users_seat, game_definition: game_definition, player_names: player_names, number_of_hands: number_of_hands } @match_id = match_id @player_proxy = AcpcPokerPlayerProxy::PlayerProxy.new( dealer_information, game_definition, users_seat, must_send_ready ) do |players_at_the_table| if players_at_the_table.match_state update_database! players_at_the_table yield players_at_the_table if block_given? else log __method__, {before_first_match_state: true} end end end |
Class Method Details
.start(match, must_send_ready = false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/acpc_table_manager/proxy.rb', line 23 def self.start(match, must_send_ready = false) game_definition = GameDefinition.parse_file(match.game_definition_file_name) match.game_def_hash = game_definition.to_h match.save! proxy = new( match.id, match.sanitized_name, AcpcDealer::ConnectionInformation.new( match.port_numbers[match.seat - 1], ::AcpcTableManager.config.dealer_host ), match.seat - 1, game_definition, match.player_names.join(' '), match.number_of_hands, must_send_ready ) do |players_at_the_table| yield players_at_the_table if block_given? end end |
Instance Method Details
#match_ended? ⇒ Boolean
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/acpc_table_manager/proxy.rb', line 161 def match_ended? return false if @player_proxy.nil? @match ||= begin Match.find(@match_id) rescue Mongoid::Errors::DocumentNotFound log( __method__, { msg: "Unable to find match", match_id: @match_id, match_ended: @player_proxy.match_ended? } ) return true end @player_proxy.match_ended? @match.number_of_hands end |
#next_hand! ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/acpc_table_manager/proxy.rb', line 91 def next_hand! log __method__ if @player_proxy.hand_ended? @player_proxy.next_hand! do |players_at_the_table| update_database! players_at_the_table yield players_at_the_table if block_given? end end log( __method__, { users_turn_to_act?: @player_proxy.users_turn_to_act?, match_ended?: @player_proxy.match_ended? } ) self end |
#play!(action, fast_forward = false) ⇒ Object
Player action interface
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/acpc_table_manager/proxy.rb', line 115 def play!(action, fast_forward = false) log __method__, users_turn_to_act?: @player_proxy.users_turn_to_act?, action: action if @player_proxy.users_turn_to_act? action = PokerAction.new(action) unless action.is_a?(PokerAction) @player_proxy.play! action do |players_at_the_table| update_database! players_at_the_table, fast_forward yield players_at_the_table if block_given? end log( __method__, { users_turn_to_act?: @player_proxy.users_turn_to_act?, match_ended?: @player_proxy.match_ended? } ) end self end |
#play_check_fold! ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/acpc_table_manager/proxy.rb', line 141 def play_check_fold! log __method__ if @player_proxy.users_turn_to_act? play!( if ( @player_proxy.legal_actions.any? do |a| a == AcpcPokerTypes::PokerAction::FOLD end ) AcpcPokerTypes::PokerAction::FOLD else AcpcPokerTypes::PokerAction::CALL end, true ) end self end |
#users_turn_to_act? ⇒ Boolean
139 |
# File 'lib/acpc_table_manager/proxy.rb', line 139 def users_turn_to_act?() @player_proxy.users_turn_to_act? end |