Class: Rubots::Samples::TargetFinder
- Inherits:
-
Rubots::Strategy
- Object
- Rubots::Strategy
- Rubots::Samples::TargetFinder
- Defined in:
- lib/rubots/samples/target_finder.rb
Overview
Homes into the center of the map, then stays there, points up, and aims down.
Constant Summary collapse
- ANGLE_DOWN =
180- ANGLE_UP =
0- ANGLE_LEFT =
270- ANGLE_RIGHT =
90
Instance Method Summary collapse
- #command(me, targets) ⇒ Object
- #find_x(me) ⇒ Object
- #find_y(me) ⇒ Object
-
#initialize(map, me, targets) ⇒ TargetFinder
constructor
A new instance of TargetFinder.
- #name ⇒ Object
Methods inherited from Rubots::Strategy
Constructor Details
#initialize(map, me, targets) ⇒ TargetFinder
Returns a new instance of TargetFinder.
10 11 12 13 14 15 |
# File 'lib/rubots/samples/target_finder.rb', line 10 def initialize(map, me, targets) @finding = :x @map = map @find_x = map.width / 2 @find_y = map.height / 2 end |
Instance Method Details
#command(me, targets) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubots/samples/target_finder.rb', line 17 def command(me, targets) if @finding == :x find_x(me) elsif @finding == :y find_y(me) elsif me.angle != 0 rotate_to 0 else rotate_gun_to 180 end end |
#find_x(me) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubots/samples/target_finder.rb', line 33 def find_x(me) if me.x > @find_x && me.angle != ANGLE_LEFT rotate_to ANGLE_LEFT elsif me.x < @find_x && me.angle != ANGLE_RIGHT rotate_to ANGLE_RIGHT elsif me.x != @find_x if (@find_x - me.x).abs > 50 throttle 4 else throttle 1 end else # At pos x @finding = :y throttle 0 end end |
#find_y(me) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubots/samples/target_finder.rb', line 50 def find_y(me) if me.y > @find_y && me.angle != ANGLE_UP rotate_to ANGLE_UP elsif me.y < @find_y && me.angle != ANGLE_DOWN rotate_to ANGLE_DOWN elsif me.y != @find_y if (@find_y - me.y).abs > 50 throttle 5 else throttle 1 end else # At pos y @finding = :none throttle 0 end end |
#name ⇒ Object
29 30 31 |
# File 'lib/rubots/samples/target_finder.rb', line 29 def name "GoToCenter" end |