-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.rb
55 lines (52 loc) · 1.54 KB
/
simulator.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
require_relative 'prospector'
require_relative 'map_finder'
# Class that runs gold rush simulation
class Simulator
def initialize(seed, prospector_count)
@seed = seed # Random number generator seed
@prospector_count = prospector_count # Number of prospectors
end
# Starts the simulator, calls all needed methods
# to keep the simulator running
def play
puts 'Start Simulator'
set_map
x = 1
while x <= @prospector_count
pete = Prospector.new(@map, MapFinder.new)
run_simulation(x, pete)
pete.see_results(x)
x += 1
end
end
# sets up the map
def set_map
# Sets up map of cities
@map = [
['Sutter Creek', 'Coloma', 'Angels Camp'],
['Coloma', 'Virginia City', 'Sutter Creek'],
['Angels Camp', 'Nevada City', 'Virginia City', 'Sutter Creek'],
['Nevada City', 'Angels Camp'],
['Virginia City', 'Angels Camp', 'Coloma', 'Midas', 'El Dorado Canyon'],
['Midas', 'Virginia City', 'El Dorado Canyon'],
['El Dorado Canyon', 'Virginia City', 'Midas']
]
end
# Starts the prospector simulation
def run_simulation(prospector_count, pete)
prospector_count = prospector_count.to_i
# Iterate through each prospector
success = nil
count = 0
y = 0
puts "\nProspector #{prospector_count} is starting in #{@map[y][0]}"
while count < 5 && prospector_count > 0
pete.mine(count, y)
count += pete.location_count
y = pete.next_location(y, @seed) unless count > 5
success = count
end
success
end
end
# end of class