Class: Rubygoal::CoachDefinitionHome

Inherits:
CoachDefinition show all
Defined in:
lib/rubygoal/coaches/coach_definition_home.rb

Instance Method Summary collapse

Methods inherited from CoachDefinition

method_missing, name, #name, players, #players, team, team_players

Instance Method Details

#formation(match) ⇒ Object



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
# File 'lib/rubygoal/coaches/coach_definition_home.rb', line 26

def formation(match)
  formation = Formation.new

  if match.me.winning?
    formation.defenders :pereira, :cacerez, :gimenez, :godin, :rodriguez
    formation.midfielders :lodeiro, :none, :rolan, :none, :arevalo
    formation.attackers :none, :cavani, :none, :suarez, :none
  elsif match.time < 20
    formation.defenders :none, :rolan, :cacerez, :gimenez, :none
    formation.midfielders :arevalo, :lodeiro, :godin, :none, :pereira
    formation.attackers :suarez, :none, :none, :cavani, :rodriguez
  elsif match.time < 20 && match.me.winning?
    # Mirror opponent players

    opponent = match.other.positions
    my_players = players

    opponent.each_with_index do |(opponent_name, opponent_pos), index|
      formation.lineup do
        custom_position do
          player my_players[index].name
          position opponent_pos.x, 100.0 - opponent_pos.y
        end
      end
    end
  else
    formation.lineup do
      if match.ball.x < 50
        lines do
          defenders 10
          midfielders 30
          attackers 50
        end
      else
        lines do
          defenders 30
          midfielders 50
          attackers 70
        end
      end

      defenders :pereira, :cacerez, :gimenez, :godin, :rodriguez
      midfielders :lodeiro, :none, :rolan, :none, :arevalo
      attackers :none, :cavani, :none, :suarez, :none
    end
  end

  formation
end