Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cooperative match and other fixes #10

Merged
merged 6 commits into from May 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rtanque/configuration.rb
Expand Up @@ -6,6 +6,7 @@ module RTanque
# @!visibility private
Configuration = ::Configuration.for('default') do
raise_brain_tick_errors true
quit_when_finished true

bot do
radius 19
Expand Down Expand Up @@ -43,4 +44,4 @@ module RTanque
def Configuration.config(&block)
::Configuration::DSL.evaluate(self, &block)
end
end
end
1 change: 1 addition & 0 deletions lib/rtanque/gui/window.rb
Expand Up @@ -36,6 +36,7 @@ def draw
self.close if button_down?(Gosu::Button::KbEscape)
@background.draw(0, 0, ZOrder::BACKGROUND)
if @match.finished?
self.close if Configuration.quit_when_finished
self.gui_bots.each { |bot| bot.grow(2) }
end
self.draw_drawables
Expand Down
4 changes: 2 additions & 2 deletions lib/rtanque/heading.rb
Expand Up @@ -78,7 +78,7 @@ def initialize(radians = NORTH)
def delta(to)
diff = (to.to_f - self.to_f).abs % FULL_ANGLE
diff = -(FULL_ANGLE - diff) if diff > Math::PI
to < self ? -diff : diff
to.to_f < self.to_f ? -diff : diff
end

# @return [RTanque::Heading]
Expand Down Expand Up @@ -159,4 +159,4 @@ def to_degrees
@memoized[:to_degrees] ||= (self.radians * 180.0) / Math::PI
end
end
end
end
5 changes: 3 additions & 2 deletions lib/rtanque/match.rb
Expand Up @@ -20,7 +20,8 @@ def max_ticks_reached?
end

def finished?
@stopped || self.max_ticks_reached? || self.bots.count <= 1
@stopped || self.max_ticks_reached? || self.bots.count <= 1 ||
self.bots.map(&:name).uniq.size == 1
end

def add_bots(*bots)
Expand Down Expand Up @@ -64,4 +65,4 @@ def tick
@ticks += 1
end
end
end
end
4 changes: 2 additions & 2 deletions lib/rtanque/match/tick_group.rb
Expand Up @@ -14,7 +14,7 @@ def each(&block)
end

def all_but(*to_exclude)
self.reject { |member| to_exclude.include?(member) }
self.to_a - to_exclude
end

def delete_if(&block)
Expand Down Expand Up @@ -47,4 +47,4 @@ def tick
end
end
end
end
end
8 changes: 6 additions & 2 deletions lib/rtanque/shell.rb
Expand Up @@ -5,13 +5,17 @@ class Shell
SHELL_SPEED_FACTOR = Configuration.shell.speed_factor
attr_reader :bot, :arena, :fire_power

def self.speed fire_power
fire_power * SHELL_SPEED_FACTOR
end

def initialize(bot, position, heading, fire_power)
@bot = bot
@arena = bot.arena
@fire_power = fire_power
self.position = position
self.heading = heading
self.speed = (fire_power * SHELL_SPEED_FACTOR) # TODO: add bot's relative speed in this heading
self.speed = self.class.speed(fire_power) # TODO: add bot's relative speed in this heading
@dead = false
end

Expand All @@ -37,4 +41,4 @@ def hits(bots, &on_hit)
end
end
end
end
end
4 changes: 3 additions & 1 deletion sample_bots/seek_and_destroy.rb
Expand Up @@ -8,6 +8,8 @@ class SeekAndDestroy < RTanque::Bot::Brain
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0

def tick!
@desired_heading ||= nil

if (lock = self.get_radar_lock)
self.destroy_lock(lock)
@desired_heading = nil
Expand Down Expand Up @@ -48,4 +50,4 @@ def get_radar_lock
@locked_on = lock.name if lock
lock
end
end
end
11 changes: 10 additions & 1 deletion spec/rtanque/match_spec.rb
Expand Up @@ -21,9 +21,18 @@
end

it 'should be false if two or more bots left' do
@instance.add_bots(:bot, :bot2)
bot1 = double('bot', :name => "bot1")
bot2 = double('bot', :name => "bot2")
@instance.add_bots(bot1, bot2)
expect(@instance.finished?).to be_false
end

it 'should be true if two or more bots left w/ same name' do
bot1 = double('bot', :name => "bot1")
bot2 = double('bot', :name => "bot1")
@instance.add_bots(bot1, bot2)
expect(@instance.finished?).to be_true
end
end

describe '#tick' do
Expand Down