Module: AcpcDealer

Defined in:
lib/acpc_dealer.rb,
lib/acpc_dealer/version.rb,
lib/acpc_dealer/dealer_runner.rb

Defined Under Namespace

Classes: ConnectionInformation, DealerRunner

Constant Summary collapse

VENDOR_DIRECTORY =
File.expand_path('../../vendor', __FILE__)
DEALER_DIRECTORY =
File.join(VENDOR_DIRECTORY, 'project_acpc_server')
GAME_DEFINITION_FILE_PATHS =
{
  2 =>
  {
    limit: "#{DEALER_DIRECTORY}/holdem.limit.2p.reverse_blinds.game",
    nolimit: "#{DEALER_DIRECTORY}/holdem.nolimit.2p.reverse_blinds.game"
  },
  3 =>
  {
    limit: "#{DEALER_DIRECTORY}/holdem.limit.3p.game",
    nolimit: "#{DEALER_DIRECTORY}/holdem.nolimit.3p.game",
    kuhn: "#{DEALER_DIRECTORY}/kuhn.limit.3p.game"
  }
}
DEALER_PATH =
"#{DEALER_DIRECTORY}/dealer"
EXAMPLE_PLAYERS =
{
  2 =>
  {
    limit: "#{DEALER_DIRECTORY}/example_player.limit.2p.sh",
    nolimit: "#{DEALER_DIRECTORY}/example_player.nolimit.2p.sh"
  },
  3 =>
  {
    limit: "#{DEALER_DIRECTORY}/example_player.limit.3p.sh",
    nolimit: "#{DEALER_DIRECTORY}/example_player.nolimit.3p.sh",
    kuhn_sf1: "#{DEALER_DIRECTORY}/kuhn_3p_equilibrium_player.sf1.sh",
    kuhn_sf2: "#{DEALER_DIRECTORY}/kuhn_3p_equilibrium_player.sf2.sh",
    kuhn_sf3: "#{DEALER_DIRECTORY}/kuhn_3p_equilibrium_player.sf3.sh"
  }
}
VERSION =
"2.4.1"

Class Method Summary collapse

Class Method Details

.dealer_running?(dealer_process_hash) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/acpc_dealer.rb', line 68

def self.dealer_running?(dealer_process_hash)
  (
    dealer_process_hash &&
    dealer_process_hash[:pid] &&
    process_exists?(dealer_process_hash[:pid])
  )
end

.default_match_name(players, game_def, seed) ⇒ Object



53
54
55
# File 'lib/acpc_dealer.rb', line 53

def self.default_match_name(players, game_def, seed)
  "#{players.join('-')}.#{game_def}.r#{seed}.#{date}"
end

.force_kill_process(pid) ⇒ Object



66
# File 'lib/acpc_dealer.rb', line 66

def self.force_kill_process(pid) Process.kill('KILL', pid) end

.game_def_label(number_of_players, betting_type_key) ⇒ Object



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

def self.game_def_label(number_of_players, betting_type_key)
  "#{number_of_players}P-#{betting_type_key}"
end

.kill_process(pid) ⇒ Object



65
# File 'lib/acpc_dealer.rb', line 65

def self.kill_process(pid) Process.kill('TERM', pid) end

.port_available?(port, ip = 'localhost') ⇒ Boolean

Thanks to joast and Chris Rice (stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open) for this (modified)

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/acpc_dealer.rb', line 79

def self.port_available?(port, ip = 'localhost')
  begin
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(ip, port)
        s.close
        return false
      rescue Errno::EHOSTUNREACH
        return false
      rescue Errno::ECONNREFUSED
        return true
      end
    end
  rescue Timeout::Error
  end
  return false
end

.process_exists?(pid) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
# File 'lib/acpc_dealer.rb', line 57

def self.process_exists?(pid)
  begin
    Process.getpgid pid
    true
  rescue Errno::ESRCH
    false
  end
end