Class: WebApplicationPlayerProxy

Inherits:
Object
  • Object
show all
Includes:
SimpleLogging
Defined in:
lib/web_application_player_proxy.rb

Overview

A proxy player for the web poker application.

Instance Method Summary collapse

Methods included from SimpleLogging

#log, #logger

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.

Parameters:

  • match_id (String)

    The ID of the match in which this player is participating.

  • dealer_information (DealerInformation)

    Information about the dealer to which this bot should connect.

  • game_definition (GameDefinition, #to_s)

    A game definition; either a GameDefinition or the name of the file containing a game definition.

  • player_names (String) (defaults to: 'user p2')

    The names of the players in this match.

  • number_of_hands (Integer) (defaults to: 1)

    The number of hands in this match.



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")).with_metadata!

  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

Returns:

  • (Boolean)

See Also:

  • PlayerProxy#match_ended?


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

See Also:

  • PlayerProxy#play!


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