Getting started with Battlesnake and PowerShell with Azure Functions
This is a basic implementation of the Battlesnake API in PowerShell leveraging Azure Functions. It's a great starting point for anyone wanting to program their first Battlesnake using PowerShell, and comes ready to deploy with Azure Functions.
- PowerShell
- Azure Functions
- Pester - Optional
- Visual Studio Code - Optional
- Visual Studio Code Azure Extension - Optional
- Azure Functions Docker Container - Optional
- Docker Compose - Optional
The Quick Start Coding Guide provides the full set of instructions to customize, register, and create your first games with your Battlesnake! The guide leverages Azure Functions to host PowerShell as a HTTP API and while the it uses Visual Studio Code with Azure VSCode Extension to publish, the instructions can be modified to work with any other publishing methods and tools like AzureCLI, Azure PowerShell, Azure Bicep.
- A free Battlesnake Account
- An Azure Account/Subscription Azure Account
Locate the Invoke-Info
function inside handlers.ps1. Inside that function you should see a line that looks like this:
return @{
apiversion = "1"
author = "MyUsername"
color = "#888888"
head = "default"
tail = "default"
version = "0.0.1-beta"
}
This function is called by the game engine periodically to make sure your Battlesnake is healthy, responding correctly, and to determine how your Battlesnake will appear on the game board. See Battlesnake Personalization for how to customize your Battlesnake's appearance using these values.
Whenever you update these values, go to the page for your Battlesnake and select 'Refresh Metadata' from the option menu. This will update your Battlesnake to use your latest configuration and those changes should be reflected in the UI as well as any new games created.
On every turn of each game your Battlesnake receives information about the game board and must decide its next move.
Locate the Invoke-Move
function inside handlers.ps1. Possible moves are "up", "down", "left", or "right". To start your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the board (available in the GameState
variable) and decide where your Battlesnake should move next.
See the Battlesnake Game Rules for more information on playing the game, moving around the board, and improving your algorithm.
To create an Azure Function App and publish your Battlesnake as an Azure PowerShell Function using Visual Studio Code follow this official guide
Note: You can skip to 'Sign in to Azure' section.
Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing Azure Functions Core Tools, renaming 'example.local.settings.json' to 'local.settings.json' and running:
func start
Note: You cannot create games on play.battlesnake.com using a locally running Battlesnake unless you install and use a port forwarding tool like ngrok. See Hosting Suggestions.
This Starter Project comes with a very simple Pester test suite for you to expand! Located in tests/starter-snake-powershell/*.tests.ps1
you can run them using the following command:
Invoke-Pester tests/starter-snake-powershell/*.tests.ps1
If you're looking for the Single Player Mode of Battlesnake, or something to practice with between events, check out Challenges.
Once you've made your Battlesnake behave and survive on its own, you can enter it into the Global Battlesnake Arena to see how it performs against other Battlesnakes worldwide.
Arenas will regularly create new games and rank Battlesnakes based on their results. They're a good way to get regular feedback on how well your Battlesnake is performing, and a fun way to track your progress as you develop your algorithm.
Want to get out there to compete and win prizes? Check out the Quick Start League Guide for information on the how and when of our competitive seasons.
All documentation is available at docs.battlesnake.com, including detailed Guides, API References, and Tips.
You can also join the Battlesnake Developer Community on Discord. We have a growing community of Battlesnake developers of all skill levels wanting to help everyone succeed and have fun with Battlesnake :)
Check out live Battlesnake events on Twitch and see what is happening when on the Calendar.
Want to contribute to Battlesnake? We have a number of open-source codebases and would love for you to get involved! Check out our page on Contributing.
Do you have an issue or suggestions for Battlesnake? Head over to our Feedback Repository today and let us know!
Do you have an issue or suggestions for this PowerShell starter project? Head over to our PowerShell Starter Project Repository today and let us know!