Coder Social home page Coder Social logo

rschaden / rtanque Goto Github PK

View Code? Open in Web Editor NEW

This project forked from awilliams/rtanque

0.0 1.0 0.0 1.89 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

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.

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 and screenshot of the game: Battle

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.0.0 or 1.9.3 (tested on 1.8.7 and 1.9.2)

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

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> ...

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 tandibar avatar iangreenleaf avatar

Watchers

 avatar

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.