Class: Match
- Inherits:
-
Object
- Object
- Match
- Defined in:
- lib/rrobots/tournament/match.rb
Instance Attribute Summary collapse
-
#bots ⇒ Object
readonly
Returns the value of attribute bots.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
Instance Method Summary collapse
-
#initialize(data) ⇒ Match
constructor
A new instance of Match.
- #loser ⇒ Object
-
#loser_health ⇒ Object
between 100 and 0.
- #loser_points ⇒ Object
- #margin ⇒ Object
- #one_line_summary ⇒ Object
- #simul? ⇒ Boolean
- #tie? ⇒ Boolean
- #timedout? ⇒ Boolean
- #winner ⇒ Object
-
#winner_health ⇒ Object
between 100 and 0.
- #winner_points ⇒ Object
Constructor Details
#initialize(data) ⇒ Match
Returns a new instance of Match.
6 7 8 9 10 11 12 |
# File 'lib/rrobots/tournament/match.rb', line 6 def initialize(data) @bots = data['robots'] @seed = data['seed'] @ticks= data['elapsed_ticks'] @timedout = data['timedout'] @match = data['match'] end |
Instance Attribute Details
#bots ⇒ Object (readonly)
Returns the value of attribute bots.
2 3 4 |
# File 'lib/rrobots/tournament/match.rb', line 2 def bots @bots end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
4 5 6 |
# File 'lib/rrobots/tournament/match.rb', line 4 def match @match end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
3 4 5 |
# File 'lib/rrobots/tournament/match.rb', line 3 def seed @seed end |
Instance Method Details
#loser ⇒ Object
19 20 21 22 |
# File 'lib/rrobots/tournament/match.rb', line 19 def loser sorted = @bots.sort{|a,b| a[1]['damage_given'] <=> b[1]['damage_given']} return sorted[0][0] end |
#loser_health ⇒ Object
between 100 and 0
56 57 58 |
# File 'lib/rrobots/tournament/match.rb', line 56 def loser_health [100 - @bots[loser]['damage_taken'], 0].max end |
#loser_points ⇒ Object
37 38 39 40 |
# File 'lib/rrobots/tournament/match.rb', line 37 def loser_points return 0.5 if simul? return loser_health / (winner_health + loser_health) end |
#margin ⇒ Object
28 29 30 |
# File 'lib/rrobots/tournament/match.rb', line 28 def margin @bots[winner]['damage_given'] - @bots[loser]['damage_given'] end |
#one_line_summary ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rrobots/tournament/match.rb', line 60 def one_line_summary if !tie? line = "#{winner} beats #{loser} by #{'%.1f' % margin} energy in #{@ticks} ticks" if @timedout then line += " (match timed out, so #{winner} gets #{winner_points}, loser gets #{loser_points})" end else line = "#{winner} ties #{loser} at #{'%.1f' % winner_health} energy in #{@ticks} ticks" if @timedout then line += " (match timed out.)" end end line += " (timed out)" if @timeout return line end |
#simul? ⇒ Boolean
42 43 44 |
# File 'lib/rrobots/tournament/match.rb', line 42 def simul? winner_health + loser_health == 0 end |
#tie? ⇒ Boolean
24 25 26 |
# File 'lib/rrobots/tournament/match.rb', line 24 def tie? return margin == 0.0 end |
#timedout? ⇒ Boolean
46 47 48 |
# File 'lib/rrobots/tournament/match.rb', line 46 def timedout? @timedout == 1 end |
#winner ⇒ Object
14 15 16 17 |
# File 'lib/rrobots/tournament/match.rb', line 14 def winner sorted = @bots.sort{|a,b| a[1]['damage_given'] <=> b[1]['damage_given']} return sorted[1][0] end |
#winner_health ⇒ Object
between 100 and 0
51 52 53 |
# File 'lib/rrobots/tournament/match.rb', line 51 def winner_health [100 - @bots[winner]['damage_taken'], 0].max end |
#winner_points ⇒ Object
32 33 34 35 |
# File 'lib/rrobots/tournament/match.rb', line 32 def winner_points return 0.5 if simul? return winner_health / (winner_health + loser_health) end |