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 =
"3.1.0"

Class Method Summary collapse

Class Method Details

.dealer_running?(dealer_process_hash) ⇒ Boolean

Returns:

  • (Boolean)

77
78
79
80
81
82
83
# File 'lib/acpc_dealer.rb', line 77

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


71
72
73
74
75
# File 'lib/acpc_dealer.rb', line 71

def self.force_kill_process(pid)
  if pid && pid > 0
    Process.kill('KILL', pid)
  end
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
66
67
68
69
# File 'lib/acpc_dealer.rb', line 65

def self.kill_process(pid)
  if pid && pid > 0
    Process.kill('TERM', pid)
  end
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)

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/acpc_dealer.rb', line 88

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