GithubHelp home page GithubHelp logo

fruit-game's Introduction

How to write a bot

Bots are written in Javascript. They'll be executed in a sandbox running the SpiderMonkey Javascript engine.

For every turn, our game server will call a function called make_move() in your program. This function can return six different values (defined as global constants):

NORTH
EAST
SOUTH
WEST
TAKE
PASS

This is a very simple, albeit not very smart, robot (a.k.a. known as "EASTBOT"):


function make_move() {
	return EAST;
}

A more fully-fledged example implementation is called random bot and comes with source code.

Bots have a number of functions they can call to enquire the state of the board, the position of the enemy player, the number of fruits left etc.

See the API documentation.

Global state

Global state persists from one call of make_move() to the next, so feel free to keep data around or cache previous results.

Time limit

There's a limit of ten seconds "thinking time" per move. After that, the bot execution is aborted and the other player wins.

Memory limit

The maximum amount of memory you can allocate is 128 Mb.

Errors / Exceptions

The bot also loses if it throws an exeception. You can check the replay logs to see the errors and exceptions that happened while your bot was running.

Standalone bot testing framework

The easiest way to hack a bot is to grab the standalone testing framework. Clone the git repository and then modify mybot.js to start writing your bot. Opening game.html will allow you to watch your bot play on random boards (you can also step through one move at a time.) It also comes with an easy opponent (if you're not ready to face an opponent yet, uncomment the "return PASS" line in assets/simplebot.js.)

Sandbox

Notice that official matches run on our servers work differently than the ones in the testing framework: On our servers every bot will run in its own sandboxed environment, with no access to anything except its own state and the game state- in particular, it won't have access to the opponents code or variables. So don't try anything sneaky :)

Rules

Two robots start in an x by y board. There are a number of different fruits lying around on the board (apples, bananas, etc.) There will be a different number of fruits for each item, so for example, there might be one apple, three melons and seven bananas.

Your goal is to collect fruits so that at the end, you have more fruits than your opponent in as many categories as possible.

So if this is the initial count:

apples		bananas		oranges
1		3		7

And after the game, you have this:

apples		bananas		melons
0		2		4

Then your opponent would have this:

apples		bananas		melons
1		1		3

Hence you will have won the game! (Your opponent has both less bananas as well as less melons than you- so you win in two out of three categories, and hence in total.)

Every turn, each player gets to either move to a vertically or horizontally adjacent square (north, east, south or west) or pick up the fruit they're standing on. Moves are made simultaneously.

Both players tell the game server where they want to move, and then both moves are made at the same time. If both bots are standing on the same fruit and both choose to pick it up, each player gets half a point (0.5). (Notice that this is, from a game-theoretic standpoint of view, equivalent to the fruit being destroyed on simultaneous pick-up)

The game ends if any of these conditions are met:

  • all the fruits have been taken
  • the game server has determined that given the state of the game, there's a clear winner (one player has more than half the fruits of more than half of the categories)
  • game positions keep repeating (meaning that both bots are either passing or going in circles)
  • one player exceeded his thinking time (a bot's make_move() function didn't return within 10 seconds)
  • A bot's make_move() function returned a value that's not a valid move

Fine with the rules? Learn how to write a bot!

fruit-game's People

Contributors

arkahnx avatar cmaster118 avatar

Stargazers

 avatar

Watchers

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