Class: AcpcPokerPlayerProxy::PlayerProxy

Inherits:
AcpcPokerTypes::PlayersAtTheTable
  • Object
show all
Includes:
AcpcPokerBasicProxy, AcpcPokerTypes
Defined in:
lib/acpc_poker_player_proxy/player_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dealer_information, game_definition_argument, users_seat = nil, must_send_ready = false) {|_self| ... } ⇒ PlayerProxy

Returns a new instance of PlayerProxy.

Parameters:

  • dealer_information (DealerInformation)

    Information about the dealer to which this bot should connect.

  • game_definition_argument (GameDefinition, #to_s)

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

Yields:

  • (_self)

Yield Parameters:



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
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 32

def initialize(
  dealer_information,
  game_definition_argument,
  users_seat = nil,
  must_send_ready = false
)
  @must_send_ready = must_send_ready
  game_def = if game_definition_argument.kind_of?(
    GameDefinition
  )
    game_definition_argument
  else
    GameDefinition.parse_file(game_definition_argument)
  end
  @basic_proxy = BasicProxy.new dealer_information

  @players_at_the_table = if users_seat
    PlayersAtTheTable.seat_players game_def, users_seat
  else
    PlayersAtTheTable.seat_players game_def
  end
  super @players_at_the_table

  @match_has_ended = false

  yield self if block_given?
  update_match_state_if_necessary! { yield self if block_given? }
end

Instance Attribute Details

#game_defObject (readonly)

Returns the value of attribute game_def.



25
26
27
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 25

def game_def
  @game_def
end

#match_has_endedObject (readonly)

Returns the value of attribute match_has_ended.



23
24
25
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 23

def match_has_ended
  @match_has_ended
end

#must_send_readyObject (readonly)

Returns the value of attribute must_send_ready.



27
28
29
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 27

def must_send_ready
  @must_send_ready
end

#players_at_the_tablePlayersAtTheTable (readonly)

Returns Summary of the progression of the match in which, this player is participating, since this object’s instantiation.

Returns:

  • (PlayersAtTheTable)

    Summary of the progression of the match in which, this player is participating, since this object’s instantiation.



21
22
23
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 21

def players_at_the_table
  @players_at_the_table
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
102
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 93

def connected?
  begin
    @basic_proxy.send_comment 'KA'
  rescue AcpcPokerBasicProxy::DealerStream::UnableToWriteToDealer
    @match_has_ended = true
    false
  else
    true
  end
end

#match_ended?(max_num_hands = nil) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 75

def match_ended?(max_num_hands = nil)
  @match_has_ended ||= (
    @players_at_the_table.match_ended?(max_num_hands) || !connected?
  )
end

#next_hand!Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 81

def next_hand!
  if @must_send_ready
    begin
      @basic_proxy.send_ready
    rescue AcpcPokerBasicProxy::DealerStream::UnableToWriteToDealer => e
      @match_has_ended = true
      raise MatchEnded.with_context("Cannot send ready message!", e)
    end
    update_match_state! { yield self if block_given? }
  end
end

#play!(action) ⇒ Object

Player action interface

Parameters:

  • action (PokerAction)

    The action to take.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/acpc_poker_player_proxy/player_proxy.rb', line 63

def play!(action)
  begin
    @basic_proxy.send_action action
  rescue AcpcPokerBasicProxy::DealerStream::UnableToWriteToDealer => e
    raise MatchEnded.with_context(
      "Cannot take action #{action} because the match has ended!",
      e
    )
  end
  update_match_state! { yield self if block_given? }
end