Take your Python skills to the next level with Battlesnake
Tags: python, opensource, twitch
Published: 2021-07-26 06:05:17

So you want to learn Python? In fact if you want to learn _any_ kind of coding, one of the best things to do, is work on a project.

I came across [Battlesnake](https://play.battlesnake.com/) through a friend. I can definitely say this has been a super fun journey. Not only have I met some really cool people through live streaming this project, I've had a lot of fun upping my Python skills, and seeing the results of my coding.

## What is Battlesnake?

Battlesnake is a coding competition where you program a snake (remember the [old Nokia phone game](https://www.playclassicgames.net/snake-nokia)) and compete against others. Your snake is hosted on a server and requests are sent between the Battlesnake server and your server. This means you don't need to sit down and code against someone. Program your snake, upload the code, and watch your snake battle against others. Battling happens constantly and you can go back and watch your games whenever you want.

A Battlesnake game consists of four snakes on a grid. The last snake standing wins. You must ensure your snake doesn't run out of health, so you need to eat the food on the board. Your snake also can't run off the board or run into other snakes, including yourself. How you program your snake is up to you.

![Battlesnake game](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5uwy98odqtqrf83vthcd.gif)

## Programming your Battlesnake

One of the coolest things about Battlesnake is how easy it is to get going. The [Battlesnake Docs](https://docs.battlesnake.com/) explain how to get started with the click of a button. If you really want to dive into the code, you can go straight to the GitHub repo and clone or fork the starter snake.

{% github BattlesnakeOfficial/starter-snake-python %}

Once you have your repo cloned or forked, you can start coding. The Docs has a tonne of information about how to code your snake and what kind of requests the Battlesnake server will ask your server.

How you program your snake is up to you. What problems do you want to focus on and how? Do you want to avoid the walls first? Do you want to avoid other snakes second? What strategy do you want to win? Will you check your snake's games and refine the code? What about using machine learning?

When you have your snake 'ready' you can enter it into a league. The leagues are really fun for seeing just how well your snake performs. It's awesome going back to the league's ladder board every few days and checking on where your snake sits on the ladder. You can also rewatch games to see how your snake wins or loses. This is useful for deciding how to refine your code and what strategies to build next.

![Sneaking into Gold](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwrrzbc6sun4t4ax0h9f.JPG) 

If you like Python, this is a great project for upping your Python skills.

## Using languages other than Python

What if you want to do something other than Python? Battlesnake has you covered. You can write your Battlesnake in any language. There are starter snakes [starting code](https://docs.battlesnake.com/references/starter-projects) for a bunch of popular languages:
- Python
- Go
- JavaScript
- TypeScript

Those are the official starter snakes made by the Battlesnake team. There are also lots of [Community Starter projects](https://docs.battlesnake.com/references/starter-projects) for languages including:
- TypeScript
- Node.js
- Java
- Ruby
- C#
- Scala
- PHP
- Rust
- C++
- Node

So choose your weapon - I mean, code - and get started. It's such a great community to be a part of and there's even live streamed league finals on [Twitch](https://www.twitch.tv/BattlesnakeOfficial). Check it out and enter your snake now. Plus there's lots of challenges to compete in if you don't want to get too competitive against others.

![Avoid self win](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e33ke5pszumrtb1omc99.gif)

This one above is a challenge to avoid yourself for 100+ turns.

If you'd like to program along with me, [check out my beginner friendly stream](https://www.twitch.tv/videos/1063852424) where I setup my snake. Or you can join me for a live session when I'm next [on Twitch](https://twitch.tv/MishManners).