rtanque 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2710b201f052939f4fdf9e2816050597b26e948e
4
- data.tar.gz: 8273925c71ec90ecce35e5c8041674fe300dfeb7
3
+ metadata.gz: f5f4b4408532ba416d2572aac6a6173f412fd99a
4
+ data.tar.gz: 1d4995cb500186090ceb317fac267fb65ea21a3b
5
5
  SHA512:
6
- metadata.gz: 38ccf85cf7d8c1a36d9ede963892303865b611db05111e283d8baccdc27f3b86db48b384a6e5dd5535cb88aef076c27f60f0eb7646c7eefd7acc73f4b08d3752
7
- data.tar.gz: be0f95f95194b3e72f0574478869a756615aafbaa0b10772e588eee2aee5e2c37495f53524e3883f5b6a97288d2873fb5a5aa19cc127be1f33dc067ed0c855b7
6
+ metadata.gz: 1461a7bc912bc9eb9546042d6972695d27a1339639c5a6859c05b2799cf229f00fd4987042d750d4d7ba68bf067cd5ab5a551795a1b65c70058e89b0a8cf5689
7
+ data.tar.gz: 4787e52d89f835655e7ef722d628554bc9bf9371dd4a75e7235cd219d60f72c4b5dd3dc45f871c0372e72a65e57146499684511dac70f39cbbe8944c7c6b2c73
data/README.md CHANGED
@@ -50,6 +50,36 @@ Make a project directory, init bundler, add the RTanque gem, and create a bot:
50
50
  * [RTanque::Heading](http://rubydoc.info/github/awilliams/RTanque/master/frames/RTanque/Heading)
51
51
  * [RTanque::Point](http://rubydoc.info/github/awilliams/RTanque/master/frames/RTanque/Point)
52
52
 
53
+ ## Advanced Options
54
+
55
+ Set arena dimensions
56
+
57
+ $ bundle exec rtanque start --width=400 --height=400 sample_bots/camper:x4
58
+
59
+ Adjust max ticks allowed
60
+
61
+ $ bundle exec rtanque start --max_ticks=500 sample_bots/camper:x4
62
+
63
+ Run headless match (no gui)
64
+
65
+ $ bundle exec rtanque start --gui=false sample_bots/camper:x4
66
+
67
+ Run team match (teams are currently determined by bot name. Bots with same name are on the same team. The match finished if alive bots have the same name.) https://github.com/awilliams/RTanque/pull/10
68
+
69
+ $ bundle exec rtanque start --teams sample_bots/camper:x4 sample_bots/seek_and_destroy.rb:4
70
+
71
+ Quiet mode (less console chatter).
72
+
73
+ $ bundle exec rtanque start --quiet sample_bots/camper:x4
74
+
75
+ Set random number seed, allowing same battle to be repeated. https://github.com/awilliams/RTanque/pull/7
76
+
77
+ $ bundle exec rtanque start --seed 1234 sample_bots/camper:x4
78
+
79
+ **Experimental** Disable garbage collection during match
80
+
81
+ $ bundle exec rtanque start --gc=false sample_bots/camper:x4
82
+
53
83
  ## Sharing
54
84
  At some point you'll want to compete against other bots, or maybe you'll even organize a small tournament. Sharing bots is easy.
55
85
 
data/bin/rtanque CHANGED
@@ -23,13 +23,14 @@ LONGDESC
23
23
  method_option :width, :aliases => '-w', :default => 1200, :type => :numeric, :banner => 'width of window'
24
24
  method_option :height, :aliases => '-h', :default => 700, :type => :numeric, :banner => 'height of window'
25
25
  method_option :max_ticks, :aliases => '-m', :default => Float::INFINITY, :type => :numeric, :banner => 'max ticks allowed per match'
26
+ method_option :teams, :default => false, :type => :boolean, :banner => 'true to do a team based match based on tank names'
26
27
  method_option :gui, :default => true, :type => :boolean, :banner => 'false to run headless'
27
28
  method_option :gc, :default => true, :type => :boolean, :banner => 'disable GC (EXPERIMENTAL)'
28
29
  method_option :quiet, :aliases => '-q', :default => false, :type => :boolean, :banner => 'disable chatter'
29
30
  method_option :seed, :default => Kernel.srand, :type => :numeric, :banner => 'random number seed value'
30
31
  def start(*brain_paths)
31
32
  Kernel.srand(options[:seed])
32
- runner = RTanque::Runner.new(options[:width], options[:height], options[:max_ticks])
33
+ runner = RTanque::Runner.new(options[:width], options[:height], options[:max_ticks], options[:teams])
33
34
  brain_paths.each { |brain_path|
34
35
  begin
35
36
  runner.add_brain_path(brain_path)
@@ -6,6 +6,7 @@ module RTanque
6
6
  # @!visibility private
7
7
  Configuration = ::Configuration.for('default') do
8
8
  raise_brain_tick_errors true
9
+ quit_when_finished true
9
10
 
10
11
  bot do
11
12
  radius 19
@@ -43,4 +44,4 @@ module RTanque
43
44
  def Configuration.config(&block)
44
45
  ::Configuration::DSL.evaluate(self, &block)
45
46
  end
46
- end
47
+ end
@@ -36,6 +36,7 @@ module RTanque
36
36
  self.close if button_down?(Gosu::Button::KbEscape)
37
37
  @background.draw(0, 0, ZOrder::BACKGROUND)
38
38
  if @match.finished?
39
+ self.close if Configuration.quit_when_finished
39
40
  self.gui_bots.each { |bot| bot.grow(2) }
40
41
  end
41
42
  self.draw_drawables
@@ -78,7 +78,7 @@ module RTanque
78
78
  def delta(to)
79
79
  diff = (to.to_f - self.to_f).abs % FULL_ANGLE
80
80
  diff = -(FULL_ANGLE - diff) if diff > Math::PI
81
- to < self ? -diff : diff
81
+ to.to_f < self.to_f ? -diff : diff
82
82
  end
83
83
 
84
84
  # @return [RTanque::Heading]
@@ -159,4 +159,4 @@ module RTanque
159
159
  @memoized[:to_degrees] ||= (self.radians * 180.0) / Math::PI
160
160
  end
161
161
  end
162
- end
162
+ end
@@ -14,7 +14,7 @@ module RTanque
14
14
  end
15
15
 
16
16
  def all_but(*to_exclude)
17
- self.reject { |member| to_exclude.include?(member) }
17
+ self.to_a - to_exclude
18
18
  end
19
19
 
20
20
  def delete_if(&block)
@@ -47,4 +47,4 @@ module RTanque
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
data/lib/rtanque/match.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module RTanque
2
2
  class Match
3
- attr_reader :arena, :bots, :shells, :explosions, :ticks, :max_ticks
3
+ attr_reader :arena, :bots, :shells, :explosions, :ticks, :max_ticks, :teams
4
4
 
5
- def initialize(arena, max_ticks = nil)
5
+ def initialize(arena, max_ticks = nil, teams = false)
6
6
  @arena = arena
7
7
  @max_ticks = max_ticks
8
+ @teams = teams
8
9
  @ticks = 0
9
10
  @shells = TickGroup.new
10
11
  @bots = TickGroup.new
@@ -20,7 +21,8 @@ module RTanque
20
21
  end
21
22
 
22
23
  def finished?
23
- @stopped || self.max_ticks_reached? || self.bots.count <= 1
24
+ @stopped || self.max_ticks_reached? || self.bots.count <= 1 ||
25
+ (self.teams && self.bots.map(&:name).uniq.size == 1)
24
26
  end
25
27
 
26
28
  def add_bots(*bots)
@@ -64,4 +66,4 @@ module RTanque
64
66
  @ticks += 1
65
67
  end
66
68
  end
67
- end
69
+ end
data/lib/rtanque/shell.rb CHANGED
@@ -5,13 +5,17 @@ module RTanque
5
5
  SHELL_SPEED_FACTOR = Configuration.shell.speed_factor
6
6
  attr_reader :bot, :arena, :fire_power
7
7
 
8
+ def self.speed fire_power
9
+ fire_power * SHELL_SPEED_FACTOR
10
+ end
11
+
8
12
  def initialize(bot, position, heading, fire_power)
9
13
  @bot = bot
10
14
  @arena = bot.arena
11
15
  @fire_power = fire_power
12
16
  self.position = position
13
17
  self.heading = heading
14
- self.speed = (fire_power * SHELL_SPEED_FACTOR) # TODO: add bot's relative speed in this heading
18
+ self.speed = self.class.speed(fire_power) # TODO: add bot's relative speed in this heading
15
19
  @dead = false
16
20
  end
17
21
 
@@ -37,4 +41,4 @@ module RTanque
37
41
  end
38
42
  end
39
43
  end
40
- end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module RTanque
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -8,6 +8,8 @@ class SeekAndDestroy < RTanque::Bot::Brain
8
8
  TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0
9
9
 
10
10
  def tick!
11
+ @desired_heading ||= nil
12
+
11
13
  if (lock = self.get_radar_lock)
12
14
  self.destroy_lock(lock)
13
15
  @desired_heading = nil
@@ -48,4 +50,4 @@ class SeekAndDestroy < RTanque::Bot::Brain
48
50
  @locked_on = lock.name if lock
49
51
  lock
50
52
  end
51
- end
53
+ end
@@ -21,9 +21,18 @@ describe RTanque::Match do
21
21
  end
22
22
 
23
23
  it 'should be false if two or more bots left' do
24
- @instance.add_bots(:bot, :bot2)
24
+ bot1 = double('bot', :name => "bot1")
25
+ bot2 = double('bot', :name => "bot2")
26
+ @instance.add_bots(bot1, bot2)
25
27
  expect(@instance.finished?).to be_false
26
28
  end
29
+
30
+ it 'should be true if two or more bots left w/ same name' do
31
+ bot1 = double('bot', :name => "bot1")
32
+ bot2 = double('bot', :name => "bot1")
33
+ @instance.add_bots(bot1, bot2)
34
+ expect(@instance.finished?).to be_true
35
+ end
27
36
  end
28
37
 
29
38
  describe '#tick' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtanque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  version: '0'
286
286
  requirements: []
287
287
  rubyforge_project:
288
- rubygems_version: 2.0.3
288
+ rubygems_version: 2.0.0
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: RTanque is a game for programmers. Players program the brain of a tank and
@@ -300,3 +300,4 @@ test_files:
300
300
  - spec/rtanque/shell_spec.rb
301
301
  - spec/rtanque_spec.rb
302
302
  - spec/spec_helper.rb
303
+ has_rdoc: