Battlesnake | Profitable Software program


I’ve been performing some leisure programming at play.battlesnake.com. It’s a sequence of on-line leagues the place you enter a program to play aggressive ‘snake’.

The principles are fairly easy:

  • eat meals to develop
  • die of hunger if you happen to go too lengthy with out consuming
  • die if you happen to collide with a wall or the physique of one other snake
  • die if you happen to collide head-on with one other snake that if of equal dimension or larger
  • final snake standing wins the match

There are additionally some variants, corresponding to ‘royale’ the place hazards transfer in from the partitions.

You may program your snake in just about any language and host it the place you want. When a match begins your program recieves JSON knowledge with the board state and has 500 milliseconds to return both “left”, “proper”, “up” or “down” for every transfer. You may write one thing super-simple (transfer to the closest meals, keep away from different snakes) or you may get as advanced as you want (machine studying or full recreation tree with alpha-pruning).

I’ve written my snake in Python (which appears applicable) and host it on a free replit.com account. It makes use of a sequence of heuristics to resolve it’s subsequent motion. It makes use of flood fill to evaluate how a lot area is on the market and A* for path discovering.

You may see my snake (‘RhinoCrocoPede’) in motion under, it’s the purple one:

You too can see it extra clearly right here.

On the time of writing RhinoCrocoPede is 132nd within the world league (out of 450) and steadily rising.

The Battlesnake documentation is sweet and I used to be capable of get the starter Python/Replit snake up and operating in quarter-hour or so. I then simply constructed on that. Replit is a pleasant on-line IDE. I did have points with the free Replit account timing out. However I mounted this with a 90 day free improve code I discovered on the Battlesnake discord. This allowed me to set my REPL as ‘all the time’ on and ‘boosted’. I nonetheless have a reasonably lengthy ping time to the server (which is in California). This eats into my 500 milliseconds. However the time remaining is loads for my present heuristic method, even in Python.

If I needed to get actually critical I might rewrite my snake in C++, use a full recreation tree or Monte Carlo method and host it on a quick server close to the battlesnake server (to scale back ping time). However it’s only a little bit of enjoyable and I don’t suppose I’ll get that critical.

My son has additionally written his personal snake, which has been helpful programming expertise for him.

Battlesnake is absolutely slick and effectively accomplished. Should you really feel like performing some leisure programming, I like to recommend you give it a strive.





Source_link

Leave a Reply

Your email address will not be published.