Giter Site home page Giter Site logo

awilliams / rtanque Goto Github PK

View Code? Open in Web Editor NEW
301.0 13.0 89.0 1.87 MB

RTanque is a game for (Ruby) programmers. Players program the brain of a tank and then send their tank+brain into battle against other tanks.

Home Page: http://awilliams.github.com/RTanque/

License: MIT License

Ruby 99.30% HTML 0.70%
rtanque ruby

rtanque's Introduction

RTanque Build Status CodeClimate

What is this? RTanque is a game for ( Ruby ) programmers. Players program the brain of a tank and then send their tank+brain into battle with other tanks. All tanks are otherwise equal.

Getting started guide

Rules of the game are simple: Last bot standing wins. Gameplay is also pretty simple. Each tank has a base, turret and radar, each of which rotate independently. The base moves the tank, the turret has a gun mounted to it which can fire at other tanks, and the radar detects other tanks in its field of vision.

Have fun competing against friends' tanks or the sample ones included. Maybe you'll start a small league at your local Ruby meetup. CLI provides easy way to download bots from gists.

Sound difficult or time consuming? It's not! Check out the included sample tank Seek&Destroy (which is actually fairly difficult to beat with the keyboard controlled bot). Note that it clocks in at under 50 LOC.

This is not an original idea, see influences. There's a lot of resources out there around tank design and tactics that could be applied to RTanque.

How does it look? Here's a video of a battle:

RTanque Demo

Influences

RTanque is based on the Java project Robocode and inspired by other Ruby ports. Thanks and credit go to them both.

Requirements

  • The Gosu library used for rendering has some dependencies. Use the Gosu getting started to resolve any for your system.
  • Ruby 2.2 or later (also tested on earlier versions)

Quick Start

Make a project directory, init bundler, add the RTanque gem, and create a bot:

$ mkdir RTanque; cd RTanque
$ bundle init
$ echo "gem 'rtanque'" >> Gemfile
$ bundle
$ bundle exec rtanque new_bot my_deadly_bot
$ bundle exec rtanque start bots/my_deadly_bot sample_bots/keyboard sample_bots/camper:x2

Drive the Keyboard bot with asdf. Aim/fire with the arrow keys

Advanced Options

Set arena dimensions

$ bundle exec rtanque start --width=400 --height=400 sample_bots/camper:x4

Adjust max ticks allowed

$ bundle exec rtanque start --max_ticks=500 sample_bots/camper:x4

Run headless match (no gui)

$ bundle exec rtanque start --gui=false sample_bots/camper:x4

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.) #10

$ bundle exec rtanque start --teams sample_bots/camper:x4 sample_bots/seek_and_destroy.rb:4

Quiet mode (less console chatter).

$ bundle exec rtanque start --quiet sample_bots/camper:x4

Set random number seed, allowing same battle to be repeated. #7

$ bundle exec rtanque start --seed 1234 sample_bots/camper:x4

Experimental Disable garbage collection during match

$ bundle exec rtanque start --gc=false sample_bots/camper:x4

Sharing

At some point you'll want to compete against other bots, or maybe you'll even organize a small tournament. Sharing bots is easy.

Ask your friends to upload their bot(s) in a gist, which you can then download with the following command:

bundle exec rtanque get_gist <gist_id> ...

For example, to download Marksman

bundle exec rtanque get_gist 5909793

If you'd like to publicly share your bot, post its gist id on the wiki https://github.com/awilliams/RTanque/wiki/bot-gists

Bot API

The tank api consists of reading input from Brain#sensors and giving output to Brain#command

Brain#sensors

class Bot < RTanque::Bot::Brain
  # RTanque::Bot::Sensors =
  #  Struct.new(:ticks, :health, :speed, :position, :heading, :radar, :turret)
  def tick!
    sensors.ticks # Integer
    sensors.health # Float
    sensors.position # RTanque::Point
    sensors.heading # RTanque::Heading
    sensors.speed # Float
    sensors.radar_heading # RTanque::Heading
    sensors.turret_heading # RTanque::Heading
    sensors.radar.each do |scanned_bot|
      # scanned_bot: RTanque::Bot::Radar::Reflection
      # Reflection(:heading, :distance, :name)
    end
  end
end

Brain#command

class Bot < RTanque::Bot::Brain
  # RTanque::Bot::Command =
  #  Struct.new(:speed, :heading, :radar_heading, :turret_heading, :fire_power)
  def tick!
    command.speed = 1
    command.heading = Math::PI / 2.0
    command.radar_heading = Math::PI
    command.turret_heading = Math::PI
    command.fire(3)
  end
end

RTanque::Heading This class handles angles. It is a wrapper around Float bound to (0..Math::PI*2)

RTanque::Heading.new(Math::PI)
=> <RTanque::Heading: 3.141592653589793rad 180.0deg>

RTanque::Heading.new_from_degrees(180)
=> <RTanque::Heading: 3.141592653589793rad 180.0deg>

RTanque::Heading.new_from_degrees(180) + RTanque::Heading.new(Math::PI)
=> <RTanque::Heading: 0.0rad 0.0deg>

