Class: Rubots::Robot
- Inherits:
-
Object
- Object
- Rubots::Robot
- Defined in:
- lib/rubots/robot.rb
Constant Summary collapse
- MAX_ANGLE =
Some constants
360- ANGLE_STEP =
Maximum angle. Wraps around to zero after this.
1- MAX_THROTTLE =
How much we change angle each tick.
10- THROTTLE_STEP =
Max throttle. Can’t go above.
1- SPEED_FACTOR =
How much we change throttle each tick.
1- MAX_GUN_ANGLE =
How much movement does each throttle step represent
360- GUN_ANGLE_STEP =
Maximum gun angle. Wraps around to zero after this.
2
Instance Attribute Summary collapse
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#desired_angle ⇒ Object
writeonly
Sets the attribute desired_angle.
-
#desired_gun_angle ⇒ Object
writeonly
Sets the attribute desired_gun_angle.
-
#desired_throttle ⇒ Object
writeonly
Sets the attribute desired_throttle.
-
#gun_angle ⇒ Object
readonly
Returns the value of attribute gun_angle.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #distance_to(other) ⇒ Object
- #do_fire ⇒ Object
-
#initialize(strategy_class, game, x, y) ⇒ Robot
constructor
A new instance of Robot.
- #name ⇒ Object
- #process_command ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize(strategy_class, game, x, y) ⇒ Robot
Returns a new instance of Robot.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubots/robot.rb', line 21 def initialize(strategy_class, game, x, y) @x = x @y = y @throttle = @desired_throttle = 0.0 @angle = @desired_angle = 0.0 @gun_angle = @desired_gun_angle = 0.0 @game = game @strategy = strategy_class.new(@game.map, robot_data, nil) @destroyed = false @cooldown_timer = 0 end |
Instance Attribute Details
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
5 6 7 |
# File 'lib/rubots/robot.rb', line 5 def angle @angle end |
#desired_angle=(value) ⇒ Object (writeonly)
Sets the attribute desired_angle
6 7 8 |
# File 'lib/rubots/robot.rb', line 6 def desired_angle=(value) @desired_angle = value end |
#desired_gun_angle=(value) ⇒ Object (writeonly)
Sets the attribute desired_gun_angle
6 7 8 |
# File 'lib/rubots/robot.rb', line 6 def desired_gun_angle=(value) @desired_gun_angle = value end |
#desired_throttle=(value) ⇒ Object (writeonly)
Sets the attribute desired_throttle
6 7 8 |
# File 'lib/rubots/robot.rb', line 6 def desired_throttle=(value) @desired_throttle = value end |
#gun_angle ⇒ Object (readonly)
Returns the value of attribute gun_angle.
5 6 7 |
# File 'lib/rubots/robot.rb', line 5 def gun_angle @gun_angle end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
5 6 7 |
# File 'lib/rubots/robot.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
5 6 7 |
# File 'lib/rubots/robot.rb', line 5 def y @y end |
Instance Method Details
#destroy ⇒ Object
72 73 74 75 |
# File 'lib/rubots/robot.rb', line 72 def destroy @throttle = 0 @destroyed = true end |
#destroyed? ⇒ Boolean
77 78 79 |
# File 'lib/rubots/robot.rb', line 77 def destroyed? @destroyed end |
#distance_to(other) ⇒ Object
66 67 68 69 70 |
# File 'lib/rubots/robot.rb', line 66 def distance_to(other) x_dist = @x - other.x y_dist = @y - other.y Math.sqrt(x_dist ** 2 + y_dist ** 2) end |
#do_fire ⇒ Object
62 63 64 |
# File 'lib/rubots/robot.rb', line 62 def do_fire @firing = true end |
#name ⇒ Object
58 59 60 |
# File 'lib/rubots/robot.rb', line 58 def name @strategy.name end |
#process_command ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubots/robot.rb', line 36 def process_command return if @destroyed if @cooldown_timer > 0 @cooldown_timer -= 1 else command = @strategy.get_command(robot_data, targets_data) command.apply_to(self) @cooldown_timer = command.cooldown end end |
#tick ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/rubots/robot.rb', line 48 def tick return if @destroyed tick_angle tick_throttle tick_movement tick_gun tick_fire end |