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.
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
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.
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.
- Sign up for a free account with ngrok
- Download their executable. This can be placed somewhere global on your machine or in your project directory.
- Make sure your snake server is running locally.
- Wherever you put that executable, run
ngrok http 5000
. Make sure the port supplied matches the port your snake is using (this project defaults to5000
). - You should see a forwarding URL in the terminal running ngrok. Copy the http URL, it should look something like
http://147fb4e4.ngrok.io
. - 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.
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/.
This repo is set up, using Github Actions, for automated deployments to AWS Elastic Beanstalk.
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.