Class: WebApplicationPlayerProxy
- Inherits:
-
Object
- Object
- WebApplicationPlayerProxy
- Includes:
- SimpleLogging
- Defined in:
- lib/web_application_player_proxy.rb
Overview
A proxy player for the web poker application.
Instance Method Summary collapse
-
#initialize(match_id, dealer_information, users_seat, game_definition, player_names = 'user p2', number_of_hands = 1) ⇒ WebApplicationPlayerProxy
constructor
A new instance of WebApplicationPlayerProxy.
- #match_ended? ⇒ Boolean
-
#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) ⇒ WebApplicationPlayerProxy
TODO:
Reduce the # of params
Returns a new instance of WebApplicationPlayerProxy.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/web_application_player_proxy.rb', line 28 def initialize( match_id, dealer_information, users_seat, game_definition, player_names='user p2', number_of_hands=1 ) @logger = Logger.from_file_name(File.join(ApplicationDefs::LOG_DIRECTORY, 'proxy_logs', "#{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 ) 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 |
Instance Method Details
#match_ended? ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/web_application_player_proxy.rb', line 86 def match_ended? return false if @player_proxy.nil? @match ||= Match.find(@match_id) @player_proxy.match_ended? || ( @player_proxy.hand_ended? && @player_proxy.match_state.hand_number >= @match.number_of_hands - 1 ) end |
#play!(action) ⇒ Object
Player action interface
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/web_application_player_proxy.rb', line 65 def play!(action) log __method__, action: action @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 |