Module: RTanque

Defined in:
lib/rtanque.rb,
lib/rtanque/gui.rb,
lib/rtanque/bot.rb,
lib/rtanque/shell.rb,
lib/rtanque/match.rb,
lib/rtanque/point.rb,
lib/rtanque/arena.rb,
lib/rtanque/runner.rb,
lib/rtanque/movable.rb,
lib/rtanque/version.rb,
lib/rtanque/heading.rb,
lib/rtanque/gui/bot.rb,
lib/rtanque/bot/radar.rb,
lib/rtanque/bot/brain.rb,
lib/rtanque/gui/shell.rb,
lib/rtanque/explosion.rb,
lib/rtanque/bot/turret.rb,
lib/rtanque/gui/window.rb,
lib/rtanque/bot/sensors.rb,
lib/rtanque/bot/command.rb,
lib/rtanque/configuration.rb,
lib/rtanque/gui/explosion.rb,
lib/rtanque/gui/draw_group.rb,
lib/rtanque/normalized_attr.rb,
lib/rtanque/bot/brain_helper.rb,
lib/rtanque/match/tick_group.rb,
lib/rtanque/gui/bot/health_color_calculator.rb

Overview

RTanque

Interesting classes for the spelunker:

Defined Under Namespace

Modules: Gui, Movable, NormalizedAttr Classes: Arena, Bot, Explosion, Heading, Match, Point, Runner, Shell

Constant Summary

VERSION =
'0.1.2'

Instance Method Summary (collapse)

Instance Method Details

- (Float) distance(other_point)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (RTanque::Heading) heading(other_point)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (Boolean) on_bottom_wall?



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (Boolean) on_left_wall?



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (Boolean) on_right_wall?



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (Boolean) on_top_wall?



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end

- (Boolean) on_wall?

True if on any wall



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rtanque/point.rb', line 65

Point = Struct.new(:x, :y, :arena) do
  def initialize(*args, &block)
    super
    block.call(self) if block
    self.freeze
  end

  def self.rand(arena)
    self.new(Kernel.rand(arena.width), Kernel.rand(arena.height), arena)
  end

  def self.distance(a, b)
    Math.hypot(a.x - b.x, a.y - b.y)
  end

  def ==(other_point)
    self.x == other_point.x && self.y == other_point.y
  end

  def within_radius?(other_point, radius)
    self.distance(other_point) <= radius
  end

  def on_top_wall?
    self.y >= self.arena.height
  end

  def on_bottom_wall?
    self.y <= 0
  end

  def on_left_wall?
    self.x <= 0
  end

  def on_right_wall?
    self.x >= self.arena.width
  end

  def on_wall?
    self.on_top_wall? || self.on_bottom_wall? || self.on_right_wall? || self.on_left_wall?
  end

  def outside_arena?
    self.y > self.arena.height || self.y < 0 || self.x > self.arena.width || self.x < 0
  end

  def move(heading, speed, bound_to_arena = true)
    # round to avoid floating point errors
    x = (self.x + (Math.sin(heading) * speed)).round(10)
    y = (self.y + (Math.cos(heading) * speed)).round(10)
    self.class.new(x, y, self.arena) { |point| point.bind_to_arena if bound_to_arena }
  end

  def bind_to_arena
    if self.x < 0
      self.x = 0.0
    elsif self.x > self.arena.width
      self.x = self.arena.width.to_f
    end
    if self.y < 0
      self.y = 0.0
    elsif self.y > self.arena.height
      self.y = self.arena.height.to_f
    end
  end

  def heading(other_point)
    Heading.new_between_points(self, other_point)
  end

  def distance(other_point)
    self.class.distance(self, other_point)
  end
end