Skip to content

tyrelh/battlesnake-typescript-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battlesnake AI using TypeScript and Node

CI/CD

A [Battlesnake AI written in TypeScript using Node as a runtime and Express as the server framework.

This project uses ts-node for running TypeScript, Mocha for testing, nodemon for development locally, and tsc for compiling TypeScript.

Requirements

Setup

First, clone this repo

git clone https://github.com/tyrelh/battlesnake-typescript-node.git battlesnake-typescript-node
cd battlesnake-typescript-node

If you don't have Node installed then install it next.(Example using Brew in MacOS. Refer to the Node docs for other OSs)

brew install node

Now install all the project dependencies with npm.

npm install

Running the snake locally

To run the snake locally simply use npm:

npm run dev

This script uses nodemon to run the server and watch local files for changes.

Battlesnake Arena using ngrok

If you want to use the Battlesnake Arena for testing locally you will need a tool such as ngrok to allow the arena to communicate with your server on your local machine.

  1. Sign up for a free account with ngrok
  2. Download their executable. This can be placed somewhere global on your machine or in your project directory.
  3. Make sure your snake server is running locally.
  4. Wherever you put that executable, run ngrok http 5000. Make sure the port supplied matches the port your snake is using (this project defaults to 5000).
  5. You should see a forwarding URL in the terminal running ngrok. Copy the http URL, it should look something like http://147fb4e4.ngrok.io.
  6. Go to the Battlesnake Arena and login with your Github account. Create a new snake and enter the ngrok URL.

Some things to note about using ngrok to run your snake locally:

  • ngrok adds a lot of latency to your snake. With a decent internet connection I was seeing times of around 130-150ms, but I have seen that spike well over the default timeout of 500ms. Just something to be aware of. ngrok should only be used for development and avoided for any competitions.
  • If you restart the ngrok process it will generate a new random URL for you. That means you need to edit the URL of your snake on the Battlesnake Arena to reflect this.

Testing

Tests can be run with npm:

npm run test

This script uses mocha and ts-node to run the TypeScript tests located in src/tests/.

Automated Deploys

This repo is set up, using Github Actions, for automated deployments to AWS Elastic Beanstalk.

Contributing

If you have any questions or suggestions feel free to open an Issue or PR on this repo.

You can find other ways to get in touch with me on my tyrelh.github.io.

About

A Battlesnake AI written in TypeScript and Node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published