-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarch_calc.rb
197 lines (155 loc) · 3.14 KB
/
march_calc.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#This program calculates the number of each tier of troops to send, accounting for up to t8s.
#To execute, simply hit the run button above. Click on the right window to change focus and
# enter the requested info.
@march_cap = 0
@max_tier = ''
#Below are the ratios used to calculate each tier, adjust if needed or desired.
@t8_infantry = {
:t1 => 0.005,
:t2 => 0.005,
:t3 => 0.005,
:t4 => 0.005,
:t5 => 0.011,
:t6 => 0.012,
:t7 => 0.022,
:t8 => 0.035
}
@t8_cavalry = {
:t1 => 0.005,
:t2 => 0.005,
:t3 => 0.006,
:t4 => 0.012,
:t5 => 0.051,
:t6 => 0.035,
:t7 => 0.068,
:t8 => 0.068
}
@t8_bowmen = {
:t1 => 0.021,
:t2 => 0.021,
:t3 => 0.031,
:t4 => 0.031,
:t5 => 0.058,
:t6 => 0.148,
:t7 => 0.102,
:t8 => 0.238
}
@t7_infantry = {
:t1 => 0.005,
:t2 => 0.005,
:t3 => 0.017,
:t4 => 0.017,
:t5 => 0.012,
:t6 => 0.022,
:t7 => 0.022
}
@t7_cavalry = {
:t1 => 0.005,
:t2 => 0.005,
:t3 => 0.028,
:t4 => 0.025,
:t5 => 0.051,
:t6 => 0.068,
:t7 => 0.068
}
@t7_bowmen = {
:t1 => 0.01,
:t2 => 0.01,
:t3 => 0.056,
:t4 => 0.112,
:t5 => 0.069,
:t6 => 0.157,
:t7 => 0.236
}
#Initial input prompt
def input
puts "Enter your march capacity: "
@march_cap = gets.chomp.to_s.sub(",", "").to_i
puts "Enter max troop tier (suports t7 and t8): "
@max_tier = gets.chomp.downcase
end
#Prompt user to continue calculation, or exit instead
def prompt_exit
puts 'Would you like to perform another calculation? (Y/N): '
ans = gets.chomp.downcase
if ans == 'y' || ans == 'yes'
input
calc_res
else
puts 'Exiting...'
end
end
#Calculates infantry count
def calc_inf
inf = []
if @max_tier == 't7' || @max_tier == '7'
hash = @t7_infantry
elsif @max_tier == 't8' || @max_tier == '8'
hash = @t8_infantry
end
hash.each { |key, value|
troop_cnt = @march_cap * value
troop_cnt = troop_cnt.to_i
res_pair = [key.to_s, troop_cnt]
inf << res_pair
}
inf
end
#Calculates cavalry count
def calc_cav
cav = []
if @max_tier == 't7' || @max_tier == '7'
hash = @t7_cavalry
elsif @max_tier == 't8' || @max_tier == '8'
hash = @t8_cavalry
else
input_error
end
hash.each {|key, value|
troop_cnt = @march_cap * value
troop_cnt = troop_cnt.to_i
res_pair = [key, troop_cnt]
cav << res_pair
}
cav
end
#Calculates bowmen count
def calc_bow
bow = []
if @max_tier == 't7' || @max_tier == '7'
hash = @t7_bowmen
elsif @max_tier == 't8' || @max_tier == '8'
hash = @t8_bowmen
else
input_error
end
hash.each {|key, value|
troop_cnt = @march_cap * value
troop_cnt = troop_cnt.to_i
res_pair = [key, troop_cnt]
bow << res_pair
}
bow
end
#Output results in a semi-decent looking fashion
def calc_res
inf = calc_inf
cav = calc_cav
bow = calc_bow
bow.each do |pair|
puts "#{pair[0]} bowmen: #{pair[1]}"
end
cav.each do |pair|
puts "#{pair[0]} cavalry: #{pair[1]}"
end
inf.each do |pair|
puts "#{pair[0]} infantry: #{pair[1]}"
end
end
def input_error
puts "Invalid input enter in max troop tier! Please try again."
input
end
input
calc_res
prompt_exit