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.



64
65
66
67
68
69
70
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 64

def initialize(dealer_information)
  @dealer_communicator = DealerStream.new(
    dealer_information.port_number,
    dealer_information.host_name
  )
  @match_state = nil
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 send.

  • match_state (#to_s)

    The current match state.

  • action (#to_s)

    The action to send through the connection.

Returns:

  • (Integer)

    The number of bytes written.



27
28
29
30
31
32
33
34
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 27

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

.send_comment(connection, comment) ⇒ Integer

Sends a comment the given connection.

Parameters:

  • connection (#write, #ready_to_write?)

    The connection through which the comment should send.

  • comment (#to_s)

    The comment to send through the connection.

Returns:

  • (Integer)

    The number of bytes written.



41
42
43
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 41

def self.send_comment(connection, comment)
  connection.write "##{comment}"
end

.send_ready(connection) ⇒ Integer

Sends a ready message to the given connection.

Parameters:

  • connection (#write, #ready_to_write?)

    The connection through which the message should send.

Returns:

  • (Integer)

    The number of bytes written.



49
50
51
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 49

def self.send_ready(connection)
  connection.write DealerStream::READY_MESSAGE
end

.valid_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


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

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



54
55
56
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 54

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


93
94
95
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 93

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

#send_action(action) ⇒ Object

Parameters:

  • action (PokerAction)

    The action to send.

Raises:

  • InitialMatchStateNotYetReceived



76
77
78
79
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 76

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

#send_comment(comment) ⇒ Object

Parameters:

  • comment (#to_s)

    The comment to send.



83
84
85
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 83

def send_comment(comment)
  BasicProxy.send_comment @dealer_communicator, comment
end

#send_readyObject



88
89
90
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 88

def send_ready
  BasicProxy.send_ready @dealer_communicator
end