Log in

Local missions, local battle, checkio-cli

  • 2
  • 5 Jul '15

Hi :)

So far, we've received a lot of feedback from players that need a tool to test algorithms before battle. Right now we have in plans to add this tool to the web version of the game. In the mean-time, please allow me to show you a console tool that we've been using to design and test the coding puzzles and battle missions for Empire of Code.

We are still polishing it so if you find any issues, please leave a comment below or leave an issue on the github repository for this tool.

Every coding puzzle on EoC is in a GitHub repository. checkio-cli is a tool which can allow you to download the repository, build it and check a solution.

checkio-cli currently works on Mac and Linux and uses Docker to build, run and test a missions, so you'll need to install Docker first. I’ll illustrate how it works on Ubuntu Desktop 14.04.2 LTS x64

Let's install Docker first:

$ sudo apt-get install linux-image-generic-lts-trusty
$ sudo reboot
$ wget -qO- https://get.docker.com/ | sh
$ sudo usermod -aG docker oduvan

Relogin after that and test how docker works

$ docker run hello-world

Here is some more information you can read about Docker and how to install it on Linux or MacOS.

checkio-cli is running with Python 3 and the installation process goes through pip so you may need to install both of these in case you don't have them.

$ sudo apt-get install python3-pip

We are also using virtualenv outside of Docker

$ sudo pip3 install virtualenv

After installing docker you'll need to install and configure checkio-cli:

$ sudo pip3 install checkio-cli

$ checkio-cli

The configuration process will be started automatically at the very first call of the checkio-cli command. The result of the interactive configuration process will be the file checkio_cli.yaml located in your home folder.

You can restart configuration process using:

$ checkio-cli config

By default all related data is stored in the checkio folder, but during the configuration you can change it.

  • 1
  • 5 Jul '15

Now it is time to download and build a battle. First call can take some time:

$ checkio-cli get-git https://github.com/CheckiO/EoC-battle eoc-battle-1

In your solution folder you can find a file eoc_battle_1.py. The battle will be created in this file.

In order to start the battle you can simply use:

$ checkio-cli battle eoc-battle-1

The battle visualization process is a simple output of every frame of the battle. The same code is running on a server and the visualization is the only difference between them.

Now let's take a look closer at the battle solution eoc_battle_1.py.

This line imports a level.

from battle_missions.utils import example as mission

you can replace it by

from battle_missions.campaigns.starter import lvl1_easy_target as mission

Here you can find a list of all available levels and their structure. You can also design your own levels to test the solution.

Then you can define a code for your crafts. It can be one source code for each of them or you can use different codes for different crafts.

