Class: Match

Inherits:
Object
  • Object
show all
Defined in:
lib/rrobots/tournament/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#botsObject (readonly)

Returns the value of attribute bots.



2
3
4
# File 'lib/rrobots/tournament/match.rb', line 2

def bots
  @bots
end

#matchObject (readonly)

Returns the value of attribute match.



4
5
6
# File 'lib/rrobots/tournament/match.rb', line 4

def match
  @match
end

#seedObject (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

#loserObject



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_healthObject

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_pointsObject



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

#marginObject



28
29
30
# File 'lib/rrobots/tournament/match.rb', line 28

def margin
  @bots[winner]['damage_given'] - @bots[loser]['damage_given']
end

#one_line_summaryObject



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/rrobots/tournament/match.rb', line 42

def simul?
  winner_health + loser_health == 0
end

#tie?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rrobots/tournament/match.rb', line 24

def tie?
  return margin == 0.0 
end

#timedout?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rrobots/tournament/match.rb', line 46

def timedout?
  @timedout == 1
end

#winnerObject



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_healthObject

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_pointsObject



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