Coder Social home page Coder Social logo

battlehack20's Introduction

Read more about Battlehack 2020 at https://bh2020.battlecode.org!

Installation

To install the engine as a local package, open your terminal and run

pip install --user --upgrade battlehack20

(Depending on how your pip is set up, you may need to replace pip with pip3.)

Running

Run a game! Use:

python3 run.py examplefuncsplayer examplefuncsplayer

You should see a game between examplefuncsplayer and examplefuncsplayer being played.

If you're on Windows and you get incomprehensible output, try instead:

python3 run.py examplefuncsplayer examplefuncsplayer --raw-text

If your code is in a directory ~/yourcode/coolplayer then you can run it against examplefuncsplayer using

python3 run.py examplefuncsplayer ~/yourcode/coolplayer

Running Interactively

Run

python3 -i run.py examplefuncsplayer examplefuncsplayer

This will open an interactive Python shell. There, you can run

step()

which advances the game 1 turn. This is very useful for debugging.

More options

Run

python3 run.py -h

to list all possible options for running.

For example, turning off debug mode, which is on by default, can be helpful:

python3 run.py examplefuncsplayer --debug false

Advanced usage

Interacting directly with the battlehack20 API will give you more freedom and might make it easier to debug your code. The following is a minimal example of how to do that.

$ python3
>>> import battlehack20
>>> code = battlehack20.CodeContainer.from_directory('./examplefuncsplayer')
>>> game = battlehack20.Game([code, code], debug=True)
>>> game.turn()

You should see the output:

[Game info] Turn 1
[Game info] Queue: {}
[Game info] Lords: [<ROBOT WHITE HQ WHITE>, <ROBOT BLACK HQ BLACK>]
[Robot WHITE HQ log] Starting Turn!
[Robot WHITE HQ log] Team: Team.WHITE
[Robot WHITE HQ log] Type: RobotType.OVERLORD
[Robot WHITE HQ log] Spawned unit at: (0, 11)
[Robot WHITE HQ log] Done! Bytecode left: 19928
[Robot BLACK HQ log] Starting Turn!
[Robot BLACK HQ log] Team: Team.BLACK
[Robot BLACK HQ log] Type: RobotType.OVERLORD
[Robot BLACK HQ log] Spawned unit at: (15, 5)
[Robot BLACK HQ log] Done! Bytecode left: 19927

If you're curious, this is how the run.py script works. Study the source code of run.py to figure out how to set up a viewer.

battlehack20's People

Contributors

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