GithubHelp home page GithubHelp logo

xm-battlesnake-nodejs's Introduction

battlesnake-nodejs

A simple BattleSnake AI written for NodeJS.

To get started you'll need a working NodeJS development environment, and at least read the Heroku docs on deploying a NodeJS app. This client uses Express4 for easy route management, read up on the docs to learn more about reading incoming JSON params, writing responses, etc.

Pre-requisite Accounts

Every team must show up with a laptop and create the following accounts in order to use the provided start snake. You are welcome to use existing accounts if you have them already.

Prerequisite Software

You'll need the follwing software on your computer before you can get started with this project:

You'll need the following software on your computer if you want to compile and run the application locally. This is completely optional but probably desired since troubleshooting coding errors and testing behaviour will be much easier.

If you haven't setup a NodeJS development environment before, read how to get started with NodeJS. You'll also need npm for easy JS dependency management.

If you have the software installed already, confirm by running the respective commands on the command prompt and check the versions:

  • npm -v
  • node -v
  • git --version
  • heroku --version

Preparing your project

DON'T SKIP THIS STEP. You'll need your own copy of this project under your own GitHub account in order to make and publish changes to your snake.

  • Make sure you are signed in to your GitHub account
  • Fork this project

Test Your Environment Setup

At this point, make sure that all of you software is installed, and you've forked this project correctly. Run the following commands:

$ git clone https://github.com/<your account>/xm-battlesnake-nodejs.git
$ cd xm-battlesnake-nodejs
$ heroku local

Your app should now be running on localhost:5000/health.

Testing your local app

You can use curl commands to easily test if you snake is working and responding to end points.

Run it locally using heroku command:

$ heroku local

/start Endpoint

$ curl localhost:5000/start -X POST -H "Content-Type: application/json" -d '{"width":20,"height":20,"game_id":"example-game-id"}'

/move Endpoint

$ curl localhost:5000/move -X POST -H "Content-Type: application/json" -d '{ "you": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98","width": 2,"turn": 0,"snakes": [{ "taunt": "git gud","name": "my-snake","id": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98","health_points": 93,"coords": [[0,0],[0,0],[0,0]] },{ "taunt": "gotta go fast","name": "other-snake","id": "c35dcf26-7f48-492c-b7b5-94ae78fbc713","health_points": 50,"coords": [[1,0],[1,0],[1,0]] }],"height": 2,"game_id": "a2facef2-b031-44ba-a36c-0859c389ef96","food": [[1,1]],"dead_snakes": [{ "taunt": "gotta go fast","name": "other-snake","id": "83fdf2b9-c8d0-44f4-acb2-0c506139079e","health_points": 50,"coords": [[5,0],[5,0],[5,0]] }] }'

Deploying to Heroku

Create an App

Next, create an application on Heroku and give it a name that represents your project. This will create a remote git repo for Heroku to use to deploy and run your project. NOTE: APP Name must start with a letter and can only contain lowercase letters, numbers, and dashes.

$ heroku create [APP NAME]
$ git push heroku master

The output should end with the URL endpoint of your snake. Use this URL to add your snake to a game on the server.

remote: -----> Launching...
remote:        Released v3
remote:        https://my-snake.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.

Testing the app

Your app should now be running on https://my-snake.herokuapp.com/health. You can use curl commands to easily test if you snake is working and responding to end points.

/start Endpoint

$ curl https://my-snake.herokuapp.com/start -X POST -H "Content-Type: application/json" -d '{"width":20,"height":20,"game_id":"example-game-id"}'

/move Endpoint

$ curl https://my-snake.herokuapp.com/move -X POST -H "Content-Type: application/json" -d '{ "you": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98","width": 2,"turn": 0,"snakes": [{ "taunt": "git gud","name": "my-snake","id": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98","health_points": 93,"coords": [[0,0],[0,0],[0,0]] },{ "taunt": "gotta go fast","name": "other-snake","id": "c35dcf26-7f48-492c-b7b5-94ae78fbc713","health_points": 50,"coords": [[1,0],[1,0],[1,0]] }],"height": 2,"game_id": "a2facef2-b031-44ba-a36c-0859c389ef96","food": [[1,1]],"dead_snakes": [{ "taunt": "gotta go fast","name": "other-snake","id": "83fdf2b9-c8d0-44f4-acb2-0c506139079e","health_points": 50,"coords": [[5,0],[5,0],[5,0]] }] }'

Pushing Updates to Heroku

You have to commit your changes to your git project as part of pushing them to the remote heroku git.

$ git add --all; git commit -m "Updated"; git push
$ git push heroku master

Debugging Logs on Heroku

Once your snake is running, you can tail the logs any time in the console using the command:

$ heroku logs --tail

Documentation

For more information about using NodeJS on Heroku, see these Dev Center articles:

xm-battlesnake-nodejs's People

Contributors

xmatters-tko avatar

Watchers

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