-
Notifications
You must be signed in to change notification settings - Fork 1
/
brave.rb
executable file
·90 lines (67 loc) · 2.29 KB
/
brave.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env ruby
require 'ostruct'
require 'optparse'
require 'yaml'
# Use reasonable defaults and parse shell args for specific options
def state_list(list = "dummy")
# Repeat for default of up to 10 agents
list.split(',').map{ |j| j.strip.to_sym } * 10
end
config_file = "config.yml"
if File.exist?(config_file)
$options = OpenStruct.new(YAML.load(IO.read(config_file)).merge(:config_file => "config.yml"))
else
$options = OpenStruct.new(:config_file => "config.yml")
end
opts = OptionParser.new do |opts|
opts.banner = "Usage: brave.rb [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-s", "--server [SERVER]", "Connect to server") do |srv|
$options.server = srv
end
opts.on("-p", "--port [NUMBER]", "Connect to port") do |port|
$options.port = port.to_i
end
opts.on("-c", "--config-file [FILE]", "The Yaml configuration file") do |c|
$options.config_file = c
end
opts.on("-i", "--initial-state [LIST,OF,STATES]", "(e.g. 'dummy', 'smart')") do |i|
$options.initial_state = i
end
opts.on("-m", "--macro-strategy", "Use the macro strategy rather than assigning initial states") do
$options.strategy = true
end
opts.on("-r", "--refresh [VALUE]", "Potential field refresh rate (e.g. 0.05)") do |r|
$options.refresh = r.to_f
end
opts.on("-g", "--gnuplot [VALUE]", "Where should we export the gnuplot file?") do |r|
$options.gnuplot_file = r
end
opts.on("-d", "--debug", "Do you want to see the detailed gnuplot?") do
$options.debug = true
end
end
opts.parse!(ARGV)
puts "Starting brave.rb with the following options: \n"
y $options.instance_variable_get("@table")
$options.initial_state = state_list($options.initial_state)
# Our main program begins here:
require 'rubygems'
require 'eventmachine'
require(File.join(File.dirname(__FILE__), "bzrequire"))
bzrequire 'lib/headquarters'
bzrequire 'lib/astar/astar',
"You may need to compile the astar (A*) extension: \n" +
"$ cd lib/astar && ruby extconf.rb && make\n"
puts
# Check that the bzfs server is running on the expected port
if `netstat -an|grep \.#{$options.port}\s`.empty?
puts "Warning: unable to connect to port #{$options.port}"
end
EventMachine.run do
EventMachine::connect(
$options.server,
$options.port,
BraveZealot::Headquarters)
end