ATTACKER_CODE = """

It is also not a very convenient to hold everything in one file, so you can put craft's code in another file then simply read the file in
eoc_battle.py.

ATTACKER_CODE = open('craft1.py').read()

What else you can do?

You can design your own levels and test them so they might become a part of our single player campaign.

The battle is completely open-source so you can add your own commands to the battle source through a pull request to the repository.

That's it so far. What do you think?

  • 5 Jul '15

This topic has been pinned.

  • 5 Jul '15

This topic has been moved.

  • 6 Jul '15

This topic has been pinned.

PoufBenoit Delaunay
  • 18 Jul '15

checkio-cli get-git https://github.com/CheckiO/EoC-battle eoc-battle-1

Is this still supposed to work ? I get a NoSuchPathError
Also, Docker works on Windows too. With a VM, everything is easy and automated

  • 18 Jul '15

@Pouf said:
checkio-cli get-git https://github.com/CheckiO/EoC-battle eoc-battle-1

Is this still supposed to work ? I get a NoSuchPathError

It is working for me right. This is part of output

Screen Shot 2015-07-18 at 6.58.03 PM.png

What is on your side?

  • 18 Jul '15

@Pouf said:
Docker works on Windows too. With a VM, everything is easy and automated

I do what to test it there as well but haven't had a change yet.

I know someone who want to use it through window os.

Have you tried? Does it work? :)

  • 11 Aug '15

A rather interesting fact I discovered today. Coordinate system in checkio-cli battle console view appears to be inverted comparatively to the browser battle UI. That is, when you do unit_client.do_move((39, 39)), the browser battle UI shows my troops move to the bottom corner of the map, which I intuitively assumed to be bottom left in checkio-cli battle. Whereas the same code in console shows them move to the bottom right corner. Slightly odd, I'd say.

  • 12 Aug '15

Thanks. Good point.

  • 10 Nov '15

Why not make a "mission simulator" that runs directly in the browser?

  • 12 Nov '15

Please post instructions for how to get this running on Windows.

  • 28 Nov '15

I tried to use checkio-cli battle on a fresh virtual machine today. It installed fine with no problems. I managed to download and build checkio-cli get-git https://... b1, as specified in tutorial, no errors.

Now, when I try to start it checkio-cli battle b1 --without-container, it prints a bunch of identical stack traces:

Traceback (most recent call last):
  File "/home/leo/checkio/sources/compiled/b1/verification/envs/python_3/main.py", line 6, in <module>
    from checkio_executor_python.client import ClientLoop, RefereeClient
ImportError: No module named 'checkio_executor_python'

Battlefield is printed in console many times, but nothing moves and all units are marked idle. Eventually it prints Game Over!!! The Winner is 0.

Any ideas on how to fix this?

  • 28 Nov '15

By the way, note that all images in the original tutorial are now broken with 404.

Also, code in EoC-battle contains an outdated code example:

# For example
# from battle_missions.campaigns.starter import lvl1_easy_target as mission

lvl1_easy_target were renamed to easy_target.

  • 28 Nov '15

@Leonix you start using checkio-cli. This is awesome :)

Any ideas on how to fix this?

What if you use $ checkio-cli battle b1 ? Does it work?

Try also $ checkio-cli compile-mission b1

EoC-battle contains an outdated code example

Yeah should be changed. We didn't change it yet after the battle was changed.

all images in the original tutorial are now broken with 404

We have this with old forum post. :( This is a current forum issue. We will fix it

  • 29 Nov '15

$ checkio-cli -v 4 compile-mission b1

Everything seems fine except the last two lines being suspicious.

DEBUG:root:Sys: /home/leo/checkio/sources/native/b1/bin/pip3 install -r /home/leo/checkio/sources/compiled/b1/interfaces/checkio_cli/requirements.txt
You must give at least one requirement to install (see "pip help install")

The specified requirements file is empty. Is this intended?


$ checkio-cli -v 4 battle b1

INFO:root:Start interface
DEBUG:docker.auth.auth:Trying /home/leo/.docker/config.json
DEBUG:docker.auth.auth:File doesn't exist
DEBUG:docker.auth.auth:Trying /home/leo/.dockercfg
DEBUG:docker.auth.auth:File doesn't exist - returning empty config
DEBUG:root:Create container: 172.17.42.1 7878 1 2 10
DEBUG:requests.packages.urllib3.connectionpool:"POST /v1.19/containers/create HTTP/1.1" 201 90
DEBUG:requests.packages.urllib3.connectionpool:"POST /v1.19/containers/f6c565a0991e586eafc598fffa0d0e4f942b59c62434b201fb0a23746af65468/start HTTP/1.1" 204 0
DEBUG:requests.packages.urllib3.connectionpool:"POST /v1.19/containers/f6c565a0991e586eafc598fffa0d0e4f942b59c62434b201fb0a23746af65468/attach?stderr=1&stdout=1&stream=1&logs=1 HTTP/1.1" 200 None
DEBUG:requests.packages.urllib3.connectionpool:"GET /v1.19/containers/f6c565a0991e586eafc598fffa0d0e4f942b59c62434b201fb0a23746af65468/json HTTP/1.1" 200 None
INFO:root:b'Raven is not configured (logging is disabled). Please see the documentation for more information.\n'
INFO:root:b'2015-11-29 06:33:32 root[1] INFO START Host:172.17.42.1 PORT:7878 CONNECTION_ID:1 DOCKER_ID:2\n'
INFO:root:b'2015-11-29 06:33:35 checkio_referee.editor.tcpclient[1] INFO Reconnecting to editor\n'

Then nothing happens. It hangs like this forever.

  • 29 Nov '15

My theory is that an empty requirements.txt file caused compilation to abort mid-way, and some dependancies were not installed. I worked around the issue by globally installing checkio_executor_python package via pip. Now I can run battles --without-container. No idea what's wrong with my docker, but I don't really care for now.

This created even more questions, though :)

1) My goal is to be able to test my defence strategies. I figured out I can arrange building layout in code by hand. This works, but it's a rather tedious affair. Would be cool if I could export my current base layout from game. Is there an API or something?

2) I'm looking for a way to divide a checkio solution file into several pieces. Trying to edit ATTACKER_CODE string without syntax highlighting is rather inconvenient, and there are going to be many strings like that: several turrets and several craft pads. Ideally I'd like to read them from separate files. But then I'm confused with where do things go during compilation. Where do I put my files so that checkio-cli allows me to read them?

3) I'm experimenting with turret algorithms. Is there a way to run a callback right after a shot? My ideas require me to sometimes switch targets at times not connected to unit death or even movement. The optimal way to do such switching is between shots, right after discharge. I can probably determine the right moment by checking for it in a loop, but it's defininitely not a good approach.

  • 29 Nov '15

4) Unit stats in battle_mocks are different from those in game. It seems the repo were not updated since beta.

  • 29 Nov '15

@Leonix said:
My theory is that an empty requirements.txt file caused compilation to abort mid-way, and some dependancies were not installed. I worked around the issue by globally installing checkio_executor_python package via pip. Now I can run battles --without-container. No idea what's wrong with my docker, but I don't really care for now.

what is your OS?

This created even more questions, though :)

1) My goal is to be able to test my defence strategies. I figured out I can arrange building layout in code by hand. This works, but it's a rather tedious affair. Would be cool if I could export my current base layout from game. Is there an API or something?

no API yet. but we will definitely do something in future.

2) I'm looking for a way to divide a checkio solution file into several pieces. Trying to edit ATTACKER_CODE string without syntax highlighting is rather inconvenient, and there are going to be many strings like that: several turrets and several craft pads. Ideally I'd like to read them from separate files. But then I'm confused with where do things go during compilation. Where do I put my files so that checkio-cli allows me to read them?

you can do ATTACKER_CODE = open("att.py").read()

3) I'm experimenting with turret algorithms. Is there a way to run a callback right after a shot? My ideas require me to sometimes switch targets at times not connected to unit death or even movement. The optimal way to do such switching is between shots, right after discharge. I can probably determine the right moment by checking for it in a loop, but it's defininitely not a good approach.

I think I can do something like this

Reply