RTanque::Heading.new(Math::PI) + (Math::PI / 2.0)
=> <RTanque::Heading: 4.71238898038469rad 270.0deg>

RTanque::Heading.new == 0
=> true

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rtanque's People

Contributors

awilliams avatar iangreenleaf avatar jrmhaig avatar tandibar avatar zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtanque's Issues

Differently colored bots?

It would be cool if there were multiple robot graphics, so that each unique bot class could possibly be given a unique color to distinguish it.

Perhaps with the use of Texplay, some sort of generic plain white "template bot" could be used and colored in with a random color?

more bots?

nice game. thank you!

there is the load bot from gist feature - but where do i find bot gists?

Error with `bundle install`. gosu 0.8.5 doesn't work with RTanque?

Hello there.

I'm on ubuntu 14.04 64 bits.

I've just cloned the git repository and install gosu on my system. Afterwards I've tried to do bundle install but I got this error:
An error occurred while installing gosu (0.7.50), and Bundler cannot continue.
Make sure that gem install gosu -v '0.7.50' succeeds before bundling.
so then, I did: sudo gem install gosu which installed gosu 0.8.5; now, I've retried to do the bundle install and I got the same error.
does RTanque not work with gosu 0.8.5?
I also have tried to do sudo gem install gosu -v '0.7.50' but it doesn't compile because it has problems finding sdl ttf fonts (which, btw, I don't understand since libsdl2-ttf-dev is correctly installed.

Recording game play?

Haven't had a chance to look at the documentation, but how hard would it be to record a game? I imagine it would be a matter of storing the initial positions, the current random seed, and the series of Commands issued, then just animating that.

Reflecting tanks' gun energy?

I've noticed most Robocode-like games allow the radar to detect the other tanks' energy. This allows lots of tactics, such as:

  • Detecting shots from other tanks, by checking the "energy drop".
    • Notice that the actual projectile target is unknown, and fire-power has to be derived from the energy difference.
  • Prioritize evasive angles from tanks with high energy levels.
  • Tracking virtual projectile positions or trajectories to refine the movement path ("wave surfing", quite competitive on one-vs-one).

I admit some of them a quite advanced, but provides a way to make more reactive movement patterns, more interesting matches and makes it more difficult to have a "finished" bot, since there is much more room for improving and researching.

As a downside, more possible tactics means more bots taking more memory and/or computing resources; that could become a security problem, but that should probably go on another issue.

sensors.button_down? in headless run throws uninitialized constant RTanque::Bot::Gosu

bundle exec rtanque start --gui false bots/ronald.5146511/rort4 bots/ronald.5146511/rort3
[..]
Bots ["Rort4", "Rort3"]
../lib/ruby/gems/1.9.1/bundler/gems/RTanque-1f114560d7cd/lib/rtanque/bot/sensors.rb:24:in `button_down?': uninitialized constant RTanque::Bot::Gosu (NameError)

What is a good solution?

a) not use button_down? unless needed (keyboard bot)
b) should my bot brain handle this?
c) should "button_down?" handle this and return false in headless mode?

Need help understanding shells position & heading

I've been having a blast playing with rtanque but I'm having some problems understanding how to work out some of my math for this. In particular, it seems like the shells aren't behaving like I'd expect.

I added an extra concept to rtanque that allows me to register additional lambdas to draw debugging information on the screen. With that, I drew a white line for heading, green lines for the radar (with spread), a yellow line for the current turret heading and a red line for the turret command heading. It works great and helps a ton... but...

It looks like the shells aren't doing the right thing. They start at the end of the turret and have the heading of the turret. I know it is in some sort of post_tick phase, and it is using "real" bot info instead of what my sensors give me so that might account for it. I dunno. I'm confused (it is 2am here so that isn't helping). Take a look to see what I mean:

http://www.zenspider.com/~ryan/rtanque_visualization.mov

What am I not getting?

Gosu Dependency qoefully out of date

The Gosu library has been updated to 1.4.3, but RTanque relies on 0.13.1 which will not install on a modern version of OSX. I'd love to get this working, as I used to use RTanque to teach beginning rubyists, and I'd like to do it again.

not balanced?

Hello,

I am doing some big stats fights with bots and the results are better depending the order of the command of execution of bots. The more bots included, the more difference on it.

So, If we initialize 2 bots that are the same I am having a 45% for the first in the command and 55% for the second in many cases.

But if we include many different bots , for stats of 1000 battles, where I think the results should be simmilar, they changes depending the order of execution.

per example:
do bundle exec bin/rtanque start --gui=false --max_ticks=100000 bots/tank_1.rb bots/tank_2.rb bots/tank_3.rb bots/tank_4.rb

here tank_4 will get good results even with a weaker code.
and the same tanks here:
do bundle exec bin/rtanque start --gui=false --max_ticks=100000 bots/tank_3.rb bots/tank_4.rb bots/tank_1.rb bots/tank_2.rb
Will give better results for tank_2, and good for tank_1 and the worst for tank_3

my stats are battles from 500 to 1500

I want to know what do you think about this, I have reviewed my stats script many times and I think it is ok (but I might be wrong, of course)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.