Class: AcpcPokerBasicProxy::BasicProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_basic_proxy/basic_proxy.rb

Constant Summary collapse

CONCATENATED_MODIFIABLE_ACTIONS =
AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.to_a.join

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dealer_information) ⇒ BasicProxy

Returns a new instance of BasicProxy.

Parameters:

  • dealer_information (AcpcDealer::ConnectionInformation)

    Information about the dealer to which this bot should connect.



43
44
45
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 43

def initialize(dealer_information)
  @dealer_communicator = DealerStream.new dealer_information.port_number, dealer_information.host_name, dealer_information.millisecond_response_timeout
end

Class Method Details

.send_action(connection, match_state, action) ⇒ Integer

Sends the given action to through the given connection in the ACPC format.

Parameters:

  • connection (#write, #ready_to_write?)

    The connection through which the action should be sent.

  • match_state (#to_s)

    The current match state.

  • action (#to_s)

    The action to be sent through the connection.

Returns:

  • (Integer)

    The number of bytes written.



25
26
27
28
29
30
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 25

def self.send_action(connection, match_state, action)
  validate_action action

  full_action = "#{AcpcPokerTypes::MatchState.parse(match_state.to_s)}:#{action.to_s}"
  connection.write full_action
end

.valid_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 37

def self.valid_action?(action)
  action.to_s.match(/^[#{AcpcPokerTypes::PokerAction::CONCATONATED_ACTIONS}]$/) ||
  action.to_s.match(/^[#{CONCATENATED_MODIFIABLE_ACTIONS}]\d+$/)
end

.validate_action(action) ⇒ Object

Raises:

  • IllegalActionFormat



33
34
35
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 33

def self.validate_action(action)
  raise IllegalActionFormat unless self.valid_action?(action)
end

Instance Method Details

#receive_match_state!Object

See Also:

  • MatchStateReceiver#receive_match_state


57
58
59
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 57

def receive_match_state!
  @match_state = AcpcPokerTypes::MatchState.receive @dealer_communicator
end

#send_action(action) ⇒ Object

Parameters:

  • action (PokerAction)

    The action to be sent.

Raises:

  • InitialMatchStateNotYetReceived



51
52
53
54
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 51

def send_action(action)
  raise InitialMatchStateNotYetReceived unless @match_state
  BasicProxy.send_action @dealer_communicator, @match_state, action
end