Git Product home page Git Product logo

tankinho's Introduction

Tankinho

A sample UDP client for playing rrobots. You can see a demo of the game here.

Getting Started

If you are playing the game on your own you will first need to get a server started. If you are playing in a group you just need to get the address of the server.

Now you can clone this repo and run it as an example like this:

$ git clone https://github.com/mmmries/tankinho.git
$ cd tankinho
$ mix do deps.get, compile
$ mix run client.exs --server 192.168.2.10:5566 --name Michael

Just replace the server address and name above with the address where the server is running and the name you want your tank to have in the game.

Customizing Your Tank

The default tank implementation is in MyTank.ex. Open that file and you can see a template. The basic idea is that you have a module with two functions:

  • init/1 function which is called when you join a game
  • tick/2 function which is called once on each tick of a game

Init Function

The init function receives a single argument like:

%{
 width:  800, #the height of the game in pixels
 height: 600, #the width of the game in pixels
 size:   60,  #the height/width of your robot in pixels
}

This function will return a state term of anything you want to keep track of for the game. This same state will be passed to your tick function on the first tick of the game.

Tick Function

The tick function is called 60 times per second (once for each frame of the game) and receives two arguments. The first argument is the game state from the server (see details below). The second argument is the current state of your tank.

The tick function is where your tank decides to take actions like turning, driving and shooting. Each time your function is called it must return a tuple of: {actions, new_state}, and the new_state will be passed as the second argument the next time your tick function is called.

The actions you want to take is a %Tankinho.Actions{} struct. You can take actions like this: %Actions{} |> Actions.fire(1) |> Actions.accelerate(2.0). For a full list of actions you can take, please see the Actions module.

The Game State

The game state from the server provides information about where the tank is, how much energy it has, and other details about the game board. Here is an example of what the data looks like.

%{
 "energy" =>        100,
 "gun_heading" =>   242.0,
 "heading" =>       242.0
 "radar_heading" => 242.0,
 "time" =>          416,
 "speed" =>         0,
 "x" =>             1764.0,
 "y" =>             60.0,
 "robots_scanned":  [1020.65],
 "broadcasts":      [["hi", "west"]],
}

tankinho's People

Contributors

mmmries avatar

Stargazers

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