Skip to content

Instantly share code, notes, and snippets.

@sammachin
Last active July 13, 2021 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sammachin/6cbf34b31e1890bb7a638005bcc4f54b to your computer and use it in GitHub Desktop.
Save sammachin/6cbf34b31e1890bb7a638005bcc4f54b to your computer and use it in GitHub Desktop.
Battlesnake Starter

A Simple flow for getting started with Battlesnake

Returns a random move for each turn.

You will need to install the node-red-node-random node into your palette other than that it uses only core nodes.

You may also want to use the Ngrok Node to utilise ngrok for exposing your Node-RED instance to the internet and handling the battlesnake webhooks.

[{"id":"3e25e21f5a4ce997","type":"tab","label":"Start","disabled":true,"info":""},{"id":"6679c30ec5613515","type":"http in","z":"3e25e21f5a4ce997","name":"","url":"/","method":"get","upload":false,"swaggerDoc":"","x":110,"y":100,"wires":[["06b0f0bae6104f48"]]},{"id":"06b0f0bae6104f48","type":"template","z":"3e25e21f5a4ce997","name":"my snake","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"apiversion\": \"1\",\n \"author\": \"\",\n \"color\": \"#a22222\",\n \"head\": \"default\",\n \"tail\": \"default\"\n}","output":"json","x":300,"y":100,"wires":[["8e92a869a40bda82"]]},{"id":"8e92a869a40bda82","type":"http response","z":"3e25e21f5a4ce997","name":"","statusCode":"","headers":{},"x":450,"y":100,"wires":[]},{"id":"7bec740b8fa1e767","type":"http in","z":"3e25e21f5a4ce997","name":"","url":"/end","method":"post","upload":false,"swaggerDoc":"","x":120,"y":180,"wires":[["a0482bfbe2a8d9ac"]]},{"id":"a0482bfbe2a8d9ac","type":"template","z":"3e25e21f5a4ce997","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"ok","output":"str","x":300,"y":180,"wires":[["096db284803fc29e"]]},{"id":"096db284803fc29e","type":"http response","z":"3e25e21f5a4ce997","name":"","statusCode":"","headers":{},"x":450,"y":180,"wires":[]},{"id":"489f0195741c8ce0","type":"http in","z":"3e25e21f5a4ce997","name":"","url":"/start","method":"post","upload":false,"swaggerDoc":"","x":130,"y":140,"wires":[["d7f05099d13f99b8"]]},{"id":"d7f05099d13f99b8","type":"template","z":"3e25e21f5a4ce997","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"ok","output":"str","x":300,"y":140,"wires":[["8d83ff74ea508b27"]]},{"id":"8d83ff74ea508b27","type":"http response","z":"3e25e21f5a4ce997","name":"","statusCode":"","headers":{},"x":450,"y":140,"wires":[]},{"id":"dc7b55b93aff605c","type":"http in","z":"3e25e21f5a4ce997","name":"","url":"/move","method":"post","upload":false,"swaggerDoc":"","x":130,"y":240,"wires":[["b9f7e53c67ce750e","66069422eee255ba"]]},{"id":"b57137af4124dc81","type":"change","z":"3e25e21f5a4ce997","name":"Select Random Move","rules":[{"t":"set","p":"payload","pt":"msg","to":"moves[msg.payload]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":240,"wires":[["3915954f05f13460"]]},{"id":"2bbaa00ffe3f226e","type":"random","z":"3e25e21f5a4ce997","name":"","low":"0","high":"","inte":"true","property":"payload","x":900,"y":240,"wires":[["b57137af4124dc81"]]},{"id":"b9f7e53c67ce750e","type":"debug","z":"3e25e21f5a4ce997","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":310,"y":340,"wires":[]},{"id":"6128249c00d9cfe4","type":"debug","z":"3e25e21f5a4ce997","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1530,"y":340,"wires":[]},{"id":"b6615de3721662fb","type":"http response","z":"3e25e21f5a4ce997","name":"","statusCode":"","headers":{},"x":1530,"y":240,"wires":[]},{"id":"3915954f05f13460","type":"template","z":"3e25e21f5a4ce997","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"move\": \"{{payload}}\"}","output":"json","x":1340,"y":240,"wires":[["b6615de3721662fb","6128249c00d9cfe4"]]},{"id":"7d46459e08f05bd6","type":"change","z":"3e25e21f5a4ce997","name":"Count Moves","rules":[{"t":"set","p":"to","pt":"msg","to":"$count(moves)-1\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":240,"wires":[["2bbaa00ffe3f226e"]]},{"id":"66069422eee255ba","type":"change","z":"3e25e21f5a4ce997","name":"","rules":[{"t":"set","p":"moves","pt":"msg","to":"[\"up\",\"down\",\"left\",\"right\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":240,"wires":[["7d46459e08f05bd6"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment