-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.rb
66 lines (55 loc) · 2.65 KB
/
script.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
require_relative 'lib/blaine'
TRAIN_SPEED = 0.05
def train_crash(track_str, limit, train_config)
track = Blaine::TrackBuilder.from_string(track_str)
trains = train_config.reduce([]) do |arr, (train_str, position)|
train = Blaine::TrainFactory.from_string(train_str)
track.add_train(train, at: position)
arr << train
end
time = 0
until time >= limit
time += 1
trains.map(&:move_forward)
sleep TRAIN_SPEED
puts `clear`
puts "time passed: #{time}"
puts track.to_s
end
-1
rescue Blaine::Crash
puts "\n**************** CRASH!!!!! ****************"
return time
end
track = """\
/------------\\
/-------------\\ / |
| | / \\------------------------\\ /-\\ /-\\ /-\\ /-\\
| | / | | | | | | | | |
| /----+--------------+------\\ \\-/ | | | | | | |
\\ / | | | /----------\\ \\-/ | | | | |
\\ | \\ | | | \\----------\\ \\-/ | | |
| | \\-------------+------+--------+---\\ | \\-/ |
| | | | | | \\-----\\ | /---------\\
\\------+--------------------+------/ / | | | | |
| | / \\------------------------+-----------+---+----\\ |
\\------S-------------+-------------/ | | | | |
| /------\\ \\ /-----+---+----/ /
/-------------\\ | | \\ \\ / | | /
| | | /-----+----\\ \\ \\ / \\---/ /
| | | | | \\ \\ S /
\\-------------+--------------+-----S-------+-----/ \\ S / \\ /
| | | \\ \\ / \\---------------/
| | | | \\ /
| \\-------------+-------------/ \\---------/
| |
\\----------------------------/
"""
train_config = {
'Aaaa' => 147,
'Bbbbbbbbbbb' => 288,
'xxxxxxxxxxxxxX' => 400,
'qqqqQ' => 0,
}
limit = 50
train_crash(track, limit, train_config)