Coder Social home page Coder Social logo

battlesnake-ts's Introduction

Preparations before K-day

We have gathered instructions for 4 different hosting solutions. There are som pros and cons with all so you have to pick the one suiting you. You can always host your Battlesnake in other places if you want.

  • Replit. Supereasy to get started but you have to use a browser based IDE.
  • Railway. You can develop on your machine and let Railway build your app when pushed to Github. But you need to give the Railway App access to your Github account.
  • Render. You can develop locally just like Railway but you don't need to give access to you repo. The build is however very slow.

Replit

Replit is a free browser based hosting and IDE. You will edit your files directly in the browser with their built in IDE.

  1. Go to https://replit.com/ and create an account.
  2. Click "+ Create" to create a new Repl.
  3. Choose "Import from github".
  4. Paste "github.com/ola-gawell-dct/battlesnake-ts-starter" as GitHub URL.
  5. Choose Typescript from Language.
  6. Click "Import from GitHub".
  7. Click "Run" to build your project and launch the server. This will takes some time the first time since it needs to install all the npm dependencies. The next time will be much faster.
  8. When you see Running Battlesnake at http://0.0.0.0:8000... in the log the server is up and running. A small browser window will show up.
  9. Copy the URL from the small browser window and use it in the next section. NOTE: It can somtimes take a while for the first request to the server to repond. The server might go into sleep mode after som inactivity so its good to call your url before the big finals.

Railway

Railway is a free browser based hosting.

  1. Go to https://github.com/ola-gawell-dct/battlesnake-ts-starter and fork the repo.
  2. Go to https://railway.app/ and click "login" an account to create a new account, user your Github account to log in.
  3. Click "+ New Project".
  4. Choose "Deploy from GitHub repo" and then “Configure GitHub App.
  5. Do the configuration and choose the forked repo.
  6. Click “+ Add variables” and enter a new variable “PORT” with value 6774 then press “+ Add” (Or whatever port is in the logs under the "Deployments tab)
  7. When you see Running Battlesnake at http://0.0.0.0:6774... in the log the server is up and running.
  8. Go to “Settings” and press “Generate Domain”.
  9. Copy the URL from "Settings" under "Domain" and use it in the Battlesnake instructions section. (You might have to re-deploy after adding variable or generating domain if you can't ping the web server later from the Battlesnake website)

Notes

  • Servers seems to be located in US-west, relevant when choosing engine region in the Battlesnake instructions section.

Render

  1. Go to https://github.com/ola-gawell-dct/battlesnake-ts-starter and fork the repo and make it public.
  2. Go to https://dashboard.render.com/register.
  3. Create an account in any way you like.
  4. Select New Web Serivces.
  5. Paste the url to you forked repo from step 1 in the Public Git Repository field or choose to connect to you Github account (not tested).
  6. Press Continue.
  7. Name your project to anything you like.
  8. Choose Node as Environment.
  9. Press Create Web Service.
  10. The build will start immediately but will take some time. Every time you push changes to the git repository you need to press the Manual Deploy > Deploy latest commit.

Heroku

NOTE: Heroku is not longer free to use. You can still use it but these instructions might not be complete anymore.

By following these instructions your server will be depolyed to Heroku. It is possible to host the server in any way you want as long as it is publicly accessible. The following instructions assumes that you want to use Heroku hosting.

If you don't want to install or use the Heroku CLI it is also possible to integrate Heroku with a Github repo, but that is not covered by this guide (https://devcenter.heroku.com/articles/github-integration).

  1. Clone this repo.

  2. Install Heroku CLI (might requiere a XCode and MacOS update on Mac) and create a Heroku account. https://devcenter.heroku.com/articles/heroku-cli

  3. Run heroku login.

  4. Remove the git directory in this repo rm -rf .git.

  5. Initialize a fresh git repo git init.

  6. Commit all files

    git add .
    git commit -m "Initial commit"
    
  7. Create a heroku app heroku create your-app-name.

  8. Deploy your code git push heroku main.

    NOTE if you encounter an error messsge saying something the one below, you're trying to push a branch that doesn't exist.

    error: src refspec master does not match any  
    error: failed to push some refs to 'https://git.heroku.com/most-super-snake.git'
    

    Change to the branch your're current using, for instance master.

  9. Verify by browsing to the URL printed by the last command.

    remote: -----> Launching...
    remote:        Released v3
    remote:        https://most-super-snake.herokuapp.com/ deployed to Heroku <---- THIS ONE 
    

Add your snake to Battlesnake

  1. Create a Battlesnake account at https://play.battlesnake.com/.
  2. Press "Create Battlesnake" on the Battlesnake site under "Battlesnakes".
  3. Choose a name and set the url to your url from last section.
  4. Choose Public battlesnake.
  5. Save
  6. Create a game and add your snake.
  7. Run it to verify that it respond to the call from Battlesnake.

Run tests

Run jest test cases with:

npm run test

Play a Game Locally (optional)

Install dependencies using npm

npm install

Start your Battlesnake

npm run start

You should see the following output once it is running

Running Battlesnake at http://0.0.0.0:8000

Open localhost:8000 in your browser and you should see

{"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}

Install the Battlesnake CLI

Command to run a local game

battlesnake play -W 11 -H 11 --name 'TypeScript Starter Project' --url http://localhost:8000 -g solo --browser

Links

Battlesnake Quickstart Guide Battlesnake API Docs

battlesnake-ts's People

Contributors

jacobferm avatar joakimemilmagnusson avatar ola-adolfsson-ipex avatar ola-gawell-dct 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.