4.2 KiB
RoboTank
A "game" where two computer controlled tanks fight each other. It's a 2D game, terrible "physics" but well, it runs. This is a work-in-progress, still buggy and subject to change.
How it works
There is a server component that opens a HTTP server on port 3000. If you open localhost:3000 in your browser you get a crude web view to see what is happening. The server provides 2 urls for websockets, /monitor for above UI and /robot for robots.
Robots have to send a few initial messages to the server after connecting:
- name <yourname> This is the name of your robot. Currently not used
- model <model name> This is the type of robot or model you want to use. Currently not used. This can be used to have different tank models (faster, but weaker, different setting for rotation speeds and such)
Message from the server are:
- lost Well, your robot got destroyed and you lost
- ready The server side for your robot is ready and we wait until your opponent is ready as well
- start round stats, you will receive updates now every 50ms.
- won Yeah, your robot did win
- specs {json}
game specifics, containing
- width: playing field with, keep inside or you get damaged
- height: playing field height
When the game is running you will receive status messages every 50ms. Data is a json object containing:
- health: your current health in %
- posX: your x location in the playing field
- posY: your y location in the playing field
- orientation: robot rotation, range 0..360, 0: north, 90: east
- gunOrient: * gun orientation (relative to tank), range 0..360, 0 front, 90 right
- radarPos: radar_position (relative to tank) 0..360, 0 front, 90 right
- contactPoints: a list of contact point from the radar
- dist: distance from robot
- angle: angle from robot view (relative to radar position) chainSpeedLeft: speed of left chain (range -1...1); chainSpeedRight: speed of right chain (range -1 ... 1); simulationTime: current simulation time in seconds causedDamage: positive number if your robot damaged another one
building and running
External dependencies: NodeJS server To build the server, go to the server-nodejs directory and install dependencies:
npm install
to build the server:
npm run build
to start the server:
node ./index.js
Included are basic robots, also written in Typescript. To build, go to the client-nodejs directory, install dependencies
npm install
to (re)build the clients:
npm run build
running with:
node <yourrobot>
included are 3 robots:
- targetpractice a dumb robot that just sits and does nothing, great for target practice
- rabbit a slighly more intelligent robot that drives to a random target position, muches a rabbit (waits 5 seconds) and drives to another target. It uses its radar to scan in front of it, if it detects an enemy, it runs away.
- simplehunter As the name implies, it is a simple hunting robot, that scans the surrounding playing field and if an enemy is detected, it starts to follow and aims the guns to the target. if the right distance is reached, it will fire its cannon.
To start the simulation, you need to have 2 robots connected and waiting. This can be changed in the server index.ts in line 10. Changing it to
worldSim.start(3)
will wait for 3 robots.
You can (and should) create your own bots with as many logic as you seem fit. Use simple state machines, fancy AI, or whatever. If you use typescript, the easiest way to interface the robot is via overloading the RoboBase class, see above robots as examples. You can use any other language and use above websocket messages. Contributions for basic classes in any language welcome.
known issues
- if you change the radar min and max value, sometimes the logic gets confused and it will do a scan the other way doing a full sweep.
- the whole custom robot specs is not yet implemented
- too many magic numbers in the code, most of them should be configurable
- the UI is crude, contributions welcome.
future extensions
The log term goal is to create a platform where you can upload your robot and it will do an automatic fight against other robots and create a leaderboard. Details and rules are open.