Skip to content

manikmagar/mule-battlesnake-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Battlesnake written in Mule and DataWeave

This is a basic implementation of the Battlesnake API. It's a great starting point for anyone wanting to program their first Battlesnake using Mule and DataWeave.

Quickstart

The Quick Start Coding Guide provides the full set of instructions to customize, register, and create your first games with your Battlesnake!

Prerequisites

Running Your Battlesnake in local Anypoint Studio

  1. This starter project a Github Template Repository. Click "Use this template" button on top or Click here to create a new project using this template.
  2. Import this project in Anypoint Studio
  3. Set CLOUDHUB_APP_PREFIX property value in pom.xml
  4. Run mule-battlesnake mule application. This will expose API at http://localhost:8081/api that you can use for creating battlesnakes.
  5. Expose local http to internet with ngrok or similar tools.
  6. Follow Battlesnake quickstart quide to create your battlesnake and play

NOTE: MuleSoft Community Twitch hosted a few live sessions demonstrating this starter and how to work with it. The first one introducing this starter project can be found on Twitch here.

Deploying to Cloudhub

Project's POM is configured for deploying to Cloudhub using Mule Maven Plugin. See the mule-maven-plugin configuration in pom.xml.

Set your Anypoint Credentials as environment variables with below keys on your terminal -

  • ANYPOINT_USER
  • ANYPOINT_PASSWORD

Run mvn deploy -DmuleDeploy to trigger the deployment.

Once deployed to Cloudhub, use application's URL https://{ch-app-name}.{region}.cloudhub.io/api to create your battlesnake.

Enabling Github Actions

The template includes a GitHub Actions workflow ./.github/workflows/build.yml to deploy to CloudHub.

To successfully deploy using GitHub Actions:

Once configured, Commits to main branch will deploy application to your CloudHub.

Customizing Your Battlesnake

Accessing http://localhost:8081/api will return response like below. You can change these parameter values from src/main/resources/application.yaml.

{
  "apiversion": "1",
  "author": "mmsonline",
  "color": "#888888",
  "head": "default",
  "tail": "default",
  "version": "0.0.1-beta"
}

This resource 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.

Changing Behavior

On every turn of each game your Battlesnake receives information about the game board and must decide its next move. Possible moves are "up", "down", "left", or "right" and initially your Battlesnake will choose a move randomly. Your goal as a developer is to read information sent to you about the game (available in the payload) and decide where your Battlesnake should move next. All your Battlesnake logic lives in /src/main/resources/dw/move-snake.dwl, and this is the code you will want to edit.

The snake algorithm in this project is written using DataWeave language. While building the game, we will learn about Mule APIs and data transformation using DataWeave. Following are some good resources to learn more about DataWeave -

See the Battlesnake Game Rules for more information on playing the game, moving around the board, and improving your algorithm.

Playing Battlesnake

Completing Challenges

If you're looking for the Single Player Mode of Battlesnake, or something to practice with between events, check out Challenges.

Joining a Battlesnake Arena

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.

Joining a Battlesnake League

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.


Resources

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.