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, 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) ⇒ Object
Player action interface.
Methods included from SimpleLogging
Constructor Details
#initialize(match_id, 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.
50 51 52 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 |
# File 'lib/acpc_table_manager/proxy.rb', line 50 def initialize( match_id, 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_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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acpc_table_manager/proxy.rb', line 22 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, 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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/acpc_table_manager/proxy.rb', line 132 def match_ended? return false if @player_proxy.nil? @match ||= begin Match.find(@match_id) rescue Mongoid::Errors::DocumentNotFound return true end @player_proxy.match_ended? || ( @player_proxy.hand_ended? && @player_proxy.match_state.hand_number >= @match.number_of_hands - 1 ) end |
#next_hand! ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/acpc_table_manager/proxy.rb', line 87 def next_hand! log __method__ @player_proxy.next_hand! do |players_at_the_table| update_database! players_at_the_table 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? } ) self end |
#play!(action) ⇒ Object
Player action interface
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/acpc_table_manager/proxy.rb', line 109 def play!(action) log __method__, action: action action = PokerAction.new(action) unless action.is_a?(PokerAction) @player_proxy.play! action do |players_at_the_table| update_database! players_at_the_table 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? } ) self end |