@@ -48,6 +48,31 @@ def simul?
48
48
def timedout?
49
49
@timedout == 1
50
50
end
51
+
52
+
53
+ def winner_shots_fired
54
+ @bots [ winner ] [ 'shots_fired' ] . to_i
55
+ end
56
+
57
+ def loser_shots_fired
58
+ @bots [ loser ] [ 'shots_fired' ] . to_i
59
+ end
60
+
61
+ def winner_shots_hit
62
+ @bots [ winner ] [ 'shots_hit' ] . to_i
63
+ end
64
+
65
+ def loser_shots_hit
66
+ @bots [ loser ] [ 'shots_hit' ] . to_i
67
+ end
68
+
69
+ def winner_accuracy
70
+ 100 * @bots [ winner ] [ 'shots_hit' ] . to_i /@bots [ winner ] [ 'shots_fired' ] . to_i
71
+ end
72
+
73
+ def loser_accuracy
74
+ 100 * @bots [ loser ] [ 'shots_hit' ] . to_i /@bots [ loser ] [ 'shots_fired' ] . to_i
75
+ end
51
76
52
77
#between 100 and 0
53
78
def winner_health
@@ -61,7 +86,7 @@ def loser_health
61
86
62
87
def one_line_summary
63
88
if !tie?
64
- line = "#{ winner } beats #{ loser } by #{ '%.1f' % margin } energy in #{ @ticks } ticks"
89
+ line = "#{ winner } beats #{ loser } by #{ '%.1f' % margin } energy in #{ @ticks } ticks. #{ winner } accuracy #{ '%.1f' % winner_accuracy } vs. #{ loser } accuracy #{ '%.1f' % loser_accuracy } "
65
90
if @timedout then line += " (match timed out, so #{ winner } gets #{ winner_points } , loser gets #{ loser_points } )" end
66
91
else
67
92
line = "#{ winner } ties #{ loser } at #{ '%.1f' % winner_health } energy in #{ @ticks } ticks"
@@ -85,7 +110,7 @@ def initialize (matches)
85
110
@bots = Hash . new { |h , key | h [ key ] = { } }
86
111
87
112
both_bots = [ @bots [ @matches [ 0 ] . winner ] , @bots [ @matches [ 0 ] . loser ] ]
88
- stats_to_init = [ 'wins' , 'points' , 'ties' , 'margin' , 'simul' , 'timedout' , 'round_wins' ]
113
+ stats_to_init = [ 'wins' , 'points' , 'ties' , 'margin' , 'simul' , 'timedout' , 'round_wins' , 'accuracy' , 'shots_fired' , 'shots_hit' ]
89
114
stats_to_init . each { |stat | both_bots . each { |b | b [ stat ] = 0 } }
90
115
91
116
@matches . each do |match |
@@ -95,6 +120,15 @@ def initialize (matches)
95
120
both_bots . each { |b | b [ 'timedout' ] += 1 if match . timedout? }
96
121
both_bots . each { |b | b [ 'simul' ] += 1 if match . simul? }
97
122
@bots [ match . winner ] [ 'margin' ] += match . margin
123
+
124
+ @bots [ match . winner ] [ 'shots_fired' ] += match . winner_shots_fired
125
+ @bots [ match . loser ] [ 'shots_fired' ] += match . loser_shots_fired
126
+ @bots [ match . winner ] [ 'shots_hit' ] += match . winner_shots_hit
127
+ @bots [ match . loser ] [ 'shots_hit' ] += match . loser_shots_hit
128
+
129
+ @bots [ match . winner ] [ 'accuracy' ] = 100 *@bots [ match . winner ] [ 'shots_hit' ] / @bots [ match . winner ] [ 'shots_fired' ]
130
+ @bots [ match . loser ] [ 'accuracy' ] = 100 *@bots [ match . loser ] [ 'shots_hit' ] / @bots [ match . loser ] [ 'shots_fired' ]
131
+
98
132
if match . tie?
99
133
both_bots . each { |b | b [ 'wins' ] += 0.5 }
100
134
else
@@ -269,7 +303,7 @@ def to_html match_data, html
269
303
rounds << r
270
304
end
271
305
272
- stats = [ 'wins' , 'points' , 'round_wins' , 'margin' , 'simul' , 'timedout' , 'ties' ]
306
+ stats = [ 'wins' , 'points' , 'round_wins' , 'margin' , 'simul' , 'timedout' , 'ties' , 'shots_fired' , 'accuracy' ]
273
307
rankings = { }
274
308
stats . each { |stat | rankings [ stat ] = rank_by_round_stat ( stat , rounds ) }
275
309
0 commit comments