Battlesnake With Brad Van Vugt

Battlesnake With Brad Van Vugt

Oct 15, 2024

Scott Keck-Warren Brad Van Vugt
In this episode, Scott talks to Brad Van Vugt about Battlesnake.com a competitive online game where your code is the controller. Links: Battlesnake - https://play.battlesnake.com/ HoneyBadger.io - https://HoneyBadger.io 00:00 Intro 00:31 What is Battlesnake? 02:33 What need does Battlesnake fill? 09:31 HoneyBadger 10:20 What technology is used? 14:46 What else should people know about Battlesnake? 15:51 Outro

Transcript

Scott Keck-Warren Scott Keck-Warren 0:05
Hello developers, and welcome to the PHP Architect Community Corner, where we have conversations with members of the web development community. I'm your host, Scott Keck Warren, and today we're talking with Brad Van Voot about battlesnake.com. Brad Van Voot is a proud dad, husband, programmer, feminist, and a Canadian. He runs battlesnake.com and works on growth at Neon. Thank you, Brad, for finding some time to talk to us today.
Brad Van Vugt Brad Van Vugt 0:28
Yeah, thanks so much for having me. I'm glad we could make it happen.
Scott Keck-Warren Scott Keck-Warren 0:31
Absolutely. So the reason I wanted to have you on today is because you're the maintainer of battlesnake.com, which is a really cool service that lets you kind of learn how to do web programming. Can you, can you talk to us a little bit about what battlesnake.com is?
Brad Van Vugt Brad Van Vugt 0:46
Yeah, yeah, at its core, Battlesnake is a multiplayer competitive programming game, and so we invite sort of the developers of all skill levels to come and build a BattleSnake, and then you can enter that BattleSnake into leaderboards and tournaments, and/or you could just play with friends or colleagues or classmates. And basically, you're programming an algorithm to control this snake that plays the game competitively, and you're trying to beat out everyone else who has competing algorithms and competing servers. Yeah, I think one of the things that's really unique about how we built BattleSnake is you can use any technology you want. So, it's not, you know, you're not coding in our web editor like some other things are, but it's really the way that you play is you have to actively deploy a web server that runs your algorithm for you. And so, that makes the spectrum, the solution space is very broad. And so we have developers that are doing many different languages, many different algorithms, many different libraries, many different backends and hosts and that sort of thing. And so you see this really broad spectrum in this community that's filled with developers of all shapes and sizes and backgrounds of experiences.
Scott Keck-Warren Scott Keck-Warren 2:03
Yeah. And so just to help clarify that, because I think the part that I find that's really fascinating is you have snakes, right? And the snakes are battling each other. And in order to to like move, they request some, uh, a file or like an endpoint from a web server or an HTTP server. And then that like directs them. And I thought that was like, just that, that concept was just totally fascinating to me, like as a, as a thing, you know what I mean? So can you, so can you, can you tell us like, how was it that like the, what, what was the initial starting point for needing, or what, what was the need that BattleSnake was fulfilling?
Brad Van Vugt Brad Van Vugt 2:41
Yeah. So BattleSnake really started as sort of like a local developer community thing. I think that if you look at the broader space of, we'll call it developer education or developer learning, if you are starting to program, there's like a million different ways to do that. And a bunch of other, a bunch of services and platforms will take your money. And try to teach you how to do for loops in Python, which is great and that should exist. But the core problem that we saw was like, if you know how to program, if you're an intermediate or senior or above developer, there's nothing for you to like actually apply those skills and try new things and learn new things. You can take courses, you can watch conference talks, you can do that. But like, there's nothing, you're not applying anything. And developers like to learn by building. So we kind of came up with the idea of BattleSnake of like, okay, how do we want to learn new things? Well, we like to learn new things by building projects and applying them. Okay, let's make a sandbox or a problem space that we can all try new things and learn sort of in our own ways. And so it was sort of like me and a group of friends from the local community up here in Canada, kind of came up with the idea of BattleSnake. And then we held— the first version of it was actually we just held like a live event. And we had— we invited like a bunch of friends and we were expecting like, I don't know, like 20 people to show up. And we had like 150 developers come out and just build, like spend an afternoon building BattleSnakes. And then at the end, this really sort of fun— And this was kind of the creation of BattleSnake was like, We were like, well, what if we just run a tournament at the end of the day? It was like, okay, great. So like someone fired up an Excel sheet and put all of our server URLs into it. And then someone else, we were running through the tournament and someone jumped up on stage and started to like shoutcast the games. And so it was like, the Blue Snake is going up into the left corner and, you know, the Python Snake is going down here and the AWS Snakes are failing for whatever reason. And that made it like really fun and engaging. And that was sort of the birth of BattleSnake. And we were like, this is actually really fun, not just for us as developers, but for other folks as spectators as well. And so that kind of kickstarted a series of live events and then eventually into the sort of live platform that exists now.
Scott Keck-Warren Scott Keck-Warren 5:18
Yeah, that's really fascinating. Because I came across it because I went to PHP Tech this last year. And one of the organizers there had— we had a tournament. There was a tournament of of BattleSnakes. And there were only 4 of us, I think, or 5 of us that actually competed, which, you know, wasn't, you know, not bad. But I found it really fascinating because it is, it's like such a, like, I'm very much like, I have a, like, I have a set input gets me a set output, right? Like, that's a lot of my code. And that's how I test code, right? I have inputs goes to outputs. And then this was like, you don't control the inputs. The inputs are so— Random. dynamic and so hard to manage that like testing is like, just like, okay, I'm just gonna throw this out there and see what happens. Right. And it is really just like a fascinating, uh, different way to like challenge my brain when a lot of what I do is just like, what's the input? What's the output? And this was a lot of like, I'm just gonna throw this up on like a droplet and like see what happens and then throw a new version up and see what happens and throw a new version. And that was really like a fun iterative like process.
Brad Van Vugt Brad Van Vugt 6:19
Yeah, I think that speaks to like, and we didn't set out when we decided on the game Snake and sort of competitive Snake, we weren't like, oh, this is really interesting from a competitive perspective. We were like, this is an idea, let's see what happens. But it turns out that like the competitive space of competitive Snake play just in general is like actually really complex. And as programmers, there's like, there's so many different aspects of it that you can work on and you see this reflected in the community as well. And the players is like, You can fine-tune algorithms or heuristic trees or AI agents to play and try to win. But you can also go for code optimization. We have some people that just try to win BattleSnake games with the fewest lines of code, which is great. That's awesome. If that's fun for you, then you should do that. But also go for latency. They're like, I'm going to dig into the Rust HTTP stack and I'm going to figure out where I can squeeze more milliseconds out of this so I can try to make more decisions. So it really, in terms of complexity, there's this deep well of game complexity and competitive complexity, but there's also this whole other side of technical complexity that the community really, really likes to dig into.
Scott Keck-Warren Scott Keck-Warren 7:38
So those of us who competed, we talked about it and The, it's, it's funny to me, like how quickly, like we all came up with some different way of like controlling it. And like one person, like they had like a solution where it was literally like the output came, they like had a tunnel into their laptop and they were literally using the keyboard. Like the keyboard was controlling the snake. And that was like the solution that they came up with. And then somebody else like had ChatGPT spit out a solution and then they like fiddled with that. You know what I mean? It's all, and it's all great ways to learn. It was, it was really fascinating to just hear what happened. So. Yeah.
Brad Van Vugt Brad Van Vugt 8:09
I think that speaks exactly to the crux of what makes BattleSnake so fun. It's like you can solve it in a million different ways with a million different technologies and whatever makes fun for you. This is like when we talk about education, it's not really education. It's like we're giving— I want to give developers an excuse to build something with the technology they've wanted to build with. And that's really what it is. The keyboard-controlled Snake, there's a fun story there. I think this was like the second live event that we ever held. And we were like, let's put, I think it's like a $100 prize up for first place or something. And currently in the current version of the game, you have, I think you have 500 milliseconds to respond, but that originally wasn't the case. We were like, great, we'll give you 5 seconds to respond and you can run all this compute, whatever you want. But in that second tournament that we ran, there was a team that figured out that in 5 seconds, you could WebSocket a game board out to a browser and then do a keyboard input. So it was actually, it was like some, one of the competitors was actually just playing live on their laptop the whole time. And I think they got second place in the tournament. And we were like, great, like good on you. That's, if you figured that out, that's awesome. And then we lowered the timeout to try to limit that. But yeah, I love— hearing of like crazy solutions like that.
Scott Keck-Warren Scott Keck-Warren 9:27
We'll be back with this after this word from our sponsors. Do you want higher clarity in production but don't have the time to earn your degree in observability? Me too. Forget logs, metrics, and traces. Honeybadger Insights is built around structured events. When you send your application logs and other events to Honeybadger, you'll unlock the power of Honeybadger's powerful new querying language, BadgerQL. You can then use BadgerQL to ask any question about your data, get convert any event into a metric, and chart your metrics on a custom dashboard. You can do all of this on Honeybadger's free plan as part of their comprehensive monitoring suite, which includes error tracking, uptime monitoring, status pages, and more. Speaking of error tracking, did you know that an error is really just a first-class event in Honeybadger? In fact, you can use Insights and BadgerQL to explore all of your existing Honeybadger data in new ways. It's pretty cool. Give it a try today at honeybadger.io. That's honeybadger.io. And we're back with Brad Van Voot. Brad, can you talk to us a little bit about the technology that runs BattleSnake?
Brad Van Vugt Brad Van Vugt 10:27
Yeah. So we kind of, we originally planned this for, the original version of BattleSnake was like a monolithic Django app. It was bad. And then we very quickly realized that we needed to rethink that. Now it's kind of split up into essentially 3 pieces. There's a game engine, which is open source, and it's written in Go. It's super highly concurrent. And that's what powers all the request concurrency. And that runs— it's running in GCP right now on like a Kubernetes cluster, and it's auto scaling as it needs to. So that's like the high performance piece of it. That was written by Go developers that are a lot smarter than I am, frankly, but it's done really well. And then the other 2 pieces that exist are sort of like, there's a primary Django app that kind of glues everything together and schedules tournaments and schedules leaderboards and does all the scoring algorithms. That's a lot— the real-time demands on that are a lot lower. And then the 3rd piece that we have is actually the game board. So the game board is like a whole separate repo. I think it's done in SvelteKit. because we rebuilt it a couple of— we rebuilt it like a year ago. But the whole visualization that you see in the real-time visualization is completely open source. And so we have developers that run variations on that, and you can run the game board locally, and you can replay tournament games or leaderboard games locally if you wanted to put a different UI on top of it for your your friend group or your classmates or whoever you're playing with. And so we see lots of really cool variations there. So a lot of it is open source. Most of it is open source. And the other important thing there in how it's built is the— I talked about the game engine. The rules for deciding who wins a game is also open source. And this was a goal of ours because early on we get a lot of, well, this didn't resolve the right way, or I'm not sure that— There's lots of questions from developers questioning, is the game game engine working properly or not? Or how do I understand this complex scenario and how it played out? And so we realized right away that if we build this to scale, all of that can just be open source. And so we don't answer technicalities over the rules anymore because we just say, hey, go look at the code and you can trace it through and see exactly what happened.
Scott Keck-Warren Scott Keck-Warren 12:59
So do you ever have people that come back and say, I should have won, but there's a bug in line 100?
Brad Van Vugt Brad Van Vugt 13:03
We have, but Like 95% of the time it's their own, it's their own bug. Um, but we have, we have had people that have found and fixed bugs in the, in the, in the game engine. Uh, it's usually around like very strange edge cases and sort of timings.
Scott Keck-Warren Scott Keck-Warren 13:16
I, I, the thing that you just like talking about all that, I find it really fascinating because you basically have like 3 different technologies that all do like their thing well, right? And you're like, this solves this problem well, this solves this problem well, this solves this problem. And like, instead of just saying, we know this, we're just going to use this. So that's, that's really like a fascinating piece of this, right? Is like, you know, you're picking the right technology for the right solution.
Brad Van Vugt Brad Van Vugt 13:38
I think it also, yeah, like 100%. And I think it also was designed a little bit, or like some of our intent with doing that was to, this is more of a far-fetched dream, but like, we want the sort of, you know, BattleSnake players start playing the game, start building a snake, and then eventually they graduate to contributors or some of them graduate to contributors. And not all of them are like, you know, deep Go concurrency developers. Some of them develop in JavaScript and build UIs, and that's great. And some of them build backend apps, and that's great. And so we intentionally wanted to like create different pockets and different contribution points. Again, speaking to the idea of like our developer community is so diverse, how do we serve a contribution model that kind of can speak to everybody?
Scott Keck-Warren Scott Keck-Warren 14:27
I love like when I talk to like a community project like this, and it's Not only is it, is there, um, you know, like there, there is a, there's a community that's helping you build it as well as using it. Right. And that's, that's always like a nice ecosystem to have as opposed to, you know, you have one person that's making all the decisions.
Brad Van Vugt Brad Van Vugt 14:43
Yeah, definitely. Definitely.
Scott Keck-Warren Scott Keck-Warren 14:45
So is there anything else that you'd like to direct our listeners to before I let you go today?
Brad Van Vugt Brad Van Vugt 14:48
Uh, yeah, I mean, definitely if you're interested in, in playing BattleSnake, it's at play.battlesnake.com. Or if you just search for BattleSnake, you'll find it. The one thing I will mention is the project itself is run entirely off GitHub sponsorship. So we rely on the community to— and our community is wonderful and lovely and giving and incredibly supportive. And so if you're looking for a good GitHub project to sponsor, BattleSnake's not a bad one. And then we also have a Discord. So if you want to check out what people are doing with their snakes or how you know, what the current meta is, uh, you're welcome to, to join the BattleSync Discord and hang out with us there.
Scott Keck-Warren Scott Keck-Warren 15:29
As a user of it who hasn't been that involved in the community, it is like a really fun, like, I want, I need to, like, I, I have some time, let me just like fiddle around with something for like 2 hours thing to do, like to just sit down and kind of play with it. So thank you, uh, again for finding some time to talk to us and thank you for, for making this available for the community.
Brad Van Vugt Brad Van Vugt 15:48
Yeah. Thanks so much for having me.
Scott Keck-Warren Scott Keck-Warren 15:50
Thank you. I have to say another heartfelt thank you to Brad for all of his time, and thank you for listening to our podcast. If you're not already a subscriber, make sure you subscribe with whatever your preferred method is so you get episodes as soon as they're released, and maybe share this post with a coworker so they know about BattleSnake too. This podcast is available both in an audio version on the PHP Architect website, as well as a video version on our YouTube channel. This is Scott Keck Warren for the PHP Architect channel signing off and reminding you to keep listening, keep coding, and keep reading.