Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cooperative match and other fixes #10

Merged
merged 6 commits into from

2 participants

@zenspider

Here are a bunch of changes that we sorta discussed. Along with cooperative matches are the ability to have the GUI shut down after it is finished (so a tournament driver script can run through a bunch of matches), some fixes, refactorings... etc.

The debugging visualization stuff will come in a different PR. These changes here are more important IMO.

@awilliams awilliams merged commit 9099bea into awilliams:master
@awilliams
Owner

I've added co-op/team mode as a command line option, deactivated by default. It's off by default since it's unexpected for a match to end suddenly when the remaining bots have the same name (something that happened to me when testing).

967b6b6

Thanks for the upgrade!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2013
  1. @zenspider

    Added the ability for the match to be finished if all bots left have

    zenspider authored
    the same name. Should probably have some configuration and/or cmdline
    options as well but that was beyond me.
  2. @zenspider
  3. @zenspider
  4. @zenspider

    Fix for odd errors I was getting. Heading#delta's to was sometimes not

    zenspider authored
    a float. Dunno why. Couldn't properly track it back because of randomness.
  5. @zenspider

    Simple refactoring to make shell speed calculations reusable by bot

    zenspider authored
    brains. Important for target prediction.
  6. @zenspider

    Added quit_when_finished configuration and made window close itself if

    zenspider authored
    the game is finished. Important for automated tournaments.
This page is out of date. Refresh to see the latest.
View
3  lib/rtanque/configuration.rb
@@ -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
@@ -43,4 +44,4 @@ module RTanque
def Configuration.config(&block)
::Configuration::DSL.evaluate(self, &block)
end
-end
+end
View
1  lib/rtanque/gui/window.rb
@@ -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
View
4 lib/rtanque/heading.rb
@@ -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]
@@ -159,4 +159,4 @@ def to_degrees
@memoized[:to_degrees] ||= (self.radians * 180.0) / Math::PI
end
end
-end
+end
View
5 lib/rtanque/match.rb
@@ -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)
@@ -64,4 +65,4 @@ def tick
@ticks += 1
end
end
-end
+end
View
4 lib/rtanque/match/tick_group.rb
@@ -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)
@@ -47,4 +47,4 @@ def tick
end
end
end
-end
+end
View
8 lib/rtanque/shell.rb
@@ -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
@@ -37,4 +41,4 @@ def hits(bots, &on_hit)
end
end
end
-end
+end
View
4 sample_bots/seek_and_destroy.rb
@@ -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
@@ -48,4 +50,4 @@ def get_radar_lock
@locked_on = lock.name if lock
lock
end
-end
+end
View
11 spec/rtanque/match_spec.rb
@@ -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
Something went wrong with that request. Please try again.