A battle ground for pitting your coding wits against others
The idea is simple enough: Code your bot; submit it; and battle it out. But how do we do it exactly? Let's have a look...
The game is powered by the Gosu gaming library. The first thing you'll need to do is install Gosu's C dependencies. You can do this using homebrew via
$ brew install sdl2 libogg libvorbis. After doing that, run
Gosu gives us all the fancy GUI and gaming geometry tools we'll need and its high level API is dead easy. Just extend
super in your
#initialize method, and implement the
#button_down loop. The loop will run every 16.667 milliseconds and allows for silky smoth animation as the screen is updated at 60 fps.
Here's the shell of game that we execute by calling
ruby game.rb from the CLI.
require 'gosu' class Game < Gosu::Window def initialize(x=1200, y=800, resize=false) super ... end def update ... end def draw ... end def button_up(id) ... end def button_down(id) ... end end Game.new.show
Building a Bot
To make a bot, simply extend the
Bot class and implement the required methods.
Think of your bot as a brain. In normal object oriented game code, your bot would be doing most of the work. The Game object would be calling Bot methods and the bot itself would be keeping track of state.
But this is a competitive endeavour and programmers can't be trusted! So rather than allowing your bot to track state and take actions, your bot will signal its intentions to a Proxy which which will query your bot's wants, track state, and enforce the game rules.
Every tick of the game (60 times per second), the proxy will inform your bot about the battlespace by calling
bot.observe. This give your information on your current position, health, heading, and turret heading, for you as well as the other competitors.
So what intentions can your bot signal?
attr_reader :name, :turn, :drive, :aim, :shoot
You set your name as well as your skill matrix in the
#initialize method. The remainder are signalled in the
@turnis a value of +1 to turn clockwise, -1 to turn anti-clockwise, or 0 to maintain direction.
@driveis a value of 1 to move forward or 0 to maintain position.
@aimis a value of +1 to -1 to turn the turret clockwise or anti-clockwise.
@shootis a value of true or false to fire your weapons.
The specifics of how you implement
#think is entirely up to you. I've included three example bots for you to examine and test against.
Your bot also contain a skill set representing relative virtues of
@sight. These virtues must sum to 100 and allow you to enhance some attributes at the expense of others.
@speeddetermines to how fast your bot can move.
@strengthincreases bullet velocity and firepower.
@staminaaids your ability to sustain damage.
@sightimproves your peripheral vision.
The Proxy will check that your virtues sum to 100 and will not allow values above this. The default is 25 each.
Submitting your bot
To submit your bot:
- For this repo and install the Gosu gem and dependencies
- Extend BattleBot::Bot
- Add your bot to players.rb
- Ensure your bot works by running
$ ruby game.rbin terminal
- Create a pull request with your bot's name.
Graphics have been blatantly plagiarised from Adam Williams' rTanque
Sounds by Mike Koenig
Todo before the next meetup
- add autoloader