Git Product home page Git Product logo

2017's Introduction

hirethissnake 2018

codecov Build Status

A Battlesnake AI based heavily on graphing algorithms. Written in Python 3.7 by Daniel Frankcom, Eric Showers, Kyle Thorpe, and Phil Denhoff, with contributions from Alex Welsh-Piedrahita.

Installation

Docker - Windows / Linux / Mac

You'll have to install Docker yourself, however once that is done installation and execution is relatively simple. The basic concept is that you install a Docker container which has all the required environment to run this project without installing a different version of Python, plus all the required packages.

For now, you'll have to build the docker image on your local machine - soon you'll (hopefully) be able to download a pre-built image.

First, git clone this repository to your local machine (using command line or a GUI). In command line, traverse to the the directory. Then build the docker image using this command

docker build -t hirethissnake .

docker initiates the docker program, build is the instruction to create an image, -t designates the name of the image, and we use '.' to say 'look for a Dockerfile in the current folder'.

Go to Running to see how to use the program.

Script - Linux Only

An installer file is provided to run the download the repo and all neccessary packages and programs to run the server. Currently only Linux is supported.

Download the install.sh file to your local server, where you'd like to the hirethissnake folder. Add execution permissions to the script and execute it. It will ask for your password to sudo-install some packages, and will request your github credentials to access the repo if it's private. Please feel free to expect the installer if you aren't comfortable with that, or do those steps yourself.

chmod +x ./install.sh
./install.sh

Running

Docker

Following the successful completion of docker build, we will need to actually run the container with our current code. One of the issues is that we want a constant environment (Python with required packages) but constantly changing source code. We manage this by mounting a volume in docker. Run this command:

Linux / Mac

docker run --rm -it -p 8080:8080 -v $(pwd)/app:/data/app -v $(pwd)/static:/data/static hirethissnake python "-mapp.main"

Windows - Command Prompt

docker run --rm -it -p 8080:8080 -v %cd%/app:/data/app -v $(pwd)/static:/data/static hirethissnake python "-mapp.main"

Windows - Power Shell

docker run --rm -it -p 8080:8080 -v $pwd/app:/data/app -v $(pwd)/static:/data/static hirethissnake python "-mapp.main"

Oh boy, there is a lot to unpack here. What are all these things? Why do Windows and Linux / Mac have different commands?

In a list:

  • docker : Runs docker on CLI
  • run : Execute an image (either start it and keep it started, or execute command in that environment)
  • --rm : Deletes the container when it closes (to keep your comptuter clean)
  • -it : Make the container interactive, so we can see what's going on!
  • -p 4000:8080 : Pass all data from port 8080 on the host computer into the docker image on port 8080, and vice-versa. 8080 can be changed on the CLI, but 8080 is the port that main.py executes on.
  • -v $(pwd)/app:/data/app : (Linux) The command is roughly the same on Windows. $(pwd) == %cd%, and returns the current location of the terminal. -v tells Docker to mount the folder before the colon (":") from the host computer to the folder after the colon on the Docker image. In this way, files located at %cd%/app are available inside the image at /data/app everytime you run the command, instead of having to re-build the image.
  • hirethissnake : The name of the image. This can be changed, and if you have many images, should be changed.
  • python "-mapp.main" : This command tells the docker image that we would like to use the python executable, and that we would like to run the file in the 'app' module called 'main'. This file is then executed inside its environment, running the server.

You can now make any changes you'd like to the local files in ./app and then run the docker run command above, and see those changes represented.

Manually

To run the server, execute

python app/main.py

and then test the client in your browser: http://localhost:8080

Docker Compose

For advanced users, we have included a docker-compose.yml file which is currently set up to pit 3 of our snakes against each other.

The primary usecase for this is currently using the included batch game server found at utilities/batchserver/. The docker-compose.yml file can easily be modified to run 1 snake, or for that matter any number of snakes providing the user has a basic understanding of the Docker Compose syntax. Additionally, it is not directly tied to the batch server in any way, and simply makes the various snake URLs available for access however you see fit.

In order to run the snake in this manner, Docker Compose must be installed.

First, build the snake image as instructed in the Installation section.

Then run the following command to start the snakes

docker-compose up

Questions?

Please email any questions you have to [email protected] and he'll make sure they get to the right person.

2017's People

Contributors

a-j-welsh avatar alexophile avatar bvanvugt avatar danielfrankcom avatar gschier avatar kylethorpe avatar phildenhoff avatar sean-lynch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

2017's Issues

Implement weightTrapSnakes()

TODO

  • How long are they?
  • How much traversal room are we leaving them?
  • Do they need food? Do they have it in the trapped location?
  • How long are we? Can we effectively block them for long enough?

Implement weightEnclosedSpaces()

TODO

  • How long are we?
  • Are we giving other people the opportunity to block off our exit?
  • What is the optimal traversal path to maximise future space opportunities
  • Don't limit our moves (against a surface) unless advantageous or necessary

Fun taunts

Update main to provide fun taunts on the fly, during the game

Implement getNextMove()

Do in tandem with each weight() method being completed
TODO

  • Run each algorithm to make decisions
  • Find best route to desired square
  • Ensure boundary is not selected (shouldn't be an issue since we
  • would only head towards positively weighted squares anyway and
  • boundary square do not exist according to algorithm)
  • If several candidates, pick one at random
  • Return decision

Fix Heroku deploy issues

Right now, appJar is causing dependency issues on Heroku. This should be solved soon for testing.

Code snippet below:

2017-03-03T19:47:38.837877+00:00 app[web.1]: [2017-03-03 19:47:38 +0000] [10] [INFO] Worker exiting (pid: 10)
2017-03-03T19:47:38.837825+00:00 app[web.1]:   File "/app/app/Game.py", line 5, in <module>
2017-03-03T19:47:38.853469+00:00 app[web.1]: [2017-03-03 19:47:38 +0000] [4] [INFO] Shutting down: Master
2017-03-03T19:47:38.837829+00:00 app[web.1]:     from tkinter import *
2017-03-03T19:47:38.837826+00:00 app[web.1]:   File "/app/app/Board.py", line 9, in <module>
2017-03-03T19:47:38.837826+00:00 app[web.1]:     from Board import Board
2017-03-03T19:47:38.853536+00:00 app[web.1]: [2017-03-03 19:47:38 +0000] [4] [INFO] Reason: Worker failed to boot.
2017-03-03T19:47:38.837829+00:00 app[web.1]: ImportError: No module named tkinter
2017-03-03T19:47:38.837828+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/appJar/appjar.py", line 22, in <module>
2017-03-03T19:47:38.938479+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-03T19:47:38.939389+00:00 heroku[web.1]: Process exited with status 3

Implement weightNotHitSnakes()

from doc:
TODO
Weight self as 0
Are we getting food this move? (Do we need to weight our tail 0)
Check if head position is in old food positions.
Weight other snakes as 0
Are they getting food this move? (Do we need to weigh their tails 0)
Are they dying this move?
How big are they? Don't block heads of small snakes

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.