Skip to content

Battlesnake starter using Java 17 with JBang, running Quarkus and works with repl.it and heroku

Notifications You must be signed in to change notification settings

jbangdev/jbang-battlesnake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Battlesnake written in Java using JBang and Quarkus.

This is a basic implementation of the Battlesnake API. It's a great starting point for anyone wanting to program their first Battlesnake using Java. It comes ready to use with Replit.com and provides instructions below for getting started. It can also be deployed to Heroku, or any other cloud provider you'd like.

Technologies

Quickstart

The Quick Start Coding Guide provides the full set of instructions to customize, register, and create your first games with your Battlesnake! While the guide uses Repl.it as an example host, the instructions can be modified to work with any hosting provider. You can also find advice on other hosting providers on our Hosting Suggestions page.

Prerequisites


Running Your Battlesnake on replit.com

Run on Replit.com

  1. Login to your Replit.com account.

  2. Click the 'Run on replit.com' button above, or visit the following URL: https://replit.com/github/jbangdev/jbang-battlesnake.

  3. You should see your Repl being initialized - this might take a few moments to complete.

  4. Once your Repl is ready to run, click Run ▶️ at the top of the screen. You should see jbang (and any other dependencies) being installed. Once installation is complete, your Battlesnake server will start and you should see the following:

    [Thread-0] INFO org.eclipse.jetty.server.Server - Started @ms
    
  5. Above the terminal window you'll see the live output from your Battlesnake server, including its URL. That URL will be the URL used to create your Battlesnake in the next step. If you visit that URL in your browser, you should see text similar to this:

    {"apiversion": "1", "author": "", "color": "#888888", "head": "default", "tail": "default"}
    

This means your Battlesnake is running correctly on Replit.com.

At this point your Battlesnake is live and ready to enter games!

Customizing Your Battlesnake

Locate the index method inside snake.java. You should see code that looks like this:

return new Info("1",
                "",
                "#888888",
                "default",
                "default");

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, you can refresh your Battlesnake on your profile page to use your latest configuration. Your 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.

Locate the move method inside Snake.java.

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 moveRequest variable) and make an intelligent decision about where your Battlesnake should move next.

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

(Optional) Running Your Battlesnake Locally

Eventually you might want to run your Battlesnake server locally for faster testing and debugging. You can do this by installing JBang, then running:

jbang snake.java

This will start the Battlesnake server on port 8080.

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.


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.


(Optional) Deploying Your First Battlesnake with Heroku

Deploy

  1. Fork this repo into your GitHub Account.

  2. Clone your forked repo into your local environment.

    git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-java.git
  3. Create a new Heroku app to run your Battlesnake.

    heroku create [YOUR-APP-NAME]
  4. Deploy your Battlesnake code to Heroku.

    git push heroku master
  5. Open your new Heroku app in your browser.

    heroku open

    If everything was successful, you should see the following text:

    {"tailType":"default","color":"#888888","headType":"default","author":"","apiversion":"1"}
    
  6. Optionally, you can view your server logs using the Heroku logs command heroku logs --tail. The --tail option will show a live feed of your logs in real-time.

At this point your Battlesnake is live and ready to enter games!

(Optional) Updating Your Battlesnake with Heroku

After making changes, commit them using git and deploy your changes to Heroku.

git add .
git commit -m "update my battlesnake's appearance"
git push heroku master

Once Heroku has updated you can create a new game with your Battlesnake to view your latest changes in action.

At this point you should feel comfortable making changes to your code and deploying those changes to Heroku!

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.

About

Battlesnake starter using Java 17 with JBang, running Quarkus and works with repl.it and heroku

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published