[{"data":1,"prerenderedAt":445},["ShallowReactive",2],{"footer-primary":3,"footer-secondary":93,"footer-description":119,"ready-set-battlesnake-start":121,"ready-set-battlesnake-start-next":175,"sales-reps":193},{"items":4},[5,29,49,69],{"id":6,"title":7,"url":8,"page":8,"children":9},"522e608a-77b0-4333-820d-d4f44be2ade1","Solutions",null,[10,15,20,25],{"id":11,"title":12,"url":8,"page":13},"fcafe85a-a798-4710-9e7a-776fe413aae5","Headless CMS",{"permalink":14},"/solutions/headless-cms",{"id":16,"title":17,"url":8,"page":18},"79972923-93cf-4777-9e32-5c9b0315fc10","Backend-as-a-Service",{"permalink":19},"/solutions/backend-as-a-service",{"id":21,"title":22,"url":8,"page":23},"0fa8d0c1-7b64-4f6f-939d-d7fdb99fc407","Product Information",{"permalink":24},"/solutions/product-information-management",{"id":26,"title":27,"url":28,"page":8},"63946d54-6052-4780-8ff4-91f5a9931dcc","100+ Things to Build","https://directus.io/blog/100-tools-apps-and-platforms-you-can-build-with-directus",{"id":30,"title":31,"url":8,"page":8,"children":32},"8ab4f9b1-f3e2-44d6-919b-011d91fe072f","Resources",[33,37,41,45],{"id":34,"title":35,"url":36,"page":8},"f951fb84-8777-4b84-9e91-996fe9d25483","Documentation","https://docs.directus.io",{"id":38,"title":39,"url":40,"page":8},"366febc7-a538-4c08-a326-e6204957f1e3","Guides","https://docs.directus.io/guides/",{"id":42,"title":43,"url":44,"page":8},"aeb9128e-1c5f-417f-863c-2449416433cd","Community","https://directus.chat",{"id":46,"title":47,"url":48,"page":8},"da1c2ed8-0a77-49b0-a903-49c56cb07de5","Release Notes","https://github.com/directus/directus/releases",{"id":50,"title":51,"url":8,"page":8,"children":52},"d61fae8c-7502-494a-822f-19ecff3d0256","Support",[53,57,61,65],{"id":54,"title":55,"url":56,"page":8},"8c43c781-7ebd-475f-a931-747e293c0a88","Issue Tracker","https://github.com/directus/directus/issues",{"id":58,"title":59,"url":60,"page":8},"d77bb78e-cf7b-4e01-932a-514414ba49d3","Feature Requests","https://github.com/directus/directus/discussions?discussions_q=is:open+sort:top",{"id":62,"title":63,"url":64,"page":8},"4346be2b-2c53-476e-b53b-becacec626a6","Community Chat","https://discord.com/channels/725371605378924594/741317677397704757",{"id":66,"title":67,"url":68,"page":8},"26c115d2-49f7-4edc-935e-d37d427fb89d","Cloud Dashboard","https://directus.cloud",{"id":70,"title":71,"url":8,"page":8,"children":72},"49141403-4f20-44ac-8453-25ace1265812","Organization",[73,78,84,88],{"id":74,"title":75,"url":76,"page":77},"1f36ea92-8a5e-47c8-914c-9822a8b9538a","About","/about",{"permalink":76},{"id":79,"title":80,"url":81,"page":82},"b84bf525-5471-4b14-a93c-225f6c386005","Careers","#",{"permalink":83},"/careers",{"id":85,"title":86,"url":87,"page":8},"86aabc3a-433d-434b-9efa-ad1d34be0a34","Brand Assets","https://drive.google.com/drive/folders/1lBOTba4RaA5ikqOn8Ewo4RYzD0XcymG9?usp=sharing",{"id":89,"title":90,"url":8,"page":91},"8d2fa1e3-198e-4405-81e1-2ceb858bc237","Contact",{"permalink":92},"/contact",{"items":94},[95,101,107,113],{"id":96,"title":97,"url":8,"page":98,"children":100},"8a1b7bfa-429d-4ffc-a650-2a5fdcf356da","Cloud Policies",{"permalink":99},"/cloud-policies",[],{"id":102,"title":103,"url":81,"page":104,"children":106},"bea848ef-828f-4306-8017-6b00ec5d4a0c","License",{"permalink":105},"/bsl",[],{"id":108,"title":109,"url":81,"page":110,"children":112},"4e914f47-4bee-42b7-b445-3119ee4196ef","Terms",{"permalink":111},"/terms",[],{"id":114,"title":115,"url":81,"page":116,"children":118},"ea69eda6-d317-4981-8421-fcabb1826bfd","Privacy",{"permalink":117},"/privacy",[],{"description":120},"\u003Cp>A composable backend to build your Headless CMS, BaaS, and more.&nbsp;\u003C/p>",{"id":122,"slug":123,"vimeo_id":124,"description":125,"tile":126,"length":127,"resources":8,"people":128,"episode_number":135,"published":136,"title":137,"video_transcript_html":138,"video_transcript_text":139,"content":8,"status":140,"episode_people":141,"recommendations":164,"season":165,"seo":8},"08d92984-9c2a-496d-a748-2ba54e64e378","start","925179495","In the first episode of the season, Kevin and Andrew bring you on the journey of learning about Battlesnake by building an (arguably) capable autonomous snake based on Node.js. ","8b37f7c7-31a2-4f7f-9293-1b8955f77ddb",111,[129,132],{"name":130,"url":131},"Kevin Lewis","https://directus.io/team/kevin-lewis",{"name":133,"url":134},"Andrew MacLean","https://twitter.com/andrewdmaclean",1,"2024-03-21","Start","\u003Cp>Speaker 0: Hello, everyone, and welcome to Ready, Set, Battlesnake. I am so thrilled for this season to be happening, bringing together a few of my interests all at the same time, including hanging out with my good friend, Andrew. Hello, Andrew.\u003C/p>\u003Cp>Speaker 1: Hey, Kevin. How are you?\u003C/p>\u003Cp>Speaker 0: I am all the better for seeing you. Would you like to tell us what the hell we're gonna be doing for the next 4 episodes?\u003C/p>\u003Cp>Speaker 1: Yeah. That's a great question. So we are gonna be exploring the wonderful world of Battlesnake. More on that in just a minute. We're gonna be looking at how Battlesnake works.\u003C/p>\u003Cp>We're gonna be looking at how Battlesnake integrates with some other really cool technologies out there. And, hopefully, by the end of this 4 week series, you'll have a Battlesnake or 4 episode series. You'll have a Battlesnake that is ready to go and to jump in and start, yeah, start competing and playing around and learning some new technologies.\u003C/p>\u003Cp>Speaker 0: Or you can just watch us fumbling around. That's also totally fine too. Also very No. I think what might be good is let's talk about what Battlesnake is and then talk about, like, our affiliations with Battlesnake. Probably feels like a good thing to throw out there.\u003C/p>\u003Cp>But let's start because we've said the phrase Battlesnake one too many times to not jump into what it is. What is Battlesnake, Andrew?\u003C/p>\u003Cp>Speaker 1: Alright. So if you have ever heard of the old classic game Snake, like that old Nokia snake game where you, sort of control the snake to go around on a screen and eat little berries and get longer, and you try to avoid yourself and avoid the walls and avoid other snakes if they're on the board. Well, Battlesnake is that same idea, but moved around a little bit into the developer space. So it's a really cool way for developers to explore new technologies, new frameworks in this kind of technology agnostic way. So you actually, create a web server that responds to the Battlesnake API, and you can crawl control a snake using code to battle or compete against other snakes in that kind of same gamified way, but, in kind of way more fun for developers.\u003C/p>\u003Cp>Speaker 0: And a few interesting notes here. So firstly, unlike snake on your Nokia, multiple snakes on the board at once, and you're basically trying to outlive everyone else. You die in the same ways, but there are multiple snakes just like this on the screen now. And because what you're doing is implementing an API, it means it's pretty technology agnostic as long as you can host a web server that can have a couple of specific endpoints that accept requests and then responds in a specific way. It almost doesn't matter what technology you use, which is pretty cool.\u003C/p>\u003Cp>And so we're going to be building this over a few episodes. Today, we're just gonna be focusing on, like, the vanilla Node. Js starter snake and challenges so we can introduce you to this wonderful world. You're gonna love it. And then we'll play around with, like, running Battlesnake in a director's project with directors automate, which should be really fun.\u003C/p>\u003Cp>And then, towards the end, we're going to also integrate dev cycle, which brings me on to a probably good point here, affiliations. Andrew, do you wanna start with, like, your history with this project?\u003C/p>\u003Cp>Speaker 1: Yeah. Sure. So so I actually started with Battlesink back in 2020. So I joined fairly early on in in the the official Battlesink company. BattleState had been around for about 5 years before I joined the team, and it started out as a community project here on the West Coast of Canada.\u003C/p>\u003Cp>It was a big sort of hackathon event that happened here where a bunch of people have gotten to a room for a couple of days and built battle stakes and competed in sort of live events. I joined the team in 2020 as sort of their first community manager as we were kind of transitioning, as many were in 2020, into that online world. And so we sort of transitioned the whole kind of BattleState concept into an online platform that folks could engage with around the world. In 2023, Battlesnake, was acquired by another Canadian startup called Dev Cycle, where I currently work as their developer advocate. And so I still get to play around with Battlesnake a lot and work with a lot of the great people that were on the Battlesnake team.\u003C/p>\u003Cp>And and it's actually like the the pre dev cycle times that, Kevin, you and I met, even though technically, we never met in person until Not\u003C/p>\u003Cp>Speaker 0: in person yet. Mhmm. Absolutely. And then, I, Battlesnake as part of going online, run a bunch of livestream series. It was a really good is still, but was really then in its peak, like, peak pandemic.\u003C/p>\u003Cp>We're doing everything online, ton of live stream series, including the competitive leagues, shows which discuss different algorithms that can be implemented. And this one show called Coding Badly, which was run with me and my friend, Joe. And this is kind of a spiritual successor to Coding Badly, I think. No offense, Andrew. I think that's probably gonna be the vibe the vibe we go for.\u003C/p>\u003Cp>So I love Battlesnake. And what's really cool about and we'll discover throughout today is at the very core, you know, there are some very simple rules. Don't hit into walls, don't hit yourself, Don't hit other snakes. Don't run out of life like it. Get food when you need it.\u003C/p>\u003Cp>But once you start to get options, you can really make some choices here. You know, you can say if left and right are both viable options, is there an algorithmically, beneficial way based on certain strategies to go? Do I box myself off, but now we only have so much life? Do I try and find food as quickly as possible at all cost to also starve out other snakes and so on? So all of this is implemented in code, and then when the games actually happen, your hands off.\u003C/p>\u003Cp>You know, your your algorithm takes over and makes decisions. So, yeah, I think that's that I I think that's most of Battlesnake. Any other thoughts, Andrew, before we crack on?\u003C/p>\u003Cp>Speaker 1: I mean, let's, I mean, let's jump into the let's jump into the docs because I think they're gonna give us a good idea of kind of the some of the things that maybe we missed. And I think, actually, I'm I'm not a 100% sure. I haven't been in the docs in a while. I may still be featured in, like, the what the heck is Battlesnake doc. So I'm very interested to see if we\u003C/p>\u003Cp>Speaker 0: can get it. Shortly.\u003C/p>\u003Cp>Speaker 1: Am I there? The real question. I'm not oh, wait. No. Hold on.\u003C/p>\u003Cp>Quick start? There I am. I'm definitely I'm definitely in the quick start. I know this. Am I still here?\u003C/p>\u003Cp>Speaker 0: We'll we'll throw this video into the resources that accompany this video on Directus TV if you wanna go and watch it in full. Awesome. Yeah. So when you click on that,\u003C/p>\u003Cp>Speaker 1: what is dev cycle, it brings you over to the dev cycle documentation, and this documentation is fantastic. One of the things that Kevin was talking about, a lot of those sort of specific things that you can and can't do, if you wanna kinda figure out what that's all about, you can really a great place to go is actually checking out the game rules. And so this is where we start to look at things like this collision idea. So, like, self collisions and body collisions and head to head and who wins in these different situations, and then also giving information about some other things that are really important in this kind of gameplay. So you have a starting position in the game.\u003C/p>\u003Cp>We'll talk a little bit more about what that looks like kind of as we go through. You have health. That's a dynamic in this game as well. There's food spawns and hazards, and we're not going to get to a lot of that stuff necessarily today. We're gonna see that kind of as we go on.\u003C/p>\u003Cp>Yeah. But checking out this kind of game rule section is a great way to, like, get a a solid understanding of the idiosyncrasies, I guess, that exist in Battlesnake over sort of the, the the traditional snake game. The other great thing is this rules repository. So, like, all of these rules are actually in, an awesome GitHub repository called Battlesnake Rules. And so if you would rather not watch a video or if you'd rather just do, like, a different kind of deep dive, you can actually, like, jump into the rules repository, which is public, and you can go through and kinda discover a lot of these things yourself.\u003C/p>\u003Cp>It's all built out in Go. So if you're not a Go developer, then maybe not for you, but it's a useful place to kinda check out all of this written in code.\u003C/p>\u003Cp>Speaker 0: And, yeah, and that was gonna be my clarifying point. This isn't pros. This isn't written out rules. But this is codified rules that actually run within the Battlesnake engine. So you can get right in there and understand again the intricacies of how it all works, which is really cool.\u003C/p>\u003Cp>I remember possibly in a coding badly episode, definitely in a battlesnake stream in the past generating, battlesnakes that that, like, actively hook into this rule logic very directly, something like that. Okay. So how do we get started? I think we're gonna stick with node. Doesn't matter what language you you use in the real, but, you know, given that directives is all JavaScript view node, and that's at least what I know.\u003C/p>\u003Cp>That feels like a good place to start.\u003C/p>\u003Cp>Speaker 1: Yeah. I'm with you. 100%. So couple places you can go. Obviously, the quick start that is here.\u003C/p>\u003Cp>So, basically, anywhere you go in the documentation, you'll find the quick start. This one is set up in Python. So, like, if you watch the video and you've never programmed in Python, it's still kind of valuable, and this will kind of walk you through the game logic. But it also does, in this kind of quick start area, let you choose from different snakes. So I highly recommend if you're just getting started with Battlesnake, click on that quick start, and you'll get the kind of fundamental understanding here.\u003C/p>\u003Cp>So when we say you are building a web server server that is kind of serving as your battle snake and it's it's interacting with the battle snake API, this is exactly what's actually happening here in this sort of representation here. So, the game engine is querying your web server where your battlesnake is, and your battlesnake server is returning a response. That response can only be 1 of 4 things, up, down, left, or right. That's right. Right.\u003C/p>\u003Cp>That you received from the game engine, and then you just are kinda repeating this process over and over and over again. So game engine is sending something to your server. Your server is sending something back to the game engine over and over and over again. And, I guess one of the the kind of gotchas here is, the web servers only have 500 milliseconds to respond. And so if you are sort of some people run these on Raspberry Pis and some people or some people run them on you still run them on Heroku servers.\u003C/p>\u003Cp>And so one of the things that we would tell people is make sure you go and, like, do something on your Heroku server or your\u003C/p>\u003Cp>Speaker 0: Just to see how the code stop at the beginning.\u003C/p>\u003Cp>Speaker 1: Yeah. Exactly. But, but yeah. And and, Kevin, I don't know if I ever told you. Do you know what are the reasons why this 500 millisecond rule was implemented?\u003C/p>\u003Cp>Have you ever heard this story?\u003C/p>\u003Cp>Speaker 0: No. Sorry. I just realized. I don't think you can see me. So I I'm doing a No.\u003C/p>\u003Cp>Speaker 1: I can. No. No.\u003C/p>\u003Cp>Speaker 0: I can\u003C/p>\u003Cp>Speaker 1: see that. I'm, like, down here. No. I can't. So so I, so in one of the early kind of days of the battle sync competition, before they had this 500 millisecond, like, response time that was there, somebody realized that it was actually faster to respond with a physical keyboard or a game controller than it was to send code back.\u003C/p>\u003Cp>Love. And so somebody actually went and built a Battlesnake that was hand controlled, and then they would respond in real time. And it's interesting because I think they did fairly well. And at the end of it, it wasn't like, no. You did the wrong thing.\u003C/p>\u003Cp>It was like, great. You kind of you broke the rule, and now we or or or, like, defined the new rule for us. And so\u003C/p>\u003Cp>Speaker 0: That's funny.\u003C/p>\u003Cp>Speaker 1: I think you could technically still do it, but, you'd have to have some pretty fast thumbs.\u003C/p>\u003Cp>Speaker 0: In planning for this series, not to spoil it, but we have spoken about what it might mean to change strategy, like, mid game. You know, there are there are ways we can achieve this. It was not real time. That's really funny. And the interesting thing about that limit is it really forces you to be computationally efficient as you start to build more complex things.\u003C/p>\u003Cp>At the beginning, literally, it doesn't matter. You're as long as your server can physically respond in that time, you know, it it doesn't matter. But what you can do with things like at the beginning of a game, spin up some kind of machine learning or artificial intelligence resource, and then per move, you can call on it, but you have to do it very efficiently. So are we gonna start with a starter snake, or are we gonna start from 0?\u003C/p>\u003Cp>Speaker 1: No. No. I think we're I think I think let's start with a starter snake because that's what I think most people are gonna do here. Perfect. And so we'll go to kind of the first step.\u003C/p>\u003Cp>We're gonna choose our starter project. I'll just open this up in a new tab here. And what I kinda love here is, and I was talking to Kevin before the the show started, is like, so I'm running on a Chromebook right now. So if you're sort of a newer software developer, and you're, like, just getting exposed to this world, and you're, like, I don't have a device that can run this. If you can run a Chrome browser, you can run this.\u003C/p>\u003Cp>Speaker 0: Absolutely.\u003C/p>\u003Cp>Speaker 1: I mean, if you wanna have, like, a crazy setup, like, some people have, like, stand alone servers that run their state, You totally can, but you definitely do not need to do that to kinda get started with this.\u003C/p>\u003Cp>Speaker 0: No. Yeah. Not at all.\u003C/p>\u003Cp>Speaker 1: And so what's also great here too is so you can see these are the official starter stakes that are up on the screen. Yes. They are up on the screen. I'm gonna zoom in a little bit. I'm gonna try and zoom in a little bit.\u003C/p>\u003Cp>I'm so used to, like, the Mac keys, so I always click the I've used a Windows keyboard on a Mac device, so I'm always hitting the Windows key. Anyways, so You can\u003C/p>\u003Cp>Speaker 0: you can remap them. That's what I had to do. I have a German keyboard on my physical MacBook. I'll just remap the keys in it. Just a few keys on as they're printed, but you just get used to it.\u003C/p>\u003Cp>Oh, I like that.\u003C/p>\u003Cp>Speaker 1: I should do it. I feel like I've tried it before and it just didn't work. Anyways, not important. So, 5 starter snakes you can start with, which are, like, officially supported starter snakes. So Python, Go, Rust, TypeScript, and then the last one there, JavaScript is what we're gonna look at today.\u003C/p>\u003Cp>But if you're like, I really wanna do an f sharp snake, there is an f sharp snake for you there. And there's some really cool ones that have been defined in, like, some really, like, interesting languages and setups. Totally worth checking out. But today, we're gonna jump into the JavaScript official snake.\u003C/p>\u003Cp>Speaker 0: Lovely.\u003C/p>\u003Cp>Speaker 1: And what's awesome about these is so you can run these on your own infrastructure. So these are all templates that are set up on there. So you're welcome to run them on there. But we do have these set up ideally if everything works out still. I have not run one of these starter stakes in a while.\u003C/p>\u003Cp>Speaker 0: That makes sense. See if\u003C/p>\u003Cp>Speaker 1: everything works well, is you can just run on Replit. It's just a really simple Node. Js and express server, and, like, there's Docker files for external things, but everything runs right out of the box if everything goes according to plan, which it almost never does. So shall we click the button to show you what?\u003C/p>\u003Cp>Speaker 0: Why would you say that? Now it's all gonna go pear shaped.\u003C/p>\u003Cp>Speaker 1: I know. You say that. No. See, now it goes perfect. You gotta call it out.\u003C/p>\u003Cp>Right? You gotta call out to that\u003C/p>\u003Cp>Speaker 0: You gotta manifest it. And this is gonna be we're gonna nail it. There's not gonna be any any any errors. And I'll Well Battle Snake's gonna win the league.\u003C/p>\u003Cp>Speaker 1: What's that saying, though? It's like break a leg. Right? You say break a leg before they go on the stage because you're, like, saying the bad thing that might happen. I feel like it's the same thing here.\u003C/p>\u003Cp>If you just say, like, this is not gonna work at all, it works perfectly.\u003C/p>\u003Cp>Speaker 0: Allegedly. Let's find out. We're gonna see what happens.\u003C/p>\u003Cp>Speaker 1: Alright. So we're gonna click here. We'll see if I'm logged in. I have a feeling that I'm not.\u003C/p>\u003Cp>Speaker 0: You're not.\u003C/p>\u003Cp>Speaker 1: I'm not. But I don't think it really mat I think it'll still spin up if I'm not logged in. We'll find out.\u003C/p>\u003Cp>Speaker 0: We'll see\u003C/p>\u003Cp>Speaker 1: what happens. Nope. I have to log in. That's all good. We've follow look at that.\u003C/p>\u003Cp>I didn't even know we had followers right now.\u003C/p>\u003Cp>Speaker 0: Alright. I'm gonna close you\u003C/p>\u003Cp>Speaker 1: because we don't need you right now. I'm gonna close you. Yeah.\u003C/p>\u003Cp>Speaker 0: And then when we when we get into REPL, it will bump the font size up significantly, I think. Yeah.\u003C/p>\u003Cp>Speaker 1: So, yeah, it's this easy. So we're literally just clicking on that fork. We're gonna do an auth zero sign in. Hopefully, we can skip past the stage where I'm gonna put my password. Let's go.\u003C/p>\u003Cp>I think Toby Flender snake is still on Replit 2, which is my which is my battle snake.\u003C/p>\u003Cp>Speaker 0: Oh. This is what this is what\u003C/p>\u003Cp>Speaker 1: I knew was gonna happen.\u003C/p>\u003Cp>Speaker 0: Alright. But you're log but you're wait. You're not logged in. It it hasn't logged you in.\u003C/p>\u003Cp>Speaker 1: Oh, weird. That's weird. Alright. Let's log in again. Let's go log in.\u003C/p>\u003Cp>Oh, I love it. All the errors, even at the authentication stage, we're running. This does not bode well. Oh, you know what it is? I think it's because I'm like, I need to auth with GitHub.\u003C/p>\u003Cp>That's probably what it is. I do have it on that email, but I'm not auth with GitHub. So let's go do that.\u003C/p>\u003Cp>Speaker 0: Oh, I hate that sometimes when you log in with, like, an SSO provider, but your email address is the same with that SSO provider and you're like, I don't I don't know which which system. Did it work this time? There we go. Okay.\u003C/p>\u003Cp>Speaker 1: Okay. So let's go. So we're in here, and I probably got a bunch of snakes in here. We'll go back over, and we'll jump into our starter projects again. We'll jump back into our JavaScript snake.\u003C/p>\u003Cp>And so I've logged in now. Don't need to worry about billing, but this should be a much more straightforward process. I love I said everything is gonna go incredibly terribly. And even at the auth stage, I definitely have jinxed this.\u003C/p>\u003Cp>Speaker 0: I'm not saying I told you so, but I'm certainly thinking it.\u003C/p>\u003Cp>Speaker 1: Alright. So here we go.\u003C/p>\u003Cp>Speaker 0: So this is the this is\u003C/p>\u003Cp>Speaker 1: the snake. I mean, let's get it in the template right now. Yeah. What do we wanna call this snake?\u003C/p>\u003Cp>Speaker 0: We're gonna call this when you call it something does does the dev cycle mascot have a name? His name's ToggleBot. So I don't know. Do we\u003C/p>\u003Cp>Speaker 1: call it, like, we could call it ToggleBot. We could also call it, like, coding badly rebirth. We could call it, we could call it, let's\u003C/p>\u003Cp>Speaker 0: call it let's call it ready, set, battlesnake.\u003C/p>\u003Cp>Speaker 1: Ready, set, battlesnake. Alright. Let's see.\u003C/p>\u003Cp>Speaker 0: I was worried you're gonna be, like, does the does the rabbit have a name? Does the director's rabbit have a name? As far as I'm aware, it doesn't. So set myself in a losing battle there. Let's use the template.\u003C/p>\u003Cp>Speaker 1: I'm very disappointed. To you.\u003C/p>\u003Cp>Speaker 0: Could be right. Could be right.\u003C/p>\u003Cp>Speaker 1: Here we go. So it's forking. If you've never used Replit before, by the way, amazing cloud based IDE, super powerful, integrates with all of the things that you're already using, but also has a lot of inbuilt features. If you've used things like so if you've used Gitpod, which is, or Codespaces, which are sort of in\u003C/p>\u003Cp>Speaker 0: the Code sandbox is another. Code sandbox.\u003C/p>\u003Cp>Speaker 1: Yes. Code sandbox. I find, somebody described it to me recently though that Replit is kind of like the Google Docs or, like, Google Suite of, like, cloud IDEs. It's just, like, very accessible. Mhmm.\u003C/p>\u003Cp>Speaker 0: Yeah. Bump your font size up. Let let's let's make that text more accessible because I can't read the damn thing.\u003C/p>\u003Cp>Speaker 1: Alright. And I already broke stuff. There we go. Let's zoom in. Wonderful.\u003C/p>\u003Cp>Alright. So let's look at the files that we have here before we start messing around with anything. So it immediately brings us into our index dotjs file. The only other two things that we have in here, ignoring, like, our our package and all the rest\u003C/p>\u003Cp>Speaker 0: of that stuff,\u003C/p>\u003Cp>Speaker 1: are our readme, which is gonna kinda give you, like, things to do, which we're gonna be looking at in that sort of quick start. And then we've got our server dotjs, And this is basically, doing what we described earlier with those different responses that you can do to the Battlesnake API. So there is the just sort of, like, base level. And what what do you call that? Like, the standard with nothing else out of it?\u003C/p>\u003Cp>Speaker 0: The site.\u003C/p>\u003Cp>Speaker 1: There you go. No. No. I mean, like, the the actual just like a slash. Like, no additional\u003C/p>\u003Cp>Speaker 0: Oh, sorry. Sorry. You're referring to that. I would call that the root route.\u003C/p>\u003Cp>Speaker 1: Boom. Root route. So, like, your root route, and we'll talk about kind of what all these things do in a minute. And then you've got your start post route. You've got your move, your end, and then we've got a bunch of other little stuff here, including a console log that actually says your battle tank is running.\u003C/p>\u003Cp>Speaker 0: And if I may just kind of embellish this a little bit. So this main endpoint that we care about is this move endpoint. That is the endpoint that will receive board states and ultimately has to respond with a direction. You'll notice there are these other ones. So this route endpoint handler, route handler there, that will respond with information about your snake.\u003C/p>\u003Cp>We'll do that in due course. But the start and end are interesting. We mentioned earlier about provisioning resource. That's basically where you would do that. Right?\u003C/p>\u003Cp>Because I think you get a small grace period between the start endpoint being hit and the first time the move endpoint is hit in any given game. And then your snake can be entered into many games.\u003C/p>\u003Cp>Speaker 1: Yep. Yep. Absolutely. And then yeah. There there's a bunch of stuff.\u003C/p>\u003Cp>We'll we'll kinda look at some of these and see what they do, but but but Kevin's absolutely right. Like, move is really what matters, and that's where you need to return sort of up down left or right. So the other thing just to look in here, especially for the snake, is just kinda looking at these, like, what you have in this basic package dot JSON file. There's really nothing there. This is a super\u003C/p>\u003Cp>Speaker 0: I think.\u003C/p>\u003Cp>Speaker 1: Super, super light template. And you can go crazy with this, but this is a very, very light template.\u003C/p>\u003Cp>Speaker 0: Mhmm.\u003C/p>\u003Cp>Speaker 1: Okay. So, do we wanna do we wanna run this or should we look through first or should we head back over to the quick start? What do you think, Kevin?\u003C/p>\u003Cp>Speaker 0: I think I think we could do a little less with the quick start because you and I have both like, we should I think we should refer to it as and when it's needed. I say let's get the let's go to the Battlesnake platform. Let's take this basic snake, which I think what what if you scroll down this file, what does the move endpoint do at the moment? Oh, there is some there is some logic there. Yeah.\u003C/p>\u003Cp>We'll talk we'll talk a little bit about that, but it does do stuff. So let's let's set up this snake and get one game running so we can kinda get to grips with how that code becomes a battle snake in a game. I think that that feels about\u003C/p>\u003Cp>Speaker 1: Kevin, I have one question for you, though. What do you think I mean, Replen is trying to tell us to do this desperately, and we haven't done it yet. What is the thing that we need to do?\u003C/p>\u003Cp>Speaker 0: Oh, I wonder if there's one call to action on this page that is significantly brighter than the oh, okay. Alright. Yeah. There was no mystery. We're hitting run.\u003C/p>\u003Cp>Speaker 1: Awesome. And so this is the piece here. So this is the piece that tells you that your Battlesnake is running, is you're gonna see this API response here. So you're gonna see this API version, the author, color, head, tail. And then in your console, if it's running, you're gonna see this running battle snake at whatever the server, domain is and, or server address is and then info.\u003C/p>\u003Cp>Now because of the nature of Battlesnake, you need to have a public, URL that you can share with the platform. This is new. They used to all be public and has since shifted. So I think we need to deploy our app. No.\u003C/p>\u003Cp>We don't need to deploy our app. So we're gonna see what happens. We're gonna see if we can use just this. Yeah. Let's go to new tab.\u003C/p>\u003Cp>And then I yeah. So it'll be like this, and let me bump this up as well. We'll see how much it bumps up actually. There we go. So this is the same thing that we're seeing here.\u003C/p>\u003Cp>And then in our, in our navigation bar, we have this, like, replit.dev link, and so that's what we're gonna put over into the Battlesleep platform. It used to show up right here. I don't know why it doesn't anymore. I wonder if it should\u003C/p>\u003Cp>Speaker 0: I imagine I imagine it got a bit unwieldy as you build more complex URLs\u003C/p>\u003Cp>Speaker 1: by that. That's right. That must be it.\u003C/p>\u003Cp>Speaker 0: And that's probably more useful as a developer just to see the the path, but who knows?\u003C/p>\u003Cp>Speaker 1: You know what, though? I have a feeling with a lot of these platforms, it might also be. Yeah. You know what? So the what you can do is if you just, like, right click on this, like, 0.0.0.08 1,000, similar to other platforms, it'll actually convert it to whatever that public URL is.\u003C/p>\u003Cp>Speaker 0: Oh, that's interesting. So it\u003C/p>\u003Cp>Speaker 1: can actually just copy that over there. Okay. So that's working. So let's head back over to play.battlesnake.com.\u003C/p>\u003Cp>Speaker 0: I'm so excited. Play. Play. Tailwind is a very nice little very nice little playground.\u003C/p>\u003Cp>Speaker 1: It is a very nice playground. This is like this Chromebook has become my central development, tool. And so, like, I have so many, like, interesting things on here. I never thought a Chromebook would be my daily driver. Alright.\u003C/p>\u003Cp>So over on the battle 6 site, auth with GitHub, highly recommend. Not that you need to, but, we're gonna auth there. Oh, look at that. Inclusive waffle. Good.\u003C/p>\u003Cp>Okay. So I'm logged in with my personal account. So here's what I love. I used to so I'm a teacher. If you didn't know that, what you\u003C/p>\u003Cp>Speaker 0: Oh, really? You have absolutely no mannerisms that would give that away. Like, what should we press on the screen now? Is it the green button?\u003C/p>\u003Cp>Speaker 1: But I I I introduced, my, like, middle schoolers to, to Battlesnake a couple of years ago. And, like, all their snakes are still in here, which I kind\u003C/p>\u003Cp>Speaker 0: of That's fun. Some of\u003C/p>\u003Cp>Speaker 1: these are That's Toby still mine, though, runs on node, on Node\u003C/p>\u003Cp>Speaker 0: RED. On Node RED.\u003C/p>\u003Cp>Speaker 1: That is a stellar platform, if you are looking at, having a stake. And actually, funny enough now now that I think about doing a directus snake\u003C/p>\u003Cp>Speaker 0: I was just about to say it. Yeah. Yeah. So so we have, directors automate as part of that. We have flows, which is a low code automation builder.\u003C/p>\u003Cp>And, yeah, if I whenever I actually describe it to developers, I ask if they've seen Node RED because I think it's very comparable. You know, you have automation builders that are very much like Zapier, and then you have ones which are more like Node RED. And this is more like that where you're wiring together these these these operations. But, yeah, we'll get to that.\u003C/p>\u003Cp>Speaker 1: I love it. Alright. So, we gotta add a snake in here. Now if you're new in your account, I think it prompts you where to add your new snake. I haven't done this in a little bit, so we're gonna see.\u003C/p>\u003Cp>I have a feeling\u003C/p>\u003Cp>Speaker 0: I actually need to go into my battlesnakes.\u003C/p>\u003Cp>Speaker 1: Yeah. We're gonna find out. There we go. And here we go. So we got all of our snakes that are currently in here.\u003C/p>\u003Cp>We're gonna create a new one. We're gonna call this one ready, set, Battlesnake. We're gonna drop our server URL in there that we copied over from do we still have it? Yeah. There it is.\u003C/p>\u003Cp>I think that's\u003C/p>\u003Cp>Speaker 0: And specifically without anything after the slash. We have to increment those, but that's correct. Yeah. So this is what\u003C/p>\u003Cp>Speaker 1: you're gonna see, something that looks a little bit like this. If you wanna try and copy this and use my snake, go nuts, or use our snake. And then the next thing you choose here is your engine region. And so I highly recommend that when you're getting started, you don't worry too much about which engine region that you're using. There's a good, like, kind of breakdown on why you would use a different engine region.\u003C/p>\u003Cp>I'm based in in in North America, so and I'm kinda closer to Oregon, so I'm gonna set the state there. Kevin might wanna set it up based in the Netherlands, but it really, really doesn't matter at\u003C/p>\u003Cp>Speaker 0: kind of the base level of Battlesnake. It it matters when you're squeezing out those milliseconds worth of worth of performance, but we're simply not.\u003C/p>\u003Cp>Speaker 1: Exactly. And then, again, description you can add, same with programming language. This is just fun. It gives it a little bit of flair. So you can add a JavaScript, and then we can say this is\u003C/p>\u003Cp>Speaker 0: Platform. We need to we need to do some work here. By the next time we record, we're gonna be doing some work to this list because we'll be we'll be moving we'll be moving our snake over.\u003C/p>\u003Cp>Speaker 1: I love it. Alright. So let's go. And what are we gonna find? What are we hosting on right now?\u003C/p>\u003Cp>We're hosting on Replit, so we should have Replit there. And what I love about this list too is you can actually see, like, here are all the different places that you could host a snake. Now some of these I highly would not recommend. Like, get out Codespaces. I don't think you can actually keep a long running server going.\u003C/p>\u003Cp>But Interesting.\u003C/p>\u003Cp>Speaker 0: No. Yeah. Yeah. You have to have the Codespace, and then they go to sleep.\u003C/p>\u003Cp>Speaker 1: Yeah. But lots of different cool options here. And then the other thing you can do is you can set it so that other people can interact with your snake. And so the upside here is that you can allow other people to kind of play around with it. The downside is you can have people that decide to challenge while you're using your snake for some other thing, and then you're having to deal with all the compute costs.\u003C/p>\u003Cp>And if you're running on, like, AWS or something that charges you for all of those compute hours, definitely challenging.\u003C/p>\u003Cp>Speaker 0: It's not just that. It's every request you get in relation to a single game has an ID of that game. But at basic levels, you're unlikely to be segmenting game logic. And if you're doing, you know, basic battle snakes, we'll just look at a single board and make a single response based on the heuristics of your code, the algorithm you create. But if you're doing something a little more clever way, you're looking over multiple turns, it screws you.\u003C/p>\u003Cp>But by that point, I suppose you are you are using that ID, but that's worth considering as well.\u003C/p>\u003Cp>Speaker 1: Yeah. Absolutely. Okay. So let's jump in here. So we'll leave it as private.\u003C/p>\u003Cp>We'll save this battle snake. So you'll know once you save right away if your battle is actually there because it'll show up with the name, obviously, that you set it here. If you don't, though, you won't get any response here in this ping. So you might put, it used to be that if you started a snake on a service, it wouldn't automatically go. And so you might have to run this ping just to kinda see.\u003C/p>\u003Cp>And you can see here, if we do this ping, we were talking about that 500 millisecond response time. You can see that Replit is really up their, like, their timing. It used to be\u003C/p>\u003Cp>Speaker 0: They didn't. They didn't. That first response was a few hundred. So that must be like a cold start kind of like now it's middling around 40, 50, 60, which is great, but it was multiple 100 the first time you, the first time it was there before you hit ping again out of interest.\u003C/p>\u003Cp>Speaker 1: Yeah. That's true.\u003C/p>\u003Cp>Speaker 0: So But then that's what you're starting to see.\u003C/p>\u003Cp>Speaker 1: A good idea. Yeah. Yeah. Okay. So we've got we've got ready set battlesync in there.\u003C/p>\u003Cp>You'll also see you kinda get the flare that's related to the the language and and sort of hosting service that you're using. And so now, our Battlesnake is in there and is ready to go. So, do we wanna make our Battlesnake look good before we bring it into the game or do we wanna bring it into the game?\u003C/p>\u003Cp>Speaker 0: Let let's jump into it and maybe we'll see if the the Battlesnake elders allow this. We might see if we can do some custom customization during the the act of us recording 4 episodes. But for now, let's just leave our our snake a slightly boring gray. We can come back to it. When when we come and update the platform to direct us, that's where we'll do the customization.\u003C/p>\u003Cp>That'll be next time.\u003C/p>\u003Cp>Speaker 1: I love it. Alright. So, we're gonna go in here. You can choose. So, well, in the traditional Battlesnake game, or traditional snake game, I guess, it's kind of a standard map.\u003C/p>\u003Cp>No hazards. It's kind of just food pops up and things like that. So we're going to choose just the standard mode and a standard board size of 11 by 11. And we're just going to add ready, set, Battlesnake onto the board. We're not going to add any other snakes in there.\u003C/p>\u003Cp>You can add some bots. These bots are always running that have, like, some set sort of modes, but we're just looking to see if our snake is ready to go. So let's go ahead and see, how ready set Battlesnake runs. Alright. We're in.\u003C/p>\u003Cp>Okay. We're here. Should we have it now? You have to.\u003C/p>\u003Cp>Speaker 0: Oh, yeah. Yeah. Come on. Let's do that. You ready?\u003C/p>\u003Cp>I'm so thrilled. No. I'm good. Alright. You ready?\u003C/p>\u003Cp>Yeah. Ready. Oh, no. No. We have a we we we get a catchphrase for this show.\u003C/p>\u003Cp>What? If Reggie said that Oh, my goodness.\u003C/p>\u003Cp>Speaker 1: Yes. Okay. Here we go. Okay. Of course.\u003C/p>\u003Cp>Alright. Let's go. Ready. Ready. Set.\u003C/p>\u003Cp>Battle snake.\u003C/p>\u003Cp>Speaker 0: That was thoroughly underwhelming. I'm gonna be honest. But but we are watching the snake. We got So this is what we got. So you see the ping?\u003C/p>\u003Cp>You saw the ping going on the right. So it was still around that 40 millisecond mark. There were 47 turns that happened before our snake died. Why did it die? And the nice thing about this editor, this player, of course, is you can step through your turns.\u003C/p>\u003Cp>So it was performing kind of a slightly eclectic set of moves, which is great. But what eventually happened to it? So it was at the bottom and it went off the board. It went down. So that was that's that's what our snake did.\u003C/p>\u003Cp>Now just to be clear, we'll look into the logic of our battle snake next, but we don't quite know why let's look at our code. And now we're at the point where we can start customizing this, this battle snake.\u003C/p>\u003Cp>Speaker 1: Alright. So we're gonna jump back over to Remplit. And so all of the things that you need to know for this snake when you're getting started are all gonna live here. And the other thing that's really cool here that I guess we didn't talk about earlier and maybe you didn't see here because we didn't go that far down in the code is we're actually returning into the console every move. So you can see why it moved or not why it moved in that direction, but you can see what happened.\u003C/p>\u003Cp>So this in this game start move 0, move 1, all of these commands that are happening are in here. But and this is sort of included in the base snake that you get here. And you can return lots of things in there. Like, you can return, like, what's leading into that. You can return logic.\u003C/p>\u003Cp>You can return things like shouts, which are just like little statements that are in your code. We kinda got rid of them. It used to be that you could do custom shouts that were displayed on the board of the games, which was very cool, but, they kinda disappeared. But, okay. Where where do we wanna start, Kevin?\u003C/p>\u003Cp>Speaker 0: Well, the nice thing about this starter snake for learning is it talks us through some steps. But before we do that, why don't we look at the code of what our battlesnake did? So it didn't just go in the same direction nonstop. Oh, that's another note. If your sync doesn't respond within 500 milliseconds or responds in an invalid way, it will continue to take the last direction There are a couple of variables here just to help us out.\u003C/p>\u003Cp>One that tells us where our head position is, and that'll give you an x y position coordinates and our neck, which is the second piece of your body. It's not all of them. It's just your head and your neck. There's a reason why your neck is important. We'll talk about that in a moment.\u003C/p>\u003Cp>And all we're doing here is oh, it's actually a lovely lovely and commented here. You can turn back into yourself. So if you're going straight up, you can go down, but you die immediately because you collide with your body. So all this logic is doing is saying don't hit the neck. Like, don't go back into the last space I was in, which is always the second position of the body.\u003C/p>\u003Cp>Now another thing that's interesting, if I may just kind of embellish kind of what's here, is we're starting to see the data structure play out a bit here. So this move function has an argument called game state. We see on lines 53 and 54 that inside of game state, there is an object called you. And inside of that, there is an array called body. And we can immediately assume that they're full of x, y coordinates.\u003C/p>\u003Cp>And in fact, that's that's made clear on line 56 where my neck and my head both have an x property. Before we continue, what might be interesting oh, I'm sorry. And so so the rest of the logic here is turn up, down, left, or right in that in that array, in that, object at the top, make them force if it means I'm gonna collide with my neck. Remove that as an option. And then I believe what it does is it basically, yeah, randomly picks 1 on line 87 and then returns the randomly selected valid move of which just doesn't collide with your neck.\u003C/p>\u003Cp>It does nothing else that's fancy. That's what we'll be doing today. Before we continue on this, can I make one recommendation that we do go back over to the docs and look at the game object so we understand what else we have at our disposal? Because I think it's important. Sorry.\u003C/p>\u003Cp>Not the get yeah. The game object. The board?\u003C/p>\u003Cp>Speaker 1: Yeah. It's the board object.\u003C/p>\u003Cp>Speaker 0: The board. The board. Perfect. Bottom left is 0. That's we're calling that out because when you draw on screen, sometimes 0 is the top left.\u003C/p>\u003Cp>If you do math, it's in the bottom left. So just note, 0 zero bottom left. That one screws me every time. This is what the object looks like. Could you zoom in a couple of sets by any any chance?\u003C/p>\u003Cp>Cool. Yep. So we have a height and a width. That's the size of the board. That is obviously important to know.\u003C/p>\u003Cp>We have the position of all the food, the position of all the hazards, which we're not playing within the classic game style. But if you hit hazards, I does your health go down or do you die?\u003C/p>\u003Cp>Speaker 1: You die if you hit a hazard. Or well, depends on it depends on the game mode, but a lot of time you'll die.\u003C/p>\u003Cp>Speaker 0: Fine. And then you have an array of snakes. Each snake has the idea of the snake, but it also has look at that. That was that was good teamwork there. It also has its health, all of its body parts, a convenience, which is an object called the head, which is always the first option in the body.\u003C/p>\u003Cp>So that's just a convenience there. They're always the same. The length, any customizations. But really what we care about for logic realistically is the body array and the head as a convenience. But we could get most of what we need from the body and the board collectively.\u003C/p>\u003Cp>What else is there here? Rule set, the game itself, but I don't think we care too much about those in this very moment. Yeah. Yeah. And I\u003C/p>\u003Cp>Speaker 1: think the only other thing that's kind of in here that's, I mean, less it's less valuable. This is more like you you can see. Like, imagine that if you're in this game, your snake can see everything about the other snakes. So, you're also sending all this information about your snake to all other snakes on the board. So\u003C/p>\u003Cp>Speaker 0: Yeah. You could stock out snakes that are low on health.\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. And some people even decide, like, I don't wanna ever, I don't ever wanna attack a purple snake or a pink snake, and they'll just decide, like, I'm gonna avoid all of those snakes. Just and you have the ability to do like that. These weird kind of logic pieces, which I think is kinda fun.\u003C/p>\u003Cp>Speaker 0: Yeah. Sure. Cool. So that is the shape of the object, which I think was important to dig into as we were starting to get a sense of what it looked like. So we know that we've got a board.\u003C/p>\u003Cp>We know we've got, we know we've got, sorry, a game. We've got boards. Boards have all the snakes and the board state itself. Snakes have a head and a body. So I think that's basically all we need to work through here.\u003C/p>\u003Cp>So all this snake does right now is avoid its neck. That is all it does. So Yep. What is the step one suggestion?\u003C/p>\u003Cp>Speaker 1: So step 1 is to prevent our Battlesnake from doing exactly what it did by moving out of bounds.\u003C/p>\u003Cp>Speaker 0: Okay. So this I mean, logically I mean, you and I have both done this kind of more simple battlesnake a a ton. But, you know, we will run through it kind of, you know, we come with a little bit more confidence in the approach, so we'll talk about it. But just know that in this little bit, there'll be a little less trial and error. Just so don't feel bad if if you're working through this and it's taking you a little longer.\u003C/p>\u003Cp>We just we just happen to know these first few steps like the back of our hand. So right here, there are a couple of comments that will go into that nested object and create a couple of variables for us, board width and board height. In this game, 11:11, but they can be smaller. They can be larger. And all we wanna do is say sorry.\u003C/p>\u003Cp>Go ahead.\u003C/p>\u003Cp>Speaker 1: No. I'm just gonna say, my eyes my eyes are burning right now. Do we see a do we see a dark mode?\u003C/p>\u003Cp>Speaker 0: It will exist. It has to exist. This is shocking. Our confidence. It it has to exist.\u003C/p>\u003Cp>Do you need to save save the snake or does it autosave or something?\u003C/p>\u003Cp>Speaker 1: No. No. So everything auto saves. Okay.\u003C/p>\u003Cp>Speaker 0: I recognize it.\u003C/p>\u003Cp>Speaker 1: I'm just, like, I'm motivated for dark mode, but I also\u003C/p>\u003Cp>Speaker 0: Does it take your does it take your, like, theme of your\u003C/p>\u003Cp>Speaker 1: Oh, look at you. Look at you, Kevin. Look at you figuring out the smart thing. I bet you it does. That's the wrong one that I want to turn.\u003C/p>\u003Cp>Where's my dark mode? Mode? I wanna click\u003C/p>\u003Cp>Speaker 0: on it\u003C/p>\u003Cp>Speaker 1: here, and then I wanna set it on dark theme. And then I bet you if I refresh this, it's gonna be dark.\u003C/p>\u003Cp>Speaker 0: Yeah. Okay.\u003C/p>\u003Cp>Speaker 1: I'm very confident that that's going to happen, but it may\u003C/p>\u003Cp>Speaker 0: not Oh, did I say I'm really confident? That's where it all falls apart. Yeah. We've already learned that that that's how it works.\u003C/p>\u003Cp>Speaker 1: Nope. Did not happen. Here we are. At least it's dark in some places. Is it\u003C/p>\u003Cp>Speaker 0: in your user settings?\u003C/p>\u003Cp>Speaker 1: It might be. It's odd that it's not actually, like\u003C/p>\u003Cp>Speaker 0: Like, here in the editor itself. Yeah. Maybe in your account, that you set up, like, your your default editor settings.\u003C/p>\u003Cp>Speaker 1: Let's see. Let's see. Billing, account, themes?\u003C/p>\u003Cp>Speaker 0: None of this. Themes. Themes. You know what? I wonder if that editor has, like, a command palette.\u003C/p>\u003Cp>Speaker 1: Oh, how\u003C/p>\u003Cp>Speaker 0: do I do that? Boom.\u003C/p>\u003Cp>Speaker 1: Beautiful. Are you gonna catch it here? Do I gotta refresh again? Oh, you're gonna make me refresh again. Alright.\u003C/p>\u003Cp>I see you. I see you.\u003C/p>\u003Cp>Speaker 0: There we go.\u003C/p>\u003Cp>Speaker 1: Beautiful. Oh, look at that. We got some dark mode battle snake as well. But oh, actually, does this still exist? There used to be.\u003C/p>\u003Cp>Yeah. You can. Dark theme. There we go. Nice.\u003C/p>\u003Cp>Speaker 0: All dark Okay.\u003C/p>\u003Cp>Speaker 1: All the time.\u003C/p>\u003Cp>Speaker 0: So let's go back to our code editor then. Sometimes in dark mode, things are just slightly less legible. So maybe let's just do one more step up on the font size, if that's alright. Yep. Lovely.\u003C/p>\u003Cp>And right. So we've got the board width, the board height. So real realistically, this code is gonna run every single turn. We're gonna know the size of the board based on these values, and we're gonna know our own heads x y position. And all we wanna do is the very pragmatic, am I on the very far right of the board?\u003C/p>\u003Cp>Yeah. I can no longer go right, left, up, and down. So that's the logic. We kinda have logic that looks similar to this above, but we can write it from scratch. That's also cool.\u003C/p>\u003Cp>Take it away, mister McLean. No. We're gonna see.\u003C/p>\u003Cp>Speaker 1: So you say we're gonna write it from scratch. I, I fundamentally disagree with you, sir. I feel like if we're provided with this code, I feel like we should use it. Alright. Here we go.\u003C/p>\u003Cp>So here, we were looking if your neck was less than your head, then you didn't wanna move left. So we're gonna remove some of these comments, but it's gonna be the same kind of concept that we're doing here. And so let's look at our let's look at our head. So we wanna get our board width is gonna be important in a minute, but let's get our head. So my head x, and then we want our head x if it's less than or equal to or greater than or equal to.\u003C/p>\u003Cp>Speaker 0: Well, hang on. Fin finish the thought. What what direction are we doing here? Left?\u003C/p>\u003Cp>Speaker 1: Yes. So we're doing so we're doing x. So we're doing the x axis.\u003C/p>\u003Cp>Speaker 0: If it's\u003C/p>\u003Cp>Speaker 1: So we wanted to\u003C/p>\u003Cp>Speaker 0: 0. If it's 0, it's on if it's 0, it's on the far left of the board.\u003C/p>\u003Cp>Speaker 1: Yep. So that's\u003C/p>\u003Cp>Speaker 0: all we need to check. If it's left, remove left trim. There is no minus one. You just die. So, double double equals double equals for for a comparison.\u003C/p>\u003Cp>Nice. So\u003C/p>\u003Cp>Speaker 1: that's our head x. So let's do our head y now. So if our head y equals our board height\u003C/p>\u003Cp>Speaker 0: So we're doing the top now. We're going clockwise. We're doing it. We're doing\u003C/p>\u003Cp>Speaker 1: the top now. But the thing here is because you're gonna get your board height, but then you need to be minus 1. So, like, your board\u003C/p>\u003Cp>Speaker 0: height because it's 0 indexed.\u003C/p>\u003Cp>Speaker 1: Exactly. So you're gonna do your board height minus 1. So this is basically saying if my oh, and not my neck. We want that to be my head.\u003C/p>\u003Cp>Speaker 0: Oh, yeah.\u003C/p>\u003Cp>Speaker 1: So if my head y is equal to the board height minus 1, then we're gonna set up to be false. Yeah. Alright. So let's do our next one. So that means that we're not gonna go off to the left of the board too far.\u003C/p>\u003Cp>It also means we're not gonna go up too far, so let's keep going around. So let's do else if my head my head, and let's go x again, and let's go we'll figure out what the in between is gonna be, but let's do board width minus 1 and is going to be\u003C/p>\u003Cp>Speaker 0: It's it's the same. It's just a double equals. The I I literally cannot get behind you doing this clockwise. It's driving me nuts, but we're here now.\u003C/p>\u003Cp>Speaker 1: We're here now.\u003C/p>\u003Cp>Speaker 0: It's so funny. I would I would have gone left, right, up, down, but I think that's because that's, like, how CSS rules are structured. Left, right, up, down. But yeah. Isn't that yeah.\u003C/p>\u003Cp>That's why I was like, what are you doing? Yeah. So this last one is gonna be, down. Right?\u003C/p>\u003Cp>Speaker 1: Yep. And so this one's gonna be my head y equals equals 0 and get rid of that. And this one's going to be, down is false, and then we actually need to change this one to right is false. And so this logic here, if you haven't been following along, is going to be if your head is equal to 0, you can no longer go left. Type of.\u003C/p>\u003Cp>Did I type\u003C/p>\u003Cp>Speaker 0: Hit backspace.\u003C/p>\u003Cp>Speaker 1: Oh, right. Hit backspace. Is move safe right. Yes. So here, if your head is at x is at 0 sorry.\u003C/p>\u003Cp>Your head x is at 0, then you are not gonna be able to go left. If your head y is at the top of the board, you're not gonna be able to go up. If your head x is at the far right hand side of the board, you're not gonna be able to go right anymore. And if your head y is at 0, you're not gonna be able to go down anymore. Cool?\u003C/p>\u003Cp>Do we wanna should we comment this? We're not gonna comment.\u003C/p>\u003Cp>Speaker 0: Get rid\u003C/p>\u003Cp>Speaker 1: of those comments. Who needs comments? You've got a whole video to go along with this.\u003C/p>\u003Cp>Speaker 0: Exactly.\u003C/p>\u003Cp>Speaker 1: Alright. So let's, it should automatically update. I'm gonna just refresh here, and we'll see if it works. Normally, it does. It's pretty good in real time.\u003C/p>\u003Cp>So let's go and see what happens. Let's just create a new game and see if our solution sorted itself out. So all we have to do here is literally just create a rematch. It's gonna go and read in with our new Battlesnake data. We're gonna see what this looks like in dark mode.\u003C/p>\u003Cp>We may be changing back to light mode. It's almost too dark now. I feel like I need a like a beige mode.\u003C/p>\u003Cp>Speaker 0: Like a like a, what is it? Like a Solaris. Is that what it's called?\u003C/p>\u003Cp>Speaker 1: Yeah. There you go. Like a sepia mode.\u003C/p>\u003Cp>Speaker 0: Yeah. Alright.\u003C/p>\u003Cp>Speaker 1: Oh, this is for so long and my wife laughed\u003C/p>\u003Cp>Speaker 0: at me. We also called it Nokia. So in the background right now, all of these moves are happening in the background. If we hit play and we get up to the latest turn, it kinda just starts to slow down, and we only and we see moves in real time. So what we're kinda letting it do now is catch up.\u003C/p>\u003Cp>So when we hit play, we can just watch it all in one go, which is Yeah. Pretty nice. The other\u003C/p>\u003Cp>Speaker 1: great thing that you can do here is you can actually change the playback speed. So if you wanna watch it slower, you can if you wanna watch it faster. We're just gonna leave it as medium. There's also some other things you can do here. Like, as soon as the first turn is ready, you can auto play in these games.\u003C/p>\u003Cp>That's nice. You can also grab, like, a scrub bar so you can see how long the game is gonna last. It's really only good for you. If you're doing that in a competitive game, it's a little bit less fun. And then you can also show board coordinates.\u003C/p>\u003Cp>I actually think this one's interesting because I think this will show folks something interesting in the game. So let's go back here. So we got the board coordinates up there. As\u003C/p>\u003Cp>Speaker 0: you can see\u003C/p>\u003Cp>Speaker 1: here, 0011. So this is the stuff that we're talking about. Right? So when we said the board width, which is technically 11, even though it's 0 to 10, it's an 11 board. So if we'd left it at that and just said board width equals Yeah.\u003C/p>\u003Cp>Speaker 0: The the the upper the upper right wouldn't have worked. It would have let it go off the yeah. Let it have died first. Let let's hit play so you can see what this thing does. So now it should avoid its neck, and it should avoid walls, which realistically means it will die by hitting itself or running out of food in theory.\u003C/p>\u003Cp>Yep.\u003C/p>\u003Cp>Speaker 1: And that's exactly what exactly what happened. Ran into its body. And so this is what we mean here. So, technically, the neck counts as part of the body as does the head, but we've defined the neck in our code. And so he's never gonna run into his neck, but it doesn't avoid him running into anything past his neck or or like Kevin said, running out of food.\u003C/p>\u003Cp>So, and you can see here, like, he's actually surviving a shorter period of time even though we have more code. But that's honestly I think you're absolutely right.\u003C/p>\u003Cp>Speaker 0: That first\u003C/p>\u003Cp>Speaker 1: time was a little bit\u003C/p>\u003Cp>Speaker 0: of a fix. Yeah. Absolutely. Oh, interesting. That should not have happened.\u003C/p>\u003Cp>Speaker 1: That should not have happened. Oh, I see. So head is technically at 0. It might have been because he's at a he's at there's no other safe moves, but that's not true. So what happened on that last move?\u003C/p>\u003Cp>Did he yeah. He went down. Interesting.\u003C/p>\u003Cp>Speaker 0: Let's let's just quickly check it again. When x is 0, if you head back to the code, when x is 0, remove left. When y is right at the top, hold height minus 1, you can't go up. When x is at the width minus 1, you can't go right. And then when y is at 0, you can't go down.\u003C/p>\u003Cp>Interesting. If or else if that Oh. Oh. No. No.\u003C/p>\u003Cp>No. I I I I I got it. This is in a a weird, like, else if else if else if. We we don't want this. We we we want each one to be its own individual statement.\u003C/p>\u003Cp>All of them need to be Oh, true. I love that.\u003C/p>\u003Cp>Speaker 1: If you\u003C/p>\u003Cp>Speaker 0: move the else's and and you change.\u003C/p>\u003Cp>Speaker 1: I love it. Alright.\u003C/p>\u003Cp>Speaker 0: It I'm not sure that's what the explains what just happened, but that was wrong. Like, it needs to be more like that.\u003C/p>\u003Cp>Speaker 1: Alright. Let's see if that fixes things for us.\u003C/p>\u003Cp>Speaker 0: Oh, timing out. Well, no. 42. Oh, that was an error. Let's scroll up.\u003C/p>\u003Cp>Let's see we'll see what happened. Just go all the way up to the top of the error. Alright. What's happening in here?\u003C/p>\u003Cp>Speaker 1: I need to zoom out a bit this a little bit. Just give me one second.\u003C/p>\u003Cp>Speaker 0: Board width is not defined. We made a typo. I think board width. Board? On line 70.\u003C/p>\u003Cp>There is on line 70. Oh, define the variables. Like, let put a let in in front of each one.\u003C/p>\u003Cp>Speaker 1: So what's interesting there is it means it was running our old code before. So that's that's part of the problem is it was actually running our old code. So now if we run this, k. Our battlesnake should be up. Let's do a game again.\u003C/p>\u003Cp>Speaker 0: And the moment you hit create rematch, we can go back to repl it, and we can see that things are happening. We saw that it made it 34 moves at least. That means all the moves have played out, so we can just hit play. It's looking promising.\u003C/p>\u003Cp>Speaker 1: Yep. Yep. Same thing. And it\u003C/p>\u003Cp>Speaker 0: went into its body.\u003C/p>\u003Cp>Speaker 1: I wanna I wanna examine that because I think that's interesting. Right? We had that l tiff. Why why was that not working? Why why do we think that wasn't working?\u003C/p>\u003Cp>Like, where's the logical error in that?\u003C/p>\u003Cp>Speaker 0: Oh, if if you're if you're at the bottom and the right, it'll only run 1. It'll run the first statement it it gets, and then it will.\u003C/p>\u003Cp>Speaker 1: There we go.\u003C/p>\u003Cp>Speaker 0: So you need to you need to get you need to get each of them. So this is now we think working. We'll we'll keep an eye on this one. Let's assume about that, like, logically, this feels good. If it starts moving out of bounds where there are viable options available, we'll come back and revisit this.\u003C/p>\u003Cp>The next step is to get it to collide is to get it to not collide with your entire body. Right now, it's just avoiding the neck, which is the second piece next to the head. We wanna avoid all of the pieces. And once again, Andrew and I have created start to battle snakes dozens, if not hundreds of times over. So what what are we gonna be doing here?\u003C/p>\u003Cp>We're gonna basically be writing a loop. We're gonna go through every piece of the body, and we're going to see if it's if it's next to me just like it was a boundary, we're gonna remove it. So we're gonna actually end up using reasonable amount of the logic. The logic is gonna look quite similar to the one above, but inside of a loop. Great.\u003C/p>\u003Cp>And we don't we don't actually need to do, we don't even need to we don't need to care about the length so much because we can, we can just use a 4, a for of loop for this, which is a syntax, which I really like. So I'll introduce you to a for of loop. John, sure, you cannot you\u003C/p>\u003Cp>Speaker 1: know what we're gonna do. We're gonna do what every good programmer does, and then I'm gonna go to Google and look up how do I do a loop in JavaScript because I have legitimately You\u003C/p>\u003Cp>Speaker 0: got me. You got me.\u003C/p>\u003Cp>Speaker 1: You got me. I it it\u003C/p>\u003Cp>Speaker 0: auto filled. Hang on. Hang on. Head back to Replit. It was helping you out there.\u003C/p>\u003Cp>It was doing it was and also w three schools. So so if you wrote the word for first first of all, it did actually kind of something yeah. Look. It's kind of giving you a hint here. So this is a very vanilla JavaScript loop.\u003C/p>\u003Cp>What this is, there are 3 parts at the top. First thing it's saying is, wow, okay. That's cool, I suppose. So we're initializing the value I with 1. We're saying keep running this loop for as long as I is less than the the the body length.\u003C/p>\u003Cp>And at the end of every iteration before you start the new one up I by 1 and I is a is a number, which you can feed into an array to get an index. There's a nicer way of doing this though, in my opinion, for this use case. So I'm gonna propose comment this out because I wanna just quickly show you a follow-up loop because I just think it's a I think it's a really nifty syntax. So instead of this, we're gonna go 4, and we're gonna do the the brackets again, but not let it autofill, all of that. Let piece where whatever we want.\u003C/p>\u003Cp>We're gonna call it piece of my body. Exactly. You've got one too many, close brackets there. And then you do squiggly brackets, and we enter into the code block. Piece is an is a variable inside of this loop, which will change its value for each iteration.\u003C/p>\u003Cp>So I just think this is yeah. I mean, it if you if you hit tab now, it seems to have already, that code's wrong. I could ain't gonna do anything. I mean, we'll leave it there as, like, as like, you know, we'll base something on this. This is not right.\u003C/p>\u003Cp>This is saying if if my head is in the spot of this piece, which also includes my head, make everything foresight. This just won't work. It will mean no isn't a viable move and it will keep it will keep sending you know, it will send it, I think, an undefined and then we'll die. So this is wrong. But just before we jump into the logic here, so this is another way to write a a loop in JavaScript.\u003C/p>\u003Cp>And another way you can do it is called a for in loop where you change the word of for in, and then the value of a piece will be the index value. So what we could have done there, an exact copy of what was above is saying for let eye of my body. And then I will automatically increment each time. It will give you the, in sorry, in my body. And then I or whatever variable name you give it, will will be a will be a number that goes up.\u003C/p>\u003Cp>The way I remember the difference between of and in, of object in index.\u003C/p>\u003Cp>Speaker 1: I love that.\u003C/p>\u003Cp>Speaker 0: Yeah. So, we'll we'll use the the for of loop. I think it's really nice because when you start to nest them, you can be really descriptive about what that value means inside of the loop. I think it looks nicer. It's a little more concise.\u003C/p>\u003Cp>But there you go. You learn about JavaScript loops. And there are obviously other loop types as well, but these are the more common 3. So what do we care about when we're looking at our body? Well, for every piece, what we wanna know is, is it one space away from us in any direction?\u003C/p>\u003Cp>That's all we wanna know. And if that is the case, we cannot move into that position. Even that strictly might not be enough because oh, no. It will be. That that will be enough.\u003C/p>\u003Cp>That is groovy. So what we wanna check is is our head equal to x? So is it on the same is it on the same x plane? Oh, no. No.\u003C/p>\u003Cp>Sorry. Inside of this initial if on 95. We're we're gonna alter 95 because 95 doesn't work. So we wanna say if it's on the x plane, but my head dot y is piece dot y minus 1, that means we are one space sorry. That means our body is one space below us.\u003C/p>\u003Cp>Down goes off the table. So this would be whatever the line is where we remove down. Game what's it called?\u003C/p>\u003Cp>Speaker 1: Yep. Yep. Let's go grab that.\u003C/p>\u003Cp>Speaker 0: Yeah. It is move is move safe. So if it's 1 under us down, down goes off. So is move safe dot down equals force. On the same x plane, hang on a moment.\u003C/p>\u003Cp>But the y for on the same x we're gonna fiddle with these till they work. This this bit always gets me. I think I might have just done that wrong, but we'll find out. Oh,\u003C/p>\u003Cp>Speaker 1: it's part of the adventure.\u003C/p>\u003Cp>Speaker 0: So, Hannah, if we're on the same x and it's below us if we're on the same Do you\u003C/p>\u003Cp>Speaker 1: need to draw this out?\u003C/p>\u003Cp>Speaker 0: Yeah. Maybe. Maybe.\u003C/p>\u003Cp>Speaker 1: Let's do it. Let's grab,\u003C/p>\u003Cp>Speaker 0: let's grab some It's bothering me. If we're if we're on the same x plane, but it's 1 below but then we're not on the same x plane out. But it's y. I wondered what tool you you were gonna grab there.\u003C/p>\u003Cp>Speaker 1: We'll see if this works. I might pull up some random drawing that I've created. I bet you I am gonna we're gonna see what magical drawing that I have up on the screen here as this loads.\u003C/p>\u003Cp>Speaker 0: What? Can you back a table in there? Because that's all we need is or a Google Sheet even, to be honest.\u003C/p>\u003Cp>Speaker 1: Oh, that's a good idea. Let's do a Sheet sheet. Okay. Let's do, sheets.new.\u003C/p>\u003Cp>Speaker 0: Sheets.new.\u003C/p>\u003Cp>Speaker 1: Sheets.new? Yes. What's happening right now?\u003C/p>\u003Cp>Speaker 0: What is slides.new, docs.new, forms.new.\u003C/p>\u003Cp>Speaker 1: I love it. That's fantastic. Okay.\u003C/p>\u003Cp>Speaker 0: Right. Zoom in. Zoom in. Zoom in. Zoom in a ton.\u003C/p>\u003Cp>Let's go zoom in. Oh, no. Wrong one. Let's go zoom zoom zoom.\u003C/p>\u003Cp>Speaker 1: There we go.\u003C/p>\u003Cp>Speaker 0: And and let's just do, like, we don't need 11. Right? We could just do, like, a 4 by 4 for the sake of argument. Like or up to 5 by 5 if you go to Ian and you go down to 5. Alright.\u003C/p>\u003Cp>Speaker 1: And I do feel like this visualization is really helpful when you're doing this, like, genuinely. I think this is, like, a process that is useful for anybody to do if you're considering doing this.\u003C/p>\u003Cp>Speaker 0: So draw, like, a 3 parts draw, I don't know. Yeah. Let's just yeah. Yeah. Perfect.\u003C/p>\u003Cp>Right. So what we want is if you go if you go right one oh, what's happening? What what we're doing? Just give me one second. This is just a small one to\u003C/p>\u003Cp>Speaker 1: do this.\u003C/p>\u003Cp>Speaker 0: Hold on. Hold on.\u003C/p>\u003Cp>Speaker 1: There we go.\u003C/p>\u003Cp>Speaker 0: Great. Hang on. Hang on. I think I think we needed to do it. Do a little more than that.\u003C/p>\u003Cp>And I would I would leave them as x's so we can notionally talk about the head. So do do maybe, like, make it like a like a u shape. So also fill in b 5 and b 4.\u003C/p>\u003Cp>Speaker 1: I'm gonna you know what? I gotta stop with this x. The the color x is\u003C/p>\u003Cp>Speaker 0: I I I I yeah.\u003C/p>\u003Cp>Speaker 1: Oh, no. Actually, hold on. I could just literally copy and paste. Come on, Andrew. What are you doing?\u003C/p>\u003Cp>There we go. This\u003C/p>\u003Cp>Speaker 0: is how we want it. Let's assume that b 5 is gonna be the head. Right. So the first thing we wanna do is to say, let let's try and do the left position first. Yep.\u003C/p>\u003Cp>So the x is the same and the piece is on x minus 1. So that's that's the first one we're we're gonna do. So x is the same as my piece dot x, but but the my piece dot. Oh my god. What's going on?\u003C/p>\u003Cp>So this is gonna be Sorry. Sorry. Sorry. Sorry. Sorry.\u003C/p>\u003Cp>The y is the same. Yeah. Because we're all because we're on the same level. We're on the same height. That's what was getting me.\u003C/p>\u003Cp>So if the y if the y is the same, the x is minus 1, you remove left. So let's do that first.\u003C/p>\u003Cp>Speaker 1: Alright. So if the y is the same, x minus y?\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. Yeah. So so let let's do the first if the first half of the statement, let's change those for y's. So if the y is the same, but the x is piece x minus 1 remove left.\u003C/p>\u003Cp>Speaker 1: Love that.\u003C/p>\u003Cp>Speaker 0: Okay. And and it's exactly the inverse for right. So x and sorry, y and y, perfect. We we replace those, but this time it's gonna be plus 1. That's all it was.\u003C/p>\u003Cp>We're we're just struggling struggling with that. So just to be clear, sorry, those first two still wanna be you need to basically inverse all of them. So y Correct.\u003C/p>\u003Cp>Speaker 1: There we go. And then we're gonna return off\u003C/p>\u003Cp>Speaker 0: that will be right. Yeah. And I I don't think we need I'm really glad we pulled out that tool, but I think we can basically invest them now. So copy and paste both of these. So next thing we're gonna do, not like that, is if the x is the same, therefore, the the column we're in is the same.\u003C/p>\u003Cp>That was it. But the y piece is minus 1, then it's under us. So we're gonna remove down. And, yeah. Exactly.\u003C/p>\u003Cp>Xxy y. There we go. That took us that took us a hot minute, but we got there. So that should now prevent us colliding with oh, hang on. Hang on.\u003C/p>\u003Cp>Why? Oh, no. It's fine. On that line 94 piece isn't, like, white, so I thought it was unused. Oh, no.\u003C/p>\u003Cp>It's\u003C/p>\u003Cp>Speaker 1: because I added an s in there. There was a there was an error there. Just because I'm doing the Windows key save.\u003C/p>\u003Cp>Speaker 0: No. No. No. Peace is declared but never used. I don't think that's right.\u003C/p>\u003Cp>Speaker 1: Oh, there it is. It caught it.\u003C/p>\u003Cp>Speaker 0: There we are. There we go.\u003C/p>\u003Cp>Speaker 1: Cool. Oh, but we got a formatting issue? Hold on. So we can\u003C/p>\u003Cp>Speaker 0: No. It was a it was a formatting issue. No? Hold\u003C/p>\u003Cp>Speaker 1: on. Nope. We're still getting a bug here.\u003C/p>\u003Cp>Speaker 0: Someone watching this right now is screaming. They're like 100%. A 100%. I feel like I'm missing it. Scroll to the top of the arrow.\u003C/p>\u003Cp>The top of the arrow is gonna tell you tell you what it is, but we're not at the top of it yet. Keep going all the way up, all the way up, all the way up. More more more more. Oh, okay. Less.\u003C/p>\u003Cp>Speaker 1: We went too far.\u003C/p>\u003Cp>Speaker 0: We went too far.\u003C/p>\u003Cp>Speaker 1: It happens. Hold on. There we go. I just went too far into the first interpreter.\u003C/p>\u003Cp>Speaker 0: Alright. Board meeting No. No. We sorted that. That was before now.\u003C/p>\u003Cp>We did that.\u003C/p>\u003Cp>Speaker 1: Oh, it's this one. Hold on. Hold the phone. Close u.\u003C/p>\u003Cp>Speaker 0: Wow. Capsule consoles.\u003C/p>\u003Cp>Speaker 1: So many consoles. Formatting failed with message. What?\u003C/p>\u003Cp>Speaker 0: And go have I missed something pretty obvious here?\u003C/p>\u003Cp>Speaker 1: No. I think I think that was the that was the issue for let piece of my body. Hey, bro. Yes. I think it was just that s in there.\u003C/p>\u003Cp>Let's try running it again.\u003C/p>\u003Cp>Speaker 0: You can do it. You can do it. I'm getting a hunch it can't do it without some intervention.\u003C/p>\u003Cp>Speaker 1: What have we done? Is it because we do need to declare this let on my body?\u003C/p>\u003Cp>Speaker 0: Oh, yeah. Maybe that that was the grape last time.\u003C/p>\u003Cp>Speaker 1: Kevin lied.\u003C/p>\u003Cp>Speaker 0: There you go.\u003C/p>\u003Cp>Speaker 1: You lied. You said I didn't have to let it.\u003C/p>\u003Cp>Speaker 0: No. I literally did earlier. That's what happened with board width.\u003C/p>\u003Cp>Speaker 1: I feel like it's it's a useful thing to blame other people for your coding mistakes. I feel like that is what it is the sign of a true a true professional.\u003C/p>\u003Cp>Speaker 0: The professionals we clearly are.\u003C/p>\u003Cp>Speaker 1: Yeah. As I as I went to Google to search how to\u003C/p>\u003Cp>Speaker 0: do a\u003C/p>\u003Cp>Speaker 1: loop in JavaScript.\u003C/p>\u003Cp>Speaker 0: What's what's happening right now? It's all taking a little long. Can you can you refresh the web view at the top?\u003C/p>\u003Cp>Speaker 1: Yeah. Let's do that. I feel like that's k. We can close this out for now. Yeah.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah.\u003C/p>\u003Cp>Speaker 1: Let's see what's going on. I don't know. Yeah. I don't know what's happening. Maybe repllets happen a day.\u003C/p>\u003Cp>I mean, this is the thing. Right? It's like we are dealing with a cloud ID, so it does chug sometimes. But\u003C/p>\u003Cp>Speaker 0: Absolutely.\u003C/p>\u003Cp>Speaker 1: The REPL is booting. It's doing its thing.\u003C/p>\u003Cp>Speaker 0: It is. I will say as much as I love cloud IDs or cloud development environments as they're trying to brand themselves now, I use Gitpod for ages, I use Codespaces for a while, I have moved back to using a desktop editor for things like this. Like, why am I waiting for my editor to get its act together?\u003C/p>\u003Cp>Speaker 1: You're not wrong.\u003C/p>\u003Cp>Speaker 0: So so yeah.\u003C/p>\u003Cp>Speaker 1: There we go.\u003C/p>\u003Cp>Speaker 0: And the GitHub CLI makes it really, like, quite quite nice to to move between PRs as I'm reviewing stuff. So, alright, great. Let's rerun the game. So now it should not die from its own body. So in theory in theory, for a one snake battlesnake, I think it's gonna have a yeah.\u003C/p>\u003Cp>I think it's gonna have a decent life. Look at this. We broke a 100. There we go. This is amazing.\u003C/p>\u003Cp>Wow. This, okay, 170 moves. Let's see what ended up doing it in no. It could be health or it could be eventually, it had no viable options. You know?\u003C/p>\u003Cp>Let's see.\u003C/p>\u003Cp>Speaker 1: Yep. So it's doing all the things. Not running into its tail now, which was entirely possible with our previous code. It's not getting bigger because it's not getting food. So now it's going in that circle because it's avoiding its body, and it's avoiding its tail, and it's avoiding its neck.\u003C/p>\u003Cp>And so I think he might starve out just because he's getting stuck in that circle.\u003C/p>\u003Cp>Speaker 0: Oh, no. Poor buttersnake. Eat something. Look all that food around you, mate.\u003C/p>\u003Cp>Speaker 1: Dang. So, yeah, that's the interesting thing is, technically, he got into that loop where, like, technically, he was right, but we didn't say if you do this more than once, get out of it, which is a thing you can do. And what that, chicken or sorry. What that snake did is a is a a very famous move in the Battle State community called chicken snake. And chicken snake used to, like, go into a corner and would just chase its tail and wait for everybody else to die.\u003C/p>\u003Cp>And it would do really well.\u003C/p>\u003Cp>Speaker 0: Yeah. And you you basically, you are you either other everyone has to die before you or you have to hope food spawns in in well, it it won't spawn where you are though, will it? It won't spawn in a position where a snake is. So actually\u003C/p>\u003Cp>Speaker 1: It can spawn, like, right where oh, you're actually not wrong. That's absolutely\u003C/p>\u003Cp>Speaker 0: right. Yeah. Interesting. Okay. Cool.\u003C/p>\u003Cp>So step 3 is a pretty, a pretty good evolution of what we just did there, which is up until now, we have a single battle snake on our board. But in reality, battle snakes will not be alone on the board. There will be at least one other snake on the on the board. And our job is not only to avoid ourself, but to avoid every snake and all of their body parts. Thankfully, we are effectively gonna get to get gonna get to, like, work on this work on this.\u003C/p>\u003Cp>And in fact, Andrew, I don't think we should copy and paste it. I think we should adapt this because our snake is in the snake's array as well. The might the me, whatever it's called, is again a convenience like the head to just give you the first item. So there's no point doing a loop over all our parts, then a loop over an array which includes us. We should just adapt this immediately.\u003C/p>\u003Cp>Speaker 1: Okay. Great. Let's do it. Alright. So let's go yeah.\u003C/p>\u003Cp>So we've already defined here. So we've got our opponents defined, and we're gonna do that same let again. Right? Like, we're gonna do our loop with around our opponents, or do we wanna remove ourselves from that first?\u003C/p>\u003Cp>Speaker 0: You know or I mean, this is I mean, it's up to you. Right? We can either, yes, remove ourselves from it, run the loop again because who cares? You know, it's just repeating logic effectively. Or we can adapt what is written above in that kind of 90 to a 110 line range to just be the loop.\u003C/p>\u003Cp>Speaker 1: Oh, I see. Okay. Okay. So where where should we start?\u003C/p>\u003Cp>Speaker 0: Us. So we we know here based on line 116, which we should probably comment out because it doesn't have a let in front of it, but we know that game state dot board dot snakes is an array of all snakes including us. I believe we're always first. So let let's create that variable above this loop, first of all.\u003C/p>\u003Cp>Speaker 1: Alright. Let's do that up here. I see. I see what you're saying. Now when you said adapt, I was like, is that not what I'm doing?\u003C/p>\u003Cp>Alright. So let's define that.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. We we don't need to build on top of what we've already done here. In theory in theory, we can also do a way above with, the avoid our neck logic that it came with because we're gonna avoid our neck by virtue of this. Let let's leave it for now.\u003C/p>\u003Cp>Let's do a little bit of cleanup at the end, I think. So now we have it's not even opponents. I don't even think that's the right name. It's snakes. These are the snakes, and it includes us.\u003C/p>\u003Cp>We have a loop that will go through our body and do the check. And, basically, all we wanna do here is write a full loop above it, like surround it in a further full loop, and we'll do the same thing. So we'll go let, snake singular because each iteration is going to be a single snake of snakes. We'll do the open squiggly bracket here on line 44, remove that exactly input precisely, and we'll put that outside the outside of the other one. And all we wanna do here is instead of my body, it will be snake dot body.\u003C/p>\u003Cp>Speaker 1: Oh, Kevin. It's like you've done this many times before. That is just like It is. That is beautiful. So in my hearing and\u003C/p>\u003Cp>Speaker 0: the We we don't know it works yet.\u003C/p>\u003Cp>Speaker 1: No. But I like aesthetically, it's very pleasing.\u003C/p>\u003Cp>Speaker 0: Thank you. You're welcome.\u003C/p>\u003Cp>Speaker 1: Thank you.\u003C/p>\u003Cp>Speaker 0: So now in theory, we're running the same loop for all of for all the snakes. Right? Should we test it?\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. Let's test. Alright. So let's I'm I was wrong.\u003C/p>\u003Cp>We do need to stop and start it. So let's see. This should work fine. Perfect. Okay.\u003C/p>\u003Cp>Let's head back over here. Gotta do a new game now, because we What? Are actually gonna add\u003C/p>\u003Cp>Speaker 0: another set. Of course. Of course. We may as well use one of these bot snakes.\u003C/p>\u003Cp>Speaker 1: I love that scared bot just disappears in this dark mode.\u003C/p>\u003Cp>Speaker 0: In dark mode.\u003C/p>\u003Cp>Speaker 1: Just not there. That's fine. It doesn't matter. We're gonna add him, and we're gonna add in ready, set, and battle snake.\u003C/p>\u003Cp>Speaker 0: Right.\u003C/p>\u003Cp>Speaker 1: Alright. Let's add that in there. Alright. And so we've got a game running now. Now this is another thing about playing this is, like, you can see a lot of these things from your logs.\u003C/p>\u003Cp>So if you're ever playing BattleSync competitively and, like, there's a competition, like, it's almost like you have to close your logs. Otherwise, it gives too much away.\u003C/p>\u003Cp>Speaker 0: It's like\u003C/p>\u003Cp>Speaker 1: you know Woah.\u003C/p>\u003Cp>Speaker 0: What happened. The other the other nice thing about this is, of course, we get the whole board state every time. So as we start to integrate this with Directus, we can we can consume and store as much of this as we want. Let's, let let's play it. Yeah.\u003C/p>\u003Cp>Game over. 101 moves. Let's see what happens.\u003C/p>\u003Cp>Speaker 1: Okay. So avoiding body, avoiding other snakes as well. Oh, I think I know\u003C/p>\u003Cp>Speaker 0: how this is. Yeah. I think I know how it's gonna end for this snake.\u003C/p>\u003Cp>Speaker 1: Yeah. Me too.\u003C/p>\u003Cp>Speaker 0: Womp womp.\u003C/p>\u003Cp>Speaker 1: Womp womp. Womp womp.\u003C/p>\u003Cp>Speaker 0: And look how close the food is. Boom. Game over. So it can can we do a rematch? Can we get something hopefully a little more vibrant?\u003C/p>\u003Cp>Speaker 1: Let's do a rematch.\u003C/p>\u003Cp>Speaker 0: Let's see\u003C/p>\u003Cp>Speaker 1: what happens here. Yeah. And we'll play it just so that we can see it in real time. And and this way, you can actually see this What\u003C/p>\u003Cp>Speaker 0: is going on with our snake? Why is it happening? Our snake actually oh, there's an error with our snake because there was a viable direction there. It was to go right, and it did not. No safe moves detected.\u003C/p>\u003Cp>So that makes sense. So why was it no safe moves? So we have it set that it's not going to go is\u003C/p>\u003Cp>Speaker 1: that it's not gonna go no. Because he's been going up there. So she should just\u003C/p>\u003Cp>Speaker 0: the final move? He should have gone right.\u003C/p>\u003Cp>Speaker 1: Yeah. He should have gone right or\u003C/p>\u003Cp>Speaker 0: he should\u003C/p>\u003Cp>Speaker 1: have gone wrong. Loop.\u003C/p>\u003Cp>Speaker 0: So our logic is wrong. Let's take a look at that. But but and right was the only move. It couldn't go up based on our heuristics. Even though, in theory, to avoid our body, we can remove the tails.\u003C/p>\u003Cp>We can remove the final piece.\u003C/p>\u003Cp>Speaker 1: But what's interesting is he was doing that. Like, if you look at this, so he was here and he was going here. So, technically, when he was in this spot, he could have actually done this again. Right? Oh, yes.\u003C/p>\u003Cp>So he could have gone up or he could have gone right. Of course. Interesting. Okay. But let's go to our code and see why that didn't so why did\u003C/p>\u003Cp>Speaker 0: you decide? It's because\u003C/p>\u003Cp>Speaker 1: of the other snake. So it is it does have something to do with the fact that he was right next to a snake, and so he didn't think\u003C/p>\u003Cp>Speaker 0: what about oh, no. No. It's right. My head is still correct. And we wanna be checking the piece of every snake.\u003C/p>\u003Cp>Speaker 1: P sex minus 1, p sex plus 1. Yes. That's right. I feel like it's because we do actually need to bring this logic inside because we're running these this and then we're running through this loop.\u003C/p>\u003Cp>Speaker 0: It shouldn't make a difference, though. So? If it's set force once, it's we never set anything's true. We're never undoing the work we did. We're just kind of repeating it.\u003C/p>\u003Cp>You know? Yep. Okay. So I guess my\u003C/p>\u003Cp>Speaker 1: head is in there. We don't need the my body anymore. We're not referencing my body anymore.\u003C/p>\u003Cp>Speaker 0: Sninks does include us. Right?\u003C/p>\u003Cp>Speaker 1: Yeah. Well, let's let's figure that out.\u003C/p>\u003Cp>Speaker 0: I think Let's I think it does. I think you is the name of the the object as a convenience.\u003C/p>\u003Cp>Speaker 1: Snakes snake squad. No. That's not important to us.\u003C/p>\u003Cp>Speaker 0: No. That's the snake squad.\u003C/p>\u003Cp>Speaker 1: That and then board. So, yeah, you are getting snake 1, snake 2, snake 3.\u003C/p>\u003Cp>Speaker 0: Can we see the description? Snakes. All snakes on the game board, including yourself if you have not been eliminated.\u003C/p>\u003Cp>Speaker 1: Yep. So it should be working. You're right.\u003C/p>\u003Cp>Speaker 0: So what is going on here?\u003C/p>\u003Cp>Speaker 1: So for snake of snakes, that's good.\u003C/p>\u003Cp>Speaker 0: Again, people watch it people watching this on director's TV are gonna be like, god. It's so obvious. This is the thing.\u003C/p>\u003Cp>Speaker 1: Well, let's hold on. Let's remove some some let's comment out some\u003C/p>\u003Cp>Speaker 0: I mean, sure. Sure. But, I mean, that's literally gonna\u003C/p>\u003Cp>Speaker 1: matter for anything. But okay. So if my head and let's go back to our let's go back to our sheet, drive.\u003C/p>\u003Cp>Speaker 0: 94% of storage used?\u003C/p>\u003Cp>Speaker 1: Yeah. I should probably, go in here and, you\u003C/p>\u003Cp>Speaker 0: know Oh, not pay not pay more for it. Just act stuff. Yeah. That that's the other solution.\u003C/p>\u003Cp>Speaker 1: Okay. So let's say we have let's let's actually reimagine the board state that we were in\u003C/p>\u003Cp>Speaker 0: I love that. Fine. What one step back? I if it's playing, what's going on here? Oh.\u003C/p>\u003Cp>And we just need to go one step back. We're at the end of the game.\u003C/p>\u003Cp>Speaker 1: Okay. There we go. Alright. So let's bring this to we will actually bring this to a 10 by 10 board. And let's pull this over.\u003C/p>\u003Cp>Speaker 0: No. No. No. No. No.\u003C/p>\u003Cp>We we don't need the whole board. We only need, like, however wide. We only need, like, the cluster around around what we're doing. We we don't need to recreate the whole board.\u003C/p>\u003Cp>Speaker 1: Alright. So let's go\u003C/p>\u003Cp>Speaker 0: Hang on. I'll, on my side, I'll take a little a little cheeky screenshot, and I can I can call that out for you\u003C/p>\u003Cp>Speaker 1: if you want? K.\u003C/p>\u003Cp>Speaker 0: If you if you head if you head back.\u003C/p>\u003Cp>Speaker 1: Go back to the game. There we go.\u003C/p>\u003Cp>Speaker 0: Okay. So here's what we're doing. Let's go to our sheet. So we only need 1 like, we we can do it all within here, basically. So put our snake on, a 1b 1, a 2, and b 2.\u003C/p>\u003Cp>The head is b 2. And then, that that snake's gonna go, a 3. There. Yes. One more to the left.\u003C/p>\u003Cp>We can stop there. The rest is irrelevant. So that's that's what the snake is doing. And so first thing we're doing is we're avoiding ourselves. So we're saying can't go left.\u003C/p>\u003Cp>We can't go. The thing that's got me is why is it going right? That is I'm sorry. Why isn't it going right when that is a legal option? Yep.\u003C/p>\u003Cp>That's the question. The right logic is bust.\u003C/p>\u003Cp>Speaker 1: Okay. So let's look let's pull this side by side. Let's grab this over here and let's go get this over here in our logic and see if we can make sure that our logic addresses this situation. Alright. So let's go here.\u003C/p>\u003Cp>Okay. So yeah, our first code here, my head, y.\u003C/p>\u003Cp>Speaker 0: Yeah.\u003C/p>\u003Cp>Speaker 1: So my head, y, is currently at\u003C/p>\u003Cp>Speaker 0: On on b. Sure. Yeah. Right. On on 1.\u003C/p>\u003Cp>If it's 0 indexed in the bottom left. Yep. So we're both on 1. Sure. And the x, there is a piece one step down.\u003C/p>\u003Cp>Correct. Oh, hang on a moment. I think we've got our things muddled here. If my head y, but x is my so now that's correct. So that that accounts for a 2.\u003C/p>\u003Cp>Left is no longer viable. Yep. Going down 1, it's the same. We're on the same column, but right, this one is what's got me, but the piece dot x plus 1, but that is not the case. It's an it's an and statement.\u003C/p>\u003Cp>So, you know, both those things have to be true for it to be met. So if y is the same, but the my head dot x equals piece dot x plus 1, then it's on the right, but it isn't. I don't know what's going on here. My head okay.\u003C/p>\u003Cp>Speaker 1: Well, hold on. So this technically, these are x aligned, but they're y they're not equal for y.\u003C/p>\u003Cp>Speaker 0: They're they're they're y's match. They're wise match. They're on the same column. That means they're the same do you think I've just got the accent? No.\u003C/p>\u003Cp>Speaker 1: No. No. I think that my I'm trying to work this out in my head. So this is\u003C/p>\u003Cp>Speaker 0: Call that x1 or x. No. No. That's yes. Yes.\u003C/p>\u003Cp>No. You're right. You're right. You're right. You're right.\u003C/p>\u003Cp>Sorry. Yes. Oh, sorry. X1, x2, x3, x4, x5. Yeah.\u003C/p>\u003Cp>Y1y2y3y4.\u003C/p>\u003Cp>Speaker 1: Yeah. So right now these are the same x, but they're different y's.\u003C/p>\u003Cp>Speaker 0: Well, the yeah. So if we hang on. Let's let's start at the top. So let's do the left first. So the x matches.\u003C/p>\u003Cp>We've got them flipped, Andrew. We flipped them.\u003C/p>\u003Cp>Speaker 1: Did we? Yeah. Okay.\u003C/p>\u003Cp>Speaker 0: Look, the y is the if the y is the same no, we haven't. We got it right. So if the y is the same, let's say let's take, b 2 and c 2. Right? Yep.\u003C/p>\u003Cp>The y is the same. Yep. So that they they exist in the same yeah. But the x is minus 1. That means underneath.\u003C/p>\u003Cp>No. That means To the to the left. Something on the left. Fine. Then y is the same once again.\u003C/p>\u003Cp>They're in the same row.\u003C/p>\u003Cp>Speaker 1: Are you\u003C/p>\u003Cp>Speaker 0: sure we haven't flipped them?\u003C/p>\u003Cp>Speaker 1: I I think we might have hold on. So okay. My head y, my piece and piece y are equal. So yeah. You're right.\u003C/p>\u003Cp>These 2 are technically there, and then my head x, so this is my head x, piece x minus 1. So, yeah, this removes left. That that totally makes sense. So we're good there. So next up, my head y equals piece y.\u003C/p>\u003Cp>Okay. Well, what would apply here, I guess? What would apply to this one right here?\u003C/p>\u003Cp>Speaker 0: It would have to be on the right. I think we got it right. I don't know what's going wrong.\u003C/p>\u003Cp>Speaker 1: My head x. Okay. So right now, this is they are the same for these are the same for x. So my head equals piece x. My head y equals piece y minus 1.\u003C/p>\u003Cp>Down is false. Yes. That that's right. That's good. My\u003C/p>\u003Cp>Speaker 0: head pieces We flipped them. We flipped them. And what's getting me is the 1 on 1 on line 107. So my head dot x means they are in the same it means they're in the same row.\u003C/p>\u003Cp>Speaker 1: Yes. It means\u003C/p>\u003Cp>Speaker 0: so it means they're in the same column. It means they're in the same column. Yeah. Right? They're in the same column, but the y piece is minus 1.\u003C/p>\u003Cp>They're in the same column, but the but the y is is 1 to the left. They're in the same column, but the y I I'm struggling to visualize that based on our head. They're on the same Okay. Hold on. So my head ached I think we've, I think we've muddled these.\u003C/p>\u003Cp>I think I think, yeah, these are wrong. And I know we we know this and the audience like, yeah, it's wrong. And here's exactly how, But, I don't think it's as simple as comparing the y's and then comparing the x's. I think only one piece wants to be I think the Right. So can you just put, like, an a in d two for us?\u003C/p>\u003Cp>So we're we're gonna test no. No. No. A d 2. So so so so we're gonna test h versus a.\u003C/p>\u003Cp>Right? So the y is the same. The the y the y is the same. The x is plus 1. The the y is the same and the x is plus 1.\u003C/p>\u003Cp>Yeah. Right gets removed.\u003C/p>\u003Cp>Speaker 1: So right yeah. Right should definitely\u003C/p>\u003Cp>Speaker 0: So but at least one of these is wrong because we're removing too many options. Yep. If if x is the same, so they're in the same column\u003C/p>\u003Cp>Speaker 1: So let's say y here. So these guys are in the same column.\u003C/p>\u003Cp>Speaker 0: But the y is minus 1.\u003C/p>\u003Cp>Speaker 1: Then we're gonna get that here.\u003C/p>\u003Cp>Speaker 0: Fine. Then the y's are the same, the x is plus 1, then we're going right. Dude, this looks correct to me.\u003C/p>\u003Cp>Speaker 1: It does\u003C/p>\u003Cp>Speaker 0: I don't know what's going on.\u003C/p>\u003Cp>Speaker 1: I okay. So I feel like this we've worked through this. I do think it must have something to do with this logic then. Have we screwed something up here? No.\u003C/p>\u003Cp>Speaker 0: I don't think so.\u003C/p>\u003Cp>Speaker 1: If my head equals 0, head x equals 0.\u003C/p>\u003Cp>Speaker 0: It's anywhere in that line. You can't go left. If it's at the board if y is at the height, you can't go up.\u003C/p>\u003Cp>Speaker 1: So here, this was at the height minus 1. So wait. What is height returning? Am I wrong? Have we changed the rules, and is height actually returning the height of the board and not 11?\u003C/p>\u003Cp>Oh, no. No. Returns 11. Oh. Oh.\u003C/p>\u003Cp>Wait. No. That\u003C/p>\u003Cp>Speaker 0: No. That's correct.\u003C/p>\u003Cp>Speaker 1: That's correct.\u003C/p>\u003Cp>Speaker 0: Board width minus 1.\u003C/p>\u003Cp>Speaker 1: Yeah. So that's that's fine. That would be the one that would have mattered that it would have removed the right, and that logic makes sense.\u003C/p>\u003Cp>Speaker 0: Yeah.\u003C/p>\u003Cp>Speaker 1: It's not there. Yeah. This logic is all correct. Let's run another game and see.\u003C/p>\u003Cp>Speaker 0: We are. I am full on at the point where I'm just gonna find a snake because I know I know it's less fun. I know it's less fun, but I just, but I also I also don't don't fancy doing this forever. Let's take a look.\u003C/p>\u003Cp>Speaker 1: K. I wanna see how this game plays out if something similar happens. K. Why did you run into his head? Why was that a safe move?\u003C/p>\u003Cp>Okay. What was the logic there? Did you have no safe moves again? No. So here, he thought he could go right.\u003C/p>\u003Cp>So oh, no. Because there. Okay. That makes sense. That tracks because he wasn't directly next.\u003C/p>\u003Cp>So there's no look ahead right now. So this takes\u003C/p>\u003Cp>Speaker 0: So that's so so that'll happen sometimes.\u003C/p>\u003Cp>Speaker 1: Yeah. So that tracks. That that game worked the way it should have. There's no buggy things there. It worked the way it should.\u003C/p>\u003Cp>Let's see if we can get another game because I feel like maybe that is it. Like, our code is right and there was just some sort of a glitch, but I don't know. K. So he's going in the circle. He's going in the circle.\u003C/p>\u003Cp>So he's gonna starve out anyways. We're not gonna get to see much there. Anyone? That's so weird. Can we can we\u003C/p>\u003Cp>Speaker 0: run it again and again and again?\u003C/p>\u003Cp>Speaker 1: So he's not making the same mistake again? I don't\u003C/p>\u003Cp>Speaker 0: I don't like that it's just doing that. That feel it feels weird to me that it keeps chicken whatever you call it. Chicken Chicken snaking? Chicken snaking. That feels very odd to me that it does that consistently.\u003C/p>\u003Cp>Speaker 1: Okay. So he's not doing this\u003C/p>\u003Cp>Speaker 0: as well. It isn't. Okay. Fine.\u003C/p>\u003Cp>Speaker 1: Okay. And, again, so this ish situation, was that a safe move? So he's gotta finish the game.\u003C/p>\u003Cp>Speaker 0: Come on. Come on. Go back.\u003C/p>\u003Cp>Speaker 1: Okay. So this does that make sense? Yeah. Again, this one makes sense because he didn't see right? So every one of these games, it's just the one game that was the one that was very strange.\u003C/p>\u003Cp>I think that there was some sort of a there was some sort of a an issue there with the actual way that it was reading our logic. I I hate seeing bugs that don't get resolved, but it seems like it's not happening again.\u003C/p>\u003Cp>Speaker 0: It seems to have been okay since.\u003C/p>\u003Cp>Speaker 1: Yeah. Well, let's try again. Maybe Okay. So why did he do that? So he shouldn't have done that either.\u003C/p>\u003Cp>Okay. So here's the thing. So why did he do that? So right. Right.\u003C/p>\u003Cp>Right. Game over. So he should not have gone right there. Why did he go right? Why did he think right\u003C/p>\u003Cp>Speaker 0: Something's wrong. Was a safe move.\u003C/p>\u003Cp>Speaker 1: Okay. So let's look at this again. And we're gonna have these guys here. So let's go, I'm actually gonna do color with these this time because I feel like that will actually help us. And then we'll do here and then we'll do him gray green\u003C/p>\u003Cp>Speaker 0: and gray, green, green, green. That's all. I'm literally this is driving me potty.\u003C/p>\u003Cp>Speaker 1: It's alright. This is the joy. I and, we'll fix it in post. Right?\u003C/p>\u003Cp>Speaker 0: Yeah. We'll fix it. We'll fix it in post. Okay. Okay.\u003C/p>\u003Cp>Do do do do you want them to know what lovely editor, Nat? Let's jump cut here to the point where we fix it, and then we'll explain what went wrong.\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: Welcome. Welcome back. We worked it out. Andrew did a lot more like debugging, adding print statements. Andrew, do you want to show the code?\u003C/p>\u003Cp>And for those of you who are, let's zoom in like many, many, many times over, what was the issue? I'm yeah. But but what was the issue?\u003C/p>\u003Cp>Speaker 1: So the issue was we had things flipped with the Yes.\u003C/p>\u003Cp>Speaker 0: We did.\u003C/p>\u003Cp>Speaker 1: Actual thing that we were removing. And the way that we discovered that, and this is kind of an interesting way to do it. I actually, like, find this as a really good way to do any debugging\u003C/p>\u003Cp>Speaker 0: because I\u003C/p>\u003Cp>Speaker 1: threw a console log into each one of these pieces with whatever we had been removing. So, initially, we so let's, like, put this back to what it was before. Originally, this was is moved left, right, down Down\u003C/p>\u003Cp>Speaker 0: down and up.\u003C/p>\u003Cp>Speaker 1: Yep. And so, originally, we had this. And so I wanted to look here and see where, where we sort of messed up here. And so if you look sort of in this log so, and I think this is the latest game. Is it the latest game?\u003C/p>\u003Cp>Speaker 0: No. We ran it once more since. We ran it\u003C/p>\u003Cp>Speaker 1: once more since. Did he did he go out for the same reason? That's my question.\u003C/p>\u003Cp>Speaker 0: Let's find out.\u003C/p>\u003Cp>Speaker 1: Oh, no. Because this was what he was buying correctly. So Yeah. Did I see\u003C/p>\u003Cp>Speaker 0: But but but but but we we we don't necessarily need to find it or or replicate it. But, yeah, you you basically post it in a in the state just before you died, just before it died. Yeah. And then where and then did kind of what we did with the spreadsheet again. And, basically, we had it flipped.\u003C/p>\u003Cp>So up and down needed to flip, left and right needed to flip. And then our snake has also been a lot more interesting as a result.\u003C/p>\u003Cp>Speaker 1: Yeah. So technically, like, even with bad code, it worked.\u003C/p>\u003Cp>Speaker 0: Change it back. Change change it back now before\u003C/p>\u003Cp>Speaker 1: Yeah. Before we forget. So let's go and I'll actually go in here, and I'll remove these console logs because they're false now. Let's go right. Mhmm.\u003C/p>\u003Cp>And remove this one and left. And and I feel like this is kind of the fun of this game is it's like you orienting yourself is also, like, I think it's part of the challenge here. But now, you'll see here so, like, well, in that last game, he didn't follow the rules like we thought he was going to. Now he, she, they, if we go back in here and create a rematch, we're going to see that, like Kevin said, this game is far, far more interesting now. And so here so now he's not constantly going in that loop.\u003C/p>\u003Cp>He's not running into these other snakes. And there we go. Now we're starting to get\u003C/p>\u003Cp>Speaker 0: some wins. Yes. Now I think that might be where we call this snake because the reality is this snake's doing pretty well. For the extent of our series, we don't need to do much. However, there are some other end statements here.\u003C/p>\u003Cp>Did our snake die or did no. No.\u003C/p>\u003Cp>Speaker 1: No. No. No. That was good. Nope.\u003C/p>\u003Cp>We did the right thing. He he just did head to head.\u003C/p>\u003Cp>Speaker 0: So head to head is the other thing to consider. If you collide with a snake head to head in any configuration, right, if you both enter the same square, the snake with the lowest to health, I think. Right? Yeah. Or the shortest snake?\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: No. Which one? I just gave you 2 options. Oh, sorry. Shortest so it's it's\u003C/p>\u003Cp>Speaker 1: the snake snake with the it's the snake with the lowest health, I believe. No. Wait. Hold on. Let's talk a little bit.\u003C/p>\u003Cp>The shortest snake. Always consult the docs whenever you're not sure.\u003C/p>\u003Cp>Speaker 0: And so and so what you will need to do then is also look around the heads of each snake and have an exclusion zone of one one valid direction in any way they can go. You can also remove the tail as well because next move, the tail is gonna have moved out of place. So these are the little bits of logic you can do. The longer Longer about the snake\u003C/p>\u003Cp>Speaker 1: will survive. Shorter will be eliminated. If they're both the same length, they both die.\u003C/p>\u003Cp>Speaker 0: Fine. Fine. So there is more logic we can add to this, Nate. But the reality is it's gonna perform pretty well. Apart from head to heads, it should perform or running out of food legitimately because it currently is just hitting food randomly.\u003C/p>\u003Cp>It should perform pretty well. Good enough for ready set battlesnake. But, yes, in reality, you'd also have an exclusion zone around heads, and you would be able to take the last item of each snake body and remove that from your from your checks because it's going to move out of the tail space. Or rather, the tail will not be in that space anymore. So you can stop.\u003C/p>\u003Cp>Ahead might be, but the tail won't be. Sick. Okay. Ready, set, battle snake episode 1. I think the last thing I'd love to do before we just say bye and and stop recording, shall we just do a little bit of cleanup on this on this, file from the top to the bottom, make it feel good, and then we can wrap up.\u003C/p>\u003Cp>And next episode, we will take this snake and see if we can run it inside of a director's project.\u003C/p>\u003Cp>Speaker 1: Amazing. Alright. So, yeah, let's clean this up. Let's leave those comments in there because I think they're great. Let's leave that step 4 in there as well.\u003C/p>\u003Cp>So let's go up here. Now we do need to add a couple of things. So let's do, let's call this Directus TV as our author. And we're going to leave our stuff until next week, I think\u003C/p>\u003Cp>Speaker 0: -I think so. -\u003C/p>\u003Cp>Speaker 1: for our default. But, we've got that in there. This is all good. This is all good. Do we wanna leave this or do we wanna move this inside?\u003C/p>\u003Cp>What do we wanna do, Kevin? What do you think?\u003C/p>\u003Cp>Speaker 0: What do you mean inside?\u003C/p>\u003Cp>Speaker 1: Like, do we wanna deal with moving this logic for the head and neck inside of our inside of our other logic?\u003C/p>\u003Cp>Speaker 0: You can straight up remove it. Leave the variables at the top because my head and my neck might are used. My head is used. My neck is not used. We can remove those.\u003C/p>\u003Cp>They're they're captured in the other logic.\u003C/p>\u003Cp>Speaker 1: Yep. You're absolutely right. Yeah. Okay. So we can remove and we can remove my neck because we don't need that anymore.\u003C/p>\u003Cp>And This is all good. I actually think we should put all of these together. Is there a reason that we should have our board width and height as let and our my head is const, or should we just have them all the same? I feel like they should all\u003C/p>\u003Cp>Speaker 0: the same. It literally makes no difference. Like, in reality, I would make them all cons because we don't reassign them. And I think inside of the 4 loops, you can also use const instead of let, if memory serves me right.\u003C/p>\u003Cp>Speaker 1: I feel like there's probably a way to select all of the lets in here.\u003C/p>\u003Cp>Speaker 0: Command d. Command d. Or control control d. Control\u003C/p>\u003Cp>Speaker 1: d. There we go. Let's call these all const. There we go.\u003C/p>\u003Cp>Speaker 0: Lovely. And the reality is we're still being overly verbose here. Like, line 79 could just be put inside of line 81. Like, we don't we don't need to be declaring all these variables, but I think this is fine. We're gonna move it over next time.\u003C/p>\u003Cp>I think we said we're gonna we're gonna try using direct automate to make this work, which I'm really excited about. There are some interesting quirks. I'm not sure I've quite figured out yet. We have a a pressure based rate limiter that I think we might hit, so we'll we'll have to explore that. But we'll we'll see.\u003C/p>\u003Cp>Speaker 1: Yeah. But I think that's I think that's everything. I think we've pulled out any unnecessary variables in here. I think this is looking pretty pretty good right now.\u003C/p>\u003Cp>Speaker 0: Sounds good. Great. Hit Save, and let's let's wrap up. I think this was a really nice first episode. Very happy we cut that that bit in the middle of working out what we were doing wrong.\u003C/p>\u003Cp>So thank you so much for joining us for the first episode of Ready, Set, Battlesnake. We won't see you next week. This is every 2 weeks. So if you are watching at the time it's coming out and not binge watching at the end, you will find the next episode right here on DIRECTV in 2 weeks' time. I've been Kevin.\u003C/p>\u003Cp>I've been Andrew. There we go. And until next time, you ready for the catchphrase?\u003C/p>\u003Cp>Speaker 1: Ready. Set Battle Snake. We'll get there. We've got 4 episodes.\u003C/p>\u003Cp>Speaker 0: We've got 4 episodes. Bye. Bye.\u003C/p>","Hello, everyone, and welcome to Ready, Set, Battlesnake. I am so thrilled for this season to be happening, bringing together a few of my interests all at the same time, including hanging out with my good friend, Andrew. Hello, Andrew. Hey, Kevin. How are you? I am all the better for seeing you. Would you like to tell us what the hell we're gonna be doing for the next 4 episodes? Yeah. That's a great question. So we are gonna be exploring the wonderful world of Battlesnake. More on that in just a minute. We're gonna be looking at how Battlesnake works. We're gonna be looking at how Battlesnake integrates with some other really cool technologies out there. And, hopefully, by the end of this 4 week series, you'll have a Battlesnake or 4 episode series. You'll have a Battlesnake that is ready to go and to jump in and start, yeah, start competing and playing around and learning some new technologies. Or you can just watch us fumbling around. That's also totally fine too. Also very No. I think what might be good is let's talk about what Battlesnake is and then talk about, like, our affiliations with Battlesnake. Probably feels like a good thing to throw out there. But let's start because we've said the phrase Battlesnake one too many times to not jump into what it is. What is Battlesnake, Andrew? Alright. So if you have ever heard of the old classic game Snake, like that old Nokia snake game where you, sort of control the snake to go around on a screen and eat little berries and get longer, and you try to avoid yourself and avoid the walls and avoid other snakes if they're on the board. Well, Battlesnake is that same idea, but moved around a little bit into the developer space. So it's a really cool way for developers to explore new technologies, new frameworks in this kind of technology agnostic way. So you actually, create a web server that responds to the Battlesnake API, and you can crawl control a snake using code to battle or compete against other snakes in that kind of same gamified way, but, in kind of way more fun for developers. And a few interesting notes here. So firstly, unlike snake on your Nokia, multiple snakes on the board at once, and you're basically trying to outlive everyone else. You die in the same ways, but there are multiple snakes just like this on the screen now. And because what you're doing is implementing an API, it means it's pretty technology agnostic as long as you can host a web server that can have a couple of specific endpoints that accept requests and then responds in a specific way. It almost doesn't matter what technology you use, which is pretty cool. And so we're going to be building this over a few episodes. Today, we're just gonna be focusing on, like, the vanilla Node. Js starter snake and challenges so we can introduce you to this wonderful world. You're gonna love it. And then we'll play around with, like, running Battlesnake in a director's project with directors automate, which should be really fun. And then, towards the end, we're going to also integrate dev cycle, which brings me on to a probably good point here, affiliations. Andrew, do you wanna start with, like, your history with this project? Yeah. Sure. So so I actually started with Battlesink back in 2020. So I joined fairly early on in in the the official Battlesink company. BattleState had been around for about 5 years before I joined the team, and it started out as a community project here on the West Coast of Canada. It was a big sort of hackathon event that happened here where a bunch of people have gotten to a room for a couple of days and built battle stakes and competed in sort of live events. I joined the team in 2020 as sort of their first community manager as we were kind of transitioning, as many were in 2020, into that online world. And so we sort of transitioned the whole kind of BattleState concept into an online platform that folks could engage with around the world. In 2023, Battlesnake, was acquired by another Canadian startup called Dev Cycle, where I currently work as their developer advocate. And so I still get to play around with Battlesnake a lot and work with a lot of the great people that were on the Battlesnake team. And and it's actually like the the pre dev cycle times that, Kevin, you and I met, even though technically, we never met in person until Not in person yet. Mhmm. Absolutely. And then, I, Battlesnake as part of going online, run a bunch of livestream series. It was a really good is still, but was really then in its peak, like, peak pandemic. We're doing everything online, ton of live stream series, including the competitive leagues, shows which discuss different algorithms that can be implemented. And this one show called Coding Badly, which was run with me and my friend, Joe. And this is kind of a spiritual successor to Coding Badly, I think. No offense, Andrew. I think that's probably gonna be the vibe the vibe we go for. So I love Battlesnake. And what's really cool about and we'll discover throughout today is at the very core, you know, there are some very simple rules. Don't hit into walls, don't hit yourself, Don't hit other snakes. Don't run out of life like it. Get food when you need it. But once you start to get options, you can really make some choices here. You know, you can say if left and right are both viable options, is there an algorithmically, beneficial way based on certain strategies to go? Do I box myself off, but now we only have so much life? Do I try and find food as quickly as possible at all cost to also starve out other snakes and so on? So all of this is implemented in code, and then when the games actually happen, your hands off. You know, your your algorithm takes over and makes decisions. So, yeah, I think that's that I I think that's most of Battlesnake. Any other thoughts, Andrew, before we crack on? I mean, let's, I mean, let's jump into the let's jump into the docs because I think they're gonna give us a good idea of kind of the some of the things that maybe we missed. And I think, actually, I'm I'm not a 100% sure. I haven't been in the docs in a while. I may still be featured in, like, the what the heck is Battlesnake doc. So I'm very interested to see if we can get it. Shortly. Am I there? The real question. I'm not oh, wait. No. Hold on. Quick start? There I am. I'm definitely I'm definitely in the quick start. I know this. Am I still here? We'll we'll throw this video into the resources that accompany this video on Directus TV if you wanna go and watch it in full. Awesome. Yeah. So when you click on that, what is dev cycle, it brings you over to the dev cycle documentation, and this documentation is fantastic. One of the things that Kevin was talking about, a lot of those sort of specific things that you can and can't do, if you wanna kinda figure out what that's all about, you can really a great place to go is actually checking out the game rules. And so this is where we start to look at things like this collision idea. So, like, self collisions and body collisions and head to head and who wins in these different situations, and then also giving information about some other things that are really important in this kind of gameplay. So you have a starting position in the game. We'll talk a little bit more about what that looks like kind of as we go through. You have health. That's a dynamic in this game as well. There's food spawns and hazards, and we're not going to get to a lot of that stuff necessarily today. We're gonna see that kind of as we go on. Yeah. But checking out this kind of game rule section is a great way to, like, get a a solid understanding of the idiosyncrasies, I guess, that exist in Battlesnake over sort of the, the the traditional snake game. The other great thing is this rules repository. So, like, all of these rules are actually in, an awesome GitHub repository called Battlesnake Rules. And so if you would rather not watch a video or if you'd rather just do, like, a different kind of deep dive, you can actually, like, jump into the rules repository, which is public, and you can go through and kinda discover a lot of these things yourself. It's all built out in Go. So if you're not a Go developer, then maybe not for you, but it's a useful place to kinda check out all of this written in code. And, yeah, and that was gonna be my clarifying point. This isn't pros. This isn't written out rules. But this is codified rules that actually run within the Battlesnake engine. So you can get right in there and understand again the intricacies of how it all works, which is really cool. I remember possibly in a coding badly episode, definitely in a battlesnake stream in the past generating, battlesnakes that that, like, actively hook into this rule logic very directly, something like that. Okay. So how do we get started? I think we're gonna stick with node. Doesn't matter what language you you use in the real, but, you know, given that directives is all JavaScript view node, and that's at least what I know. That feels like a good place to start. Yeah. I'm with you. 100%. So couple places you can go. Obviously, the quick start that is here. So, basically, anywhere you go in the documentation, you'll find the quick start. This one is set up in Python. So, like, if you watch the video and you've never programmed in Python, it's still kind of valuable, and this will kind of walk you through the game logic. But it also does, in this kind of quick start area, let you choose from different snakes. So I highly recommend if you're just getting started with Battlesnake, click on that quick start, and you'll get the kind of fundamental understanding here. So when we say you are building a web server server that is kind of serving as your battle snake and it's it's interacting with the battle snake API, this is exactly what's actually happening here in this sort of representation here. So, the game engine is querying your web server where your battlesnake is, and your battlesnake server is returning a response. That response can only be 1 of 4 things, up, down, left, or right. That's right. Right. That you received from the game engine, and then you just are kinda repeating this process over and over and over again. So game engine is sending something to your server. Your server is sending something back to the game engine over and over and over again. And, I guess one of the the kind of gotchas here is, the web servers only have 500 milliseconds to respond. And so if you are sort of some people run these on Raspberry Pis and some people or some people run them on you still run them on Heroku servers. And so one of the things that we would tell people is make sure you go and, like, do something on your Heroku server or your Just to see how the code stop at the beginning. Yeah. Exactly. But, but yeah. And and, Kevin, I don't know if I ever told you. Do you know what are the reasons why this 500 millisecond rule was implemented? Have you ever heard this story? No. Sorry. I just realized. I don't think you can see me. So I I'm doing a No. I can. No. No. I can see that. I'm, like, down here. No. I can't. So so I, so in one of the early kind of days of the battle sync competition, before they had this 500 millisecond, like, response time that was there, somebody realized that it was actually faster to respond with a physical keyboard or a game controller than it was to send code back. Love. And so somebody actually went and built a Battlesnake that was hand controlled, and then they would respond in real time. And it's interesting because I think they did fairly well. And at the end of it, it wasn't like, no. You did the wrong thing. It was like, great. You kind of you broke the rule, and now we or or or, like, defined the new rule for us. And so That's funny. I think you could technically still do it, but, you'd have to have some pretty fast thumbs. In planning for this series, not to spoil it, but we have spoken about what it might mean to change strategy, like, mid game. You know, there are there are ways we can achieve this. It was not real time. That's really funny. And the interesting thing about that limit is it really forces you to be computationally efficient as you start to build more complex things. At the beginning, literally, it doesn't matter. You're as long as your server can physically respond in that time, you know, it it doesn't matter. But what you can do with things like at the beginning of a game, spin up some kind of machine learning or artificial intelligence resource, and then per move, you can call on it, but you have to do it very efficiently. So are we gonna start with a starter snake, or are we gonna start from 0? No. No. I think we're I think I think let's start with a starter snake because that's what I think most people are gonna do here. Perfect. And so we'll go to kind of the first step. We're gonna choose our starter project. I'll just open this up in a new tab here. And what I kinda love here is, and I was talking to Kevin before the the show started, is like, so I'm running on a Chromebook right now. So if you're sort of a newer software developer, and you're, like, just getting exposed to this world, and you're, like, I don't have a device that can run this. If you can run a Chrome browser, you can run this. Absolutely. I mean, if you wanna have, like, a crazy setup, like, some people have, like, stand alone servers that run their state, You totally can, but you definitely do not need to do that to kinda get started with this. No. Yeah. Not at all. And so what's also great here too is so you can see these are the official starter stakes that are up on the screen. Yes. They are up on the screen. I'm gonna zoom in a little bit. I'm gonna try and zoom in a little bit. I'm so used to, like, the Mac keys, so I always click the I've used a Windows keyboard on a Mac device, so I'm always hitting the Windows key. Anyways, so You can you can remap them. That's what I had to do. I have a German keyboard on my physical MacBook. I'll just remap the keys in it. Just a few keys on as they're printed, but you just get used to it. Oh, I like that. I should do it. I feel like I've tried it before and it just didn't work. Anyways, not important. So, 5 starter snakes you can start with, which are, like, officially supported starter snakes. So Python, Go, Rust, TypeScript, and then the last one there, JavaScript is what we're gonna look at today. But if you're like, I really wanna do an f sharp snake, there is an f sharp snake for you there. And there's some really cool ones that have been defined in, like, some really, like, interesting languages and setups. Totally worth checking out. But today, we're gonna jump into the JavaScript official snake. Lovely. And what's awesome about these is so you can run these on your own infrastructure. So these are all templates that are set up on there. So you're welcome to run them on there. But we do have these set up ideally if everything works out still. I have not run one of these starter stakes in a while. That makes sense. See if everything works well, is you can just run on Replit. It's just a really simple Node. Js and express server, and, like, there's Docker files for external things, but everything runs right out of the box if everything goes according to plan, which it almost never does. So shall we click the button to show you what? Why would you say that? Now it's all gonna go pear shaped. I know. You say that. No. See, now it goes perfect. You gotta call it out. Right? You gotta call out to that You gotta manifest it. And this is gonna be we're gonna nail it. There's not gonna be any any any errors. And I'll Well Battle Snake's gonna win the league. What's that saying, though? It's like break a leg. Right? You say break a leg before they go on the stage because you're, like, saying the bad thing that might happen. I feel like it's the same thing here. If you just say, like, this is not gonna work at all, it works perfectly. Allegedly. Let's find out. We're gonna see what happens. Alright. So we're gonna click here. We'll see if I'm logged in. I have a feeling that I'm not. You're not. I'm not. But I don't think it really mat I think it'll still spin up if I'm not logged in. We'll find out. We'll see what happens. Nope. I have to log in. That's all good. We've follow look at that. I didn't even know we had followers right now. Alright. I'm gonna close you because we don't need you right now. I'm gonna close you. Yeah. And then when we when we get into REPL, it will bump the font size up significantly, I think. Yeah. So, yeah, it's this easy. So we're literally just clicking on that fork. We're gonna do an auth zero sign in. Hopefully, we can skip past the stage where I'm gonna put my password. Let's go. I think Toby Flender snake is still on Replit 2, which is my which is my battle snake. Oh. This is what this is what I knew was gonna happen. Alright. But you're log but you're wait. You're not logged in. It it hasn't logged you in. Oh, weird. That's weird. Alright. Let's log in again. Let's go log in. Oh, I love it. All the errors, even at the authentication stage, we're running. This does not bode well. Oh, you know what it is? I think it's because I'm like, I need to auth with GitHub. That's probably what it is. I do have it on that email, but I'm not auth with GitHub. So let's go do that. Oh, I hate that sometimes when you log in with, like, an SSO provider, but your email address is the same with that SSO provider and you're like, I don't I don't know which which system. Did it work this time? There we go. Okay. Okay. So let's go. So we're in here, and I probably got a bunch of snakes in here. We'll go back over, and we'll jump into our starter projects again. We'll jump back into our JavaScript snake. And so I've logged in now. Don't need to worry about billing, but this should be a much more straightforward process. I love I said everything is gonna go incredibly terribly. And even at the auth stage, I definitely have jinxed this. I'm not saying I told you so, but I'm certainly thinking it. Alright. So here we go. So this is the this is the snake. I mean, let's get it in the template right now. Yeah. What do we wanna call this snake? We're gonna call this when you call it something does does the dev cycle mascot have a name? His name's ToggleBot. So I don't know. Do we call it, like, we could call it ToggleBot. We could also call it, like, coding badly rebirth. We could call it, we could call it, let's call it let's call it ready, set, battlesnake. Ready, set, battlesnake. Alright. Let's see. I was worried you're gonna be, like, does the does the rabbit have a name? Does the director's rabbit have a name? As far as I'm aware, it doesn't. So set myself in a losing battle there. Let's use the template. I'm very disappointed. To you. Could be right. Could be right. Here we go. So it's forking. If you've never used Replit before, by the way, amazing cloud based IDE, super powerful, integrates with all of the things that you're already using, but also has a lot of inbuilt features. If you've used things like so if you've used Gitpod, which is, or Codespaces, which are sort of in the Code sandbox is another. Code sandbox. Yes. Code sandbox. I find, somebody described it to me recently though that Replit is kind of like the Google Docs or, like, Google Suite of, like, cloud IDEs. It's just, like, very accessible. Mhmm. Yeah. Bump your font size up. Let let's let's make that text more accessible because I can't read the damn thing. Alright. And I already broke stuff. There we go. Let's zoom in. Wonderful. Alright. So let's look at the files that we have here before we start messing around with anything. So it immediately brings us into our index dotjs file. The only other two things that we have in here, ignoring, like, our our package and all the rest of that stuff, are our readme, which is gonna kinda give you, like, things to do, which we're gonna be looking at in that sort of quick start. And then we've got our server dotjs, And this is basically, doing what we described earlier with those different responses that you can do to the Battlesnake API. So there is the just sort of, like, base level. And what what do you call that? Like, the standard with nothing else out of it? The site. There you go. No. No. I mean, like, the the actual just like a slash. Like, no additional Oh, sorry. Sorry. You're referring to that. I would call that the root route. Boom. Root route. So, like, your root route, and we'll talk about kind of what all these things do in a minute. And then you've got your start post route. You've got your move, your end, and then we've got a bunch of other little stuff here, including a console log that actually says your battle tank is running. And if I may just kind of embellish this a little bit. So this main endpoint that we care about is this move endpoint. That is the endpoint that will receive board states and ultimately has to respond with a direction. You'll notice there are these other ones. So this route endpoint handler, route handler there, that will respond with information about your snake. We'll do that in due course. But the start and end are interesting. We mentioned earlier about provisioning resource. That's basically where you would do that. Right? Because I think you get a small grace period between the start endpoint being hit and the first time the move endpoint is hit in any given game. And then your snake can be entered into many games. Yep. Yep. Absolutely. And then yeah. There there's a bunch of stuff. We'll we'll kinda look at some of these and see what they do, but but but Kevin's absolutely right. Like, move is really what matters, and that's where you need to return sort of up down left or right. So the other thing just to look in here, especially for the snake, is just kinda looking at these, like, what you have in this basic package dot JSON file. There's really nothing there. This is a super I think. Super, super light template. And you can go crazy with this, but this is a very, very light template. Mhmm. Okay. So, do we wanna do we wanna run this or should we look through first or should we head back over to the quick start? What do you think, Kevin? I think I think we could do a little less with the quick start because you and I have both like, we should I think we should refer to it as and when it's needed. I say let's get the let's go to the Battlesnake platform. Let's take this basic snake, which I think what what if you scroll down this file, what does the move endpoint do at the moment? Oh, there is some there is some logic there. Yeah. We'll talk we'll talk a little bit about that, but it does do stuff. So let's let's set up this snake and get one game running so we can kinda get to grips with how that code becomes a battle snake in a game. I think that that feels about Kevin, I have one question for you, though. What do you think I mean, Replen is trying to tell us to do this desperately, and we haven't done it yet. What is the thing that we need to do? Oh, I wonder if there's one call to action on this page that is significantly brighter than the oh, okay. Alright. Yeah. There was no mystery. We're hitting run. Awesome. And so this is the piece here. So this is the piece that tells you that your Battlesnake is running, is you're gonna see this API response here. So you're gonna see this API version, the author, color, head, tail. And then in your console, if it's running, you're gonna see this running battle snake at whatever the server, domain is and, or server address is and then info. Now because of the nature of Battlesnake, you need to have a public, URL that you can share with the platform. This is new. They used to all be public and has since shifted. So I think we need to deploy our app. No. We don't need to deploy our app. So we're gonna see what happens. We're gonna see if we can use just this. Yeah. Let's go to new tab. And then I yeah. So it'll be like this, and let me bump this up as well. We'll see how much it bumps up actually. There we go. So this is the same thing that we're seeing here. And then in our, in our navigation bar, we have this, like, replit.dev link, and so that's what we're gonna put over into the Battlesleep platform. It used to show up right here. I don't know why it doesn't anymore. I wonder if it should I imagine I imagine it got a bit unwieldy as you build more complex URLs by that. That's right. That must be it. And that's probably more useful as a developer just to see the the path, but who knows? You know what, though? I have a feeling with a lot of these platforms, it might also be. Yeah. You know what? So the what you can do is if you just, like, right click on this, like, 0.0.0.08 1,000, similar to other platforms, it'll actually convert it to whatever that public URL is. Oh, that's interesting. So it can actually just copy that over there. Okay. So that's working. So let's head back over to play.battlesnake.com. I'm so excited. Play. Play. Tailwind is a very nice little very nice little playground. It is a very nice playground. This is like this Chromebook has become my central development, tool. And so, like, I have so many, like, interesting things on here. I never thought a Chromebook would be my daily driver. Alright. So over on the battle 6 site, auth with GitHub, highly recommend. Not that you need to, but, we're gonna auth there. Oh, look at that. Inclusive waffle. Good. Okay. So I'm logged in with my personal account. So here's what I love. I used to so I'm a teacher. If you didn't know that, what you Oh, really? You have absolutely no mannerisms that would give that away. Like, what should we press on the screen now? Is it the green button? But I I I introduced, my, like, middle schoolers to, to Battlesnake a couple of years ago. And, like, all their snakes are still in here, which I kind of That's fun. Some of these are That's Toby still mine, though, runs on node, on Node RED. On Node RED. That is a stellar platform, if you are looking at, having a stake. And actually, funny enough now now that I think about doing a directus snake I was just about to say it. Yeah. Yeah. So so we have, directors automate as part of that. We have flows, which is a low code automation builder. And, yeah, if I whenever I actually describe it to developers, I ask if they've seen Node RED because I think it's very comparable. You know, you have automation builders that are very much like Zapier, and then you have ones which are more like Node RED. And this is more like that where you're wiring together these these these operations. But, yeah, we'll get to that. I love it. Alright. So, we gotta add a snake in here. Now if you're new in your account, I think it prompts you where to add your new snake. I haven't done this in a little bit, so we're gonna see. I have a feeling I actually need to go into my battlesnakes. Yeah. We're gonna find out. There we go. And here we go. So we got all of our snakes that are currently in here. We're gonna create a new one. We're gonna call this one ready, set, Battlesnake. We're gonna drop our server URL in there that we copied over from do we still have it? Yeah. There it is. I think that's And specifically without anything after the slash. We have to increment those, but that's correct. Yeah. So this is what you're gonna see, something that looks a little bit like this. If you wanna try and copy this and use my snake, go nuts, or use our snake. And then the next thing you choose here is your engine region. And so I highly recommend that when you're getting started, you don't worry too much about which engine region that you're using. There's a good, like, kind of breakdown on why you would use a different engine region. I'm based in in in North America, so and I'm kinda closer to Oregon, so I'm gonna set the state there. Kevin might wanna set it up based in the Netherlands, but it really, really doesn't matter at kind of the base level of Battlesnake. It it matters when you're squeezing out those milliseconds worth of worth of performance, but we're simply not. Exactly. And then, again, description you can add, same with programming language. This is just fun. It gives it a little bit of flair. So you can add a JavaScript, and then we can say this is Platform. We need to we need to do some work here. By the next time we record, we're gonna be doing some work to this list because we'll be we'll be moving we'll be moving our snake over. I love it. Alright. So let's go. And what are we gonna find? What are we hosting on right now? We're hosting on Replit, so we should have Replit there. And what I love about this list too is you can actually see, like, here are all the different places that you could host a snake. Now some of these I highly would not recommend. Like, get out Codespaces. I don't think you can actually keep a long running server going. But Interesting. No. Yeah. Yeah. You have to have the Codespace, and then they go to sleep. Yeah. But lots of different cool options here. And then the other thing you can do is you can set it so that other people can interact with your snake. And so the upside here is that you can allow other people to kind of play around with it. The downside is you can have people that decide to challenge while you're using your snake for some other thing, and then you're having to deal with all the compute costs. And if you're running on, like, AWS or something that charges you for all of those compute hours, definitely challenging. It's not just that. It's every request you get in relation to a single game has an ID of that game. But at basic levels, you're unlikely to be segmenting game logic. And if you're doing, you know, basic battle snakes, we'll just look at a single board and make a single response based on the heuristics of your code, the algorithm you create. But if you're doing something a little more clever way, you're looking over multiple turns, it screws you. But by that point, I suppose you are you are using that ID, but that's worth considering as well. Yeah. Absolutely. Okay. So let's jump in here. So we'll leave it as private. We'll save this battle snake. So you'll know once you save right away if your battle is actually there because it'll show up with the name, obviously, that you set it here. If you don't, though, you won't get any response here in this ping. So you might put, it used to be that if you started a snake on a service, it wouldn't automatically go. And so you might have to run this ping just to kinda see. And you can see here, if we do this ping, we were talking about that 500 millisecond response time. You can see that Replit is really up their, like, their timing. It used to be They didn't. They didn't. That first response was a few hundred. So that must be like a cold start kind of like now it's middling around 40, 50, 60, which is great, but it was multiple 100 the first time you, the first time it was there before you hit ping again out of interest. Yeah. That's true. So But then that's what you're starting to see. A good idea. Yeah. Yeah. Okay. So we've got we've got ready set battlesync in there. You'll also see you kinda get the flare that's related to the the language and and sort of hosting service that you're using. And so now, our Battlesnake is in there and is ready to go. So, do we wanna make our Battlesnake look good before we bring it into the game or do we wanna bring it into the game? Let let's jump into it and maybe we'll see if the the Battlesnake elders allow this. We might see if we can do some custom customization during the the act of us recording 4 episodes. But for now, let's just leave our our snake a slightly boring gray. We can come back to it. When when we come and update the platform to direct us, that's where we'll do the customization. That'll be next time. I love it. Alright. So, we're gonna go in here. You can choose. So, well, in the traditional Battlesnake game, or traditional snake game, I guess, it's kind of a standard map. No hazards. It's kind of just food pops up and things like that. So we're going to choose just the standard mode and a standard board size of 11 by 11. And we're just going to add ready, set, Battlesnake onto the board. We're not going to add any other snakes in there. You can add some bots. These bots are always running that have, like, some set sort of modes, but we're just looking to see if our snake is ready to go. So let's go ahead and see, how ready set Battlesnake runs. Alright. We're in. Okay. We're here. Should we have it now? You have to. Oh, yeah. Yeah. Come on. Let's do that. You ready? I'm so thrilled. No. I'm good. Alright. You ready? Yeah. Ready. Oh, no. No. We have a we we we get a catchphrase for this show. What? If Reggie said that Oh, my goodness. Yes. Okay. Here we go. Okay. Of course. Alright. Let's go. Ready. Ready. Set. Battle snake. That was thoroughly underwhelming. I'm gonna be honest. But but we are watching the snake. We got So this is what we got. So you see the ping? You saw the ping going on the right. So it was still around that 40 millisecond mark. There were 47 turns that happened before our snake died. Why did it die? And the nice thing about this editor, this player, of course, is you can step through your turns. So it was performing kind of a slightly eclectic set of moves, which is great. But what eventually happened to it? So it was at the bottom and it went off the board. It went down. So that was that's that's what our snake did. Now just to be clear, we'll look into the logic of our battle snake next, but we don't quite know why let's look at our code. And now we're at the point where we can start customizing this, this battle snake. Alright. So we're gonna jump back over to Remplit. And so all of the things that you need to know for this snake when you're getting started are all gonna live here. And the other thing that's really cool here that I guess we didn't talk about earlier and maybe you didn't see here because we didn't go that far down in the code is we're actually returning into the console every move. So you can see why it moved or not why it moved in that direction, but you can see what happened. So this in this game start move 0, move 1, all of these commands that are happening are in here. But and this is sort of included in the base snake that you get here. And you can return lots of things in there. Like, you can return, like, what's leading into that. You can return logic. You can return things like shouts, which are just like little statements that are in your code. We kinda got rid of them. It used to be that you could do custom shouts that were displayed on the board of the games, which was very cool, but, they kinda disappeared. But, okay. Where where do we wanna start, Kevin? Well, the nice thing about this starter snake for learning is it talks us through some steps. But before we do that, why don't we look at the code of what our battlesnake did? So it didn't just go in the same direction nonstop. Oh, that's another note. If your sync doesn't respond within 500 milliseconds or responds in an invalid way, it will continue to take the last direction There are a couple of variables here just to help us out. One that tells us where our head position is, and that'll give you an x y position coordinates and our neck, which is the second piece of your body. It's not all of them. It's just your head and your neck. There's a reason why your neck is important. We'll talk about that in a moment. And all we're doing here is oh, it's actually a lovely lovely and commented here. You can turn back into yourself. So if you're going straight up, you can go down, but you die immediately because you collide with your body. So all this logic is doing is saying don't hit the neck. Like, don't go back into the last space I was in, which is always the second position of the body. Now another thing that's interesting, if I may just kind of embellish kind of what's here, is we're starting to see the data structure play out a bit here. So this move function has an argument called game state. We see on lines 53 and 54 that inside of game state, there is an object called you. And inside of that, there is an array called body. And we can immediately assume that they're full of x, y coordinates. And in fact, that's that's made clear on line 56 where my neck and my head both have an x property. Before we continue, what might be interesting oh, I'm sorry. And so so the rest of the logic here is turn up, down, left, or right in that in that array, in that, object at the top, make them force if it means I'm gonna collide with my neck. Remove that as an option. And then I believe what it does is it basically, yeah, randomly picks 1 on line 87 and then returns the randomly selected valid move of which just doesn't collide with your neck. It does nothing else that's fancy. That's what we'll be doing today. Before we continue on this, can I make one recommendation that we do go back over to the docs and look at the game object so we understand what else we have at our disposal? Because I think it's important. Sorry. Not the get yeah. The game object. The board? Yeah. It's the board object. The board. The board. Perfect. Bottom left is 0. That's we're calling that out because when you draw on screen, sometimes 0 is the top left. If you do math, it's in the bottom left. So just note, 0 zero bottom left. That one screws me every time. This is what the object looks like. Could you zoom in a couple of sets by any any chance? Cool. Yep. So we have a height and a width. That's the size of the board. That is obviously important to know. We have the position of all the food, the position of all the hazards, which we're not playing within the classic game style. But if you hit hazards, I does your health go down or do you die? You die if you hit a hazard. Or well, depends on it depends on the game mode, but a lot of time you'll die. Fine. And then you have an array of snakes. Each snake has the idea of the snake, but it also has look at that. That was that was good teamwork there. It also has its health, all of its body parts, a convenience, which is an object called the head, which is always the first option in the body. So that's just a convenience there. They're always the same. The length, any customizations. But really what we care about for logic realistically is the body array and the head as a convenience. But we could get most of what we need from the body and the board collectively. What else is there here? Rule set, the game itself, but I don't think we care too much about those in this very moment. Yeah. Yeah. And I think the only other thing that's kind of in here that's, I mean, less it's less valuable. This is more like you you can see. Like, imagine that if you're in this game, your snake can see everything about the other snakes. So, you're also sending all this information about your snake to all other snakes on the board. So Yeah. You could stock out snakes that are low on health. Yeah. Yeah. And some people even decide, like, I don't wanna ever, I don't ever wanna attack a purple snake or a pink snake, and they'll just decide, like, I'm gonna avoid all of those snakes. Just and you have the ability to do like that. These weird kind of logic pieces, which I think is kinda fun. Yeah. Sure. Cool. So that is the shape of the object, which I think was important to dig into as we were starting to get a sense of what it looked like. So we know that we've got a board. We know we've got, we know we've got, sorry, a game. We've got boards. Boards have all the snakes and the board state itself. Snakes have a head and a body. So I think that's basically all we need to work through here. So all this snake does right now is avoid its neck. That is all it does. So Yep. What is the step one suggestion? So step 1 is to prevent our Battlesnake from doing exactly what it did by moving out of bounds. Okay. So this I mean, logically I mean, you and I have both done this kind of more simple battlesnake a a ton. But, you know, we will run through it kind of, you know, we come with a little bit more confidence in the approach, so we'll talk about it. But just know that in this little bit, there'll be a little less trial and error. Just so don't feel bad if if you're working through this and it's taking you a little longer. We just we just happen to know these first few steps like the back of our hand. So right here, there are a couple of comments that will go into that nested object and create a couple of variables for us, board width and board height. In this game, 11:11, but they can be smaller. They can be larger. And all we wanna do is say sorry. Go ahead. No. I'm just gonna say, my eyes my eyes are burning right now. Do we see a do we see a dark mode? It will exist. It has to exist. This is shocking. Our confidence. It it has to exist. Do you need to save save the snake or does it autosave or something? No. No. So everything auto saves. Okay. I recognize it. I'm just, like, I'm motivated for dark mode, but I also Does it take your does it take your, like, theme of your Oh, look at you. Look at you, Kevin. Look at you figuring out the smart thing. I bet you it does. That's the wrong one that I want to turn. Where's my dark mode? Mode? I wanna click on it here, and then I wanna set it on dark theme. And then I bet you if I refresh this, it's gonna be dark. Yeah. Okay. I'm very confident that that's going to happen, but it may not Oh, did I say I'm really confident? That's where it all falls apart. Yeah. We've already learned that that that's how it works. Nope. Did not happen. Here we are. At least it's dark in some places. Is it in your user settings? It might be. It's odd that it's not actually, like Like, here in the editor itself. Yeah. Maybe in your account, that you set up, like, your your default editor settings. Let's see. Let's see. Billing, account, themes? None of this. Themes. Themes. You know what? I wonder if that editor has, like, a command palette. Oh, how do I do that? Boom. Beautiful. Are you gonna catch it here? Do I gotta refresh again? Oh, you're gonna make me refresh again. Alright. I see you. I see you. There we go. Beautiful. Oh, look at that. We got some dark mode battle snake as well. But oh, actually, does this still exist? There used to be. Yeah. You can. Dark theme. There we go. Nice. All dark Okay. All the time. So let's go back to our code editor then. Sometimes in dark mode, things are just slightly less legible. So maybe let's just do one more step up on the font size, if that's alright. Yep. Lovely. And right. So we've got the board width, the board height. So real realistically, this code is gonna run every single turn. We're gonna know the size of the board based on these values, and we're gonna know our own heads x y position. And all we wanna do is the very pragmatic, am I on the very far right of the board? Yeah. I can no longer go right, left, up, and down. So that's the logic. We kinda have logic that looks similar to this above, but we can write it from scratch. That's also cool. Take it away, mister McLean. No. We're gonna see. So you say we're gonna write it from scratch. I, I fundamentally disagree with you, sir. I feel like if we're provided with this code, I feel like we should use it. Alright. Here we go. So here, we were looking if your neck was less than your head, then you didn't wanna move left. So we're gonna remove some of these comments, but it's gonna be the same kind of concept that we're doing here. And so let's look at our let's look at our head. So we wanna get our board width is gonna be important in a minute, but let's get our head. So my head x, and then we want our head x if it's less than or equal to or greater than or equal to. Well, hang on. Fin finish the thought. What what direction are we doing here? Left? Yes. So we're doing so we're doing x. So we're doing the x axis. If it's So we wanted to 0. If it's 0, it's on if it's 0, it's on the far left of the board. Yep. So that's all we need to check. If it's left, remove left trim. There is no minus one. You just die. So, double double equals double equals for for a comparison. Nice. So that's our head x. So let's do our head y now. So if our head y equals our board height So we're doing the top now. We're going clockwise. We're doing it. We're doing the top now. But the thing here is because you're gonna get your board height, but then you need to be minus 1. So, like, your board height because it's 0 indexed. Exactly. So you're gonna do your board height minus 1. So this is basically saying if my oh, and not my neck. We want that to be my head. Oh, yeah. So if my head y is equal to the board height minus 1, then we're gonna set up to be false. Yeah. Alright. So let's do our next one. So that means that we're not gonna go off to the left of the board too far. It also means we're not gonna go up too far, so let's keep going around. So let's do else if my head my head, and let's go x again, and let's go we'll figure out what the in between is gonna be, but let's do board width minus 1 and is going to be It's it's the same. It's just a double equals. The I I literally cannot get behind you doing this clockwise. It's driving me nuts, but we're here now. We're here now. It's so funny. I would I would have gone left, right, up, down, but I think that's because that's, like, how CSS rules are structured. Left, right, up, down. But yeah. Isn't that yeah. That's why I was like, what are you doing? Yeah. So this last one is gonna be, down. Right? Yep. And so this one's gonna be my head y equals equals 0 and get rid of that. And this one's going to be, down is false, and then we actually need to change this one to right is false. And so this logic here, if you haven't been following along, is going to be if your head is equal to 0, you can no longer go left. Type of. Did I type Hit backspace. Oh, right. Hit backspace. Is move safe right. Yes. So here, if your head is at x is at 0 sorry. Your head x is at 0, then you are not gonna be able to go left. If your head y is at the top of the board, you're not gonna be able to go up. If your head x is at the far right hand side of the board, you're not gonna be able to go right anymore. And if your head y is at 0, you're not gonna be able to go down anymore. Cool? Do we wanna should we comment this? We're not gonna comment. Get rid of those comments. Who needs comments? You've got a whole video to go along with this. Exactly. Alright. So let's, it should automatically update. I'm gonna just refresh here, and we'll see if it works. Normally, it does. It's pretty good in real time. So let's go and see what happens. Let's just create a new game and see if our solution sorted itself out. So all we have to do here is literally just create a rematch. It's gonna go and read in with our new Battlesnake data. We're gonna see what this looks like in dark mode. We may be changing back to light mode. It's almost too dark now. I feel like I need a like a beige mode. Like a like a, what is it? Like a Solaris. Is that what it's called? Yeah. There you go. Like a sepia mode. Yeah. Alright. Oh, this is for so long and my wife laughed at me. We also called it Nokia. So in the background right now, all of these moves are happening in the background. If we hit play and we get up to the latest turn, it kinda just starts to slow down, and we only and we see moves in real time. So what we're kinda letting it do now is catch up. So when we hit play, we can just watch it all in one go, which is Yeah. Pretty nice. The other great thing that you can do here is you can actually change the playback speed. So if you wanna watch it slower, you can if you wanna watch it faster. We're just gonna leave it as medium. There's also some other things you can do here. Like, as soon as the first turn is ready, you can auto play in these games. That's nice. You can also grab, like, a scrub bar so you can see how long the game is gonna last. It's really only good for you. If you're doing that in a competitive game, it's a little bit less fun. And then you can also show board coordinates. I actually think this one's interesting because I think this will show folks something interesting in the game. So let's go back here. So we got the board coordinates up there. As you can see here, 0011. So this is the stuff that we're talking about. Right? So when we said the board width, which is technically 11, even though it's 0 to 10, it's an 11 board. So if we'd left it at that and just said board width equals Yeah. The the the upper the upper right wouldn't have worked. It would have let it go off the yeah. Let it have died first. Let let's hit play so you can see what this thing does. So now it should avoid its neck, and it should avoid walls, which realistically means it will die by hitting itself or running out of food in theory. Yep. And that's exactly what exactly what happened. Ran into its body. And so this is what we mean here. So, technically, the neck counts as part of the body as does the head, but we've defined the neck in our code. And so he's never gonna run into his neck, but it doesn't avoid him running into anything past his neck or or like Kevin said, running out of food. So, and you can see here, like, he's actually surviving a shorter period of time even though we have more code. But that's honestly I think you're absolutely right. That first time was a little bit of a fix. Yeah. Absolutely. Oh, interesting. That should not have happened. That should not have happened. Oh, I see. So head is technically at 0. It might have been because he's at a he's at there's no other safe moves, but that's not true. So what happened on that last move? Did he yeah. He went down. Interesting. Let's let's just quickly check it again. When x is 0, if you head back to the code, when x is 0, remove left. When y is right at the top, hold height minus 1, you can't go up. When x is at the width minus 1, you can't go right. And then when y is at 0, you can't go down. Interesting. If or else if that Oh. Oh. No. No. No. I I I I I got it. This is in a a weird, like, else if else if else if. We we don't want this. We we we want each one to be its own individual statement. All of them need to be Oh, true. I love that. If you move the else's and and you change. I love it. Alright. It I'm not sure that's what the explains what just happened, but that was wrong. Like, it needs to be more like that. Alright. Let's see if that fixes things for us. Oh, timing out. Well, no. 42. Oh, that was an error. Let's scroll up. Let's see we'll see what happened. Just go all the way up to the top of the error. Alright. What's happening in here? I need to zoom out a bit this a little bit. Just give me one second. Board width is not defined. We made a typo. I think board width. Board? On line 70. There is on line 70. Oh, define the variables. Like, let put a let in in front of each one. So what's interesting there is it means it was running our old code before. So that's that's part of the problem is it was actually running our old code. So now if we run this, k. Our battlesnake should be up. Let's do a game again. And the moment you hit create rematch, we can go back to repl it, and we can see that things are happening. We saw that it made it 34 moves at least. That means all the moves have played out, so we can just hit play. It's looking promising. Yep. Yep. Same thing. And it went into its body. I wanna I wanna examine that because I think that's interesting. Right? We had that l tiff. Why why was that not working? Why why do we think that wasn't working? Like, where's the logical error in that? Oh, if if you're if you're at the bottom and the right, it'll only run 1. It'll run the first statement it it gets, and then it will. There we go. So you need to you need to get you need to get each of them. So this is now we think working. We'll we'll keep an eye on this one. Let's assume about that, like, logically, this feels good. If it starts moving out of bounds where there are viable options available, we'll come back and revisit this. The next step is to get it to collide is to get it to not collide with your entire body. Right now, it's just avoiding the neck, which is the second piece next to the head. We wanna avoid all of the pieces. And once again, Andrew and I have created start to battle snakes dozens, if not hundreds of times over. So what what are we gonna be doing here? We're gonna basically be writing a loop. We're gonna go through every piece of the body, and we're going to see if it's if it's next to me just like it was a boundary, we're gonna remove it. So we're gonna actually end up using reasonable amount of the logic. The logic is gonna look quite similar to the one above, but inside of a loop. Great. And we don't we don't actually need to do, we don't even need to we don't need to care about the length so much because we can, we can just use a 4, a for of loop for this, which is a syntax, which I really like. So I'll introduce you to a for of loop. John, sure, you cannot you know what we're gonna do. We're gonna do what every good programmer does, and then I'm gonna go to Google and look up how do I do a loop in JavaScript because I have legitimately You got me. You got me. You got me. I it it auto filled. Hang on. Hang on. Head back to Replit. It was helping you out there. It was doing it was and also w three schools. So so if you wrote the word for first first of all, it did actually kind of something yeah. Look. It's kind of giving you a hint here. So this is a very vanilla JavaScript loop. What this is, there are 3 parts at the top. First thing it's saying is, wow, okay. That's cool, I suppose. So we're initializing the value I with 1. We're saying keep running this loop for as long as I is less than the the the body length. And at the end of every iteration before you start the new one up I by 1 and I is a is a number, which you can feed into an array to get an index. There's a nicer way of doing this though, in my opinion, for this use case. So I'm gonna propose comment this out because I wanna just quickly show you a follow-up loop because I just think it's a I think it's a really nifty syntax. So instead of this, we're gonna go 4, and we're gonna do the the brackets again, but not let it autofill, all of that. Let piece where whatever we want. We're gonna call it piece of my body. Exactly. You've got one too many, close brackets there. And then you do squiggly brackets, and we enter into the code block. Piece is an is a variable inside of this loop, which will change its value for each iteration. So I just think this is yeah. I mean, it if you if you hit tab now, it seems to have already, that code's wrong. I could ain't gonna do anything. I mean, we'll leave it there as, like, as like, you know, we'll base something on this. This is not right. This is saying if if my head is in the spot of this piece, which also includes my head, make everything foresight. This just won't work. It will mean no isn't a viable move and it will keep it will keep sending you know, it will send it, I think, an undefined and then we'll die. So this is wrong. But just before we jump into the logic here, so this is another way to write a a loop in JavaScript. And another way you can do it is called a for in loop where you change the word of for in, and then the value of a piece will be the index value. So what we could have done there, an exact copy of what was above is saying for let eye of my body. And then I will automatically increment each time. It will give you the, in sorry, in my body. And then I or whatever variable name you give it, will will be a will be a number that goes up. The way I remember the difference between of and in, of object in index. I love that. Yeah. So, we'll we'll use the the for of loop. I think it's really nice because when you start to nest them, you can be really descriptive about what that value means inside of the loop. I think it looks nicer. It's a little more concise. But there you go. You learn about JavaScript loops. And there are obviously other loop types as well, but these are the more common 3. So what do we care about when we're looking at our body? Well, for every piece, what we wanna know is, is it one space away from us in any direction? That's all we wanna know. And if that is the case, we cannot move into that position. Even that strictly might not be enough because oh, no. It will be. That that will be enough. That is groovy. So what we wanna check is is our head equal to x? So is it on the same is it on the same x plane? Oh, no. No. Sorry. Inside of this initial if on 95. We're we're gonna alter 95 because 95 doesn't work. So we wanna say if it's on the x plane, but my head dot y is piece dot y minus 1, that means we are one space sorry. That means our body is one space below us. Down goes off the table. So this would be whatever the line is where we remove down. Game what's it called? Yep. Yep. Let's go grab that. Yeah. It is move is move safe. So if it's 1 under us down, down goes off. So is move safe dot down equals force. On the same x plane, hang on a moment. But the y for on the same x we're gonna fiddle with these till they work. This this bit always gets me. I think I might have just done that wrong, but we'll find out. Oh, it's part of the adventure. So, Hannah, if we're on the same x and it's below us if we're on the same Do you need to draw this out? Yeah. Maybe. Maybe. Let's do it. Let's grab, let's grab some It's bothering me. If we're if we're on the same x plane, but it's 1 below but then we're not on the same x plane out. But it's y. I wondered what tool you you were gonna grab there. We'll see if this works. I might pull up some random drawing that I've created. I bet you I am gonna we're gonna see what magical drawing that I have up on the screen here as this loads. What? Can you back a table in there? Because that's all we need is or a Google Sheet even, to be honest. Oh, that's a good idea. Let's do a Sheet sheet. Okay. Let's do, sheets.new. Sheets.new. Sheets.new? Yes. What's happening right now? What is slides.new, docs.new, forms.new. I love it. That's fantastic. Okay. Right. Zoom in. Zoom in. Zoom in. Zoom in a ton. Let's go zoom in. Oh, no. Wrong one. Let's go zoom zoom zoom. There we go. And and let's just do, like, we don't need 11. Right? We could just do, like, a 4 by 4 for the sake of argument. Like or up to 5 by 5 if you go to Ian and you go down to 5. Alright. And I do feel like this visualization is really helpful when you're doing this, like, genuinely. I think this is, like, a process that is useful for anybody to do if you're considering doing this. So draw, like, a 3 parts draw, I don't know. Yeah. Let's just yeah. Yeah. Perfect. Right. So what we want is if you go if you go right one oh, what's happening? What what we're doing? Just give me one second. This is just a small one to do this. Hold on. Hold on. There we go. Great. Hang on. Hang on. I think I think we needed to do it. Do a little more than that. And I would I would leave them as x's so we can notionally talk about the head. So do do maybe, like, make it like a like a u shape. So also fill in b 5 and b 4. I'm gonna you know what? I gotta stop with this x. The the color x is I I I I yeah. Oh, no. Actually, hold on. I could just literally copy and paste. Come on, Andrew. What are you doing? There we go. This is how we want it. Let's assume that b 5 is gonna be the head. Right. So the first thing we wanna do is to say, let let's try and do the left position first. Yep. So the x is the same and the piece is on x minus 1. So that's that's the first one we're we're gonna do. So x is the same as my piece dot x, but but the my piece dot. Oh my god. What's going on? So this is gonna be Sorry. Sorry. Sorry. Sorry. Sorry. The y is the same. Yeah. Because we're all because we're on the same level. We're on the same height. That's what was getting me. So if the y if the y is the same, the x is minus 1, you remove left. So let's do that first. Alright. So if the y is the same, x minus y? Yeah. Yeah. Yeah. So so let let's do the first if the first half of the statement, let's change those for y's. So if the y is the same, but the x is piece x minus 1 remove left. Love that. Okay. And and it's exactly the inverse for right. So x and sorry, y and y, perfect. We we replace those, but this time it's gonna be plus 1. That's all it was. We're we're just struggling struggling with that. So just to be clear, sorry, those first two still wanna be you need to basically inverse all of them. So y Correct. There we go. And then we're gonna return off that will be right. Yeah. And I I don't think we need I'm really glad we pulled out that tool, but I think we can basically invest them now. So copy and paste both of these. So next thing we're gonna do, not like that, is if the x is the same, therefore, the the column we're in is the same. That was it. But the y piece is minus 1, then it's under us. So we're gonna remove down. And, yeah. Exactly. Xxy y. There we go. That took us that took us a hot minute, but we got there. So that should now prevent us colliding with oh, hang on. Hang on. Why? Oh, no. It's fine. On that line 94 piece isn't, like, white, so I thought it was unused. Oh, no. It's because I added an s in there. There was a there was an error there. Just because I'm doing the Windows key save. No. No. No. Peace is declared but never used. I don't think that's right. Oh, there it is. It caught it. There we are. There we go. Cool. Oh, but we got a formatting issue? Hold on. So we can No. It was a it was a formatting issue. No? Hold on. Nope. We're still getting a bug here. Someone watching this right now is screaming. They're like 100%. A 100%. I feel like I'm missing it. Scroll to the top of the arrow. The top of the arrow is gonna tell you tell you what it is, but we're not at the top of it yet. Keep going all the way up, all the way up, all the way up. More more more more. Oh, okay. Less. We went too far. We went too far. It happens. Hold on. There we go. I just went too far into the first interpreter. Alright. Board meeting No. No. We sorted that. That was before now. We did that. Oh, it's this one. Hold on. Hold the phone. Close u. Wow. Capsule consoles. So many consoles. Formatting failed with message. What? And go have I missed something pretty obvious here? No. I think I think that was the that was the issue for let piece of my body. Hey, bro. Yes. I think it was just that s in there. Let's try running it again. You can do it. You can do it. I'm getting a hunch it can't do it without some intervention. What have we done? Is it because we do need to declare this let on my body? Oh, yeah. Maybe that that was the grape last time. Kevin lied. There you go. You lied. You said I didn't have to let it. No. I literally did earlier. That's what happened with board width. I feel like it's it's a useful thing to blame other people for your coding mistakes. I feel like that is what it is the sign of a true a true professional. The professionals we clearly are. Yeah. As I as I went to Google to search how to do a loop in JavaScript. What's what's happening right now? It's all taking a little long. Can you can you refresh the web view at the top? Yeah. Let's do that. I feel like that's k. We can close this out for now. Yeah. Yeah. Yeah. Let's see what's going on. I don't know. Yeah. I don't know what's happening. Maybe repllets happen a day. I mean, this is the thing. Right? It's like we are dealing with a cloud ID, so it does chug sometimes. But Absolutely. The REPL is booting. It's doing its thing. It is. I will say as much as I love cloud IDs or cloud development environments as they're trying to brand themselves now, I use Gitpod for ages, I use Codespaces for a while, I have moved back to using a desktop editor for things like this. Like, why am I waiting for my editor to get its act together? You're not wrong. So so yeah. There we go. And the GitHub CLI makes it really, like, quite quite nice to to move between PRs as I'm reviewing stuff. So, alright, great. Let's rerun the game. So now it should not die from its own body. So in theory in theory, for a one snake battlesnake, I think it's gonna have a yeah. I think it's gonna have a decent life. Look at this. We broke a 100. There we go. This is amazing. Wow. This, okay, 170 moves. Let's see what ended up doing it in no. It could be health or it could be eventually, it had no viable options. You know? Let's see. Yep. So it's doing all the things. Not running into its tail now, which was entirely possible with our previous code. It's not getting bigger because it's not getting food. So now it's going in that circle because it's avoiding its body, and it's avoiding its tail, and it's avoiding its neck. And so I think he might starve out just because he's getting stuck in that circle. Oh, no. Poor buttersnake. Eat something. Look all that food around you, mate. Dang. So, yeah, that's the interesting thing is, technically, he got into that loop where, like, technically, he was right, but we didn't say if you do this more than once, get out of it, which is a thing you can do. And what that, chicken or sorry. What that snake did is a is a a very famous move in the Battle State community called chicken snake. And chicken snake used to, like, go into a corner and would just chase its tail and wait for everybody else to die. And it would do really well. Yeah. And you you basically, you are you either other everyone has to die before you or you have to hope food spawns in in well, it it won't spawn where you are though, will it? It won't spawn in a position where a snake is. So actually It can spawn, like, right where oh, you're actually not wrong. That's absolutely right. Yeah. Interesting. Okay. Cool. So step 3 is a pretty, a pretty good evolution of what we just did there, which is up until now, we have a single battle snake on our board. But in reality, battle snakes will not be alone on the board. There will be at least one other snake on the on the board. And our job is not only to avoid ourself, but to avoid every snake and all of their body parts. Thankfully, we are effectively gonna get to get gonna get to, like, work on this work on this. And in fact, Andrew, I don't think we should copy and paste it. I think we should adapt this because our snake is in the snake's array as well. The might the me, whatever it's called, is again a convenience like the head to just give you the first item. So there's no point doing a loop over all our parts, then a loop over an array which includes us. We should just adapt this immediately. Okay. Great. Let's do it. Alright. So let's go yeah. So we've already defined here. So we've got our opponents defined, and we're gonna do that same let again. Right? Like, we're gonna do our loop with around our opponents, or do we wanna remove ourselves from that first? You know or I mean, this is I mean, it's up to you. Right? We can either, yes, remove ourselves from it, run the loop again because who cares? You know, it's just repeating logic effectively. Or we can adapt what is written above in that kind of 90 to a 110 line range to just be the loop. Oh, I see. Okay. Okay. So where where should we start? Us. So we we know here based on line 116, which we should probably comment out because it doesn't have a let in front of it, but we know that game state dot board dot snakes is an array of all snakes including us. I believe we're always first. So let let's create that variable above this loop, first of all. Alright. Let's do that up here. I see. I see what you're saying. Now when you said adapt, I was like, is that not what I'm doing? Alright. So let's define that. Yeah. Yeah. We we don't need to build on top of what we've already done here. In theory in theory, we can also do a way above with, the avoid our neck logic that it came with because we're gonna avoid our neck by virtue of this. Let let's leave it for now. Let's do a little bit of cleanup at the end, I think. So now we have it's not even opponents. I don't even think that's the right name. It's snakes. These are the snakes, and it includes us. We have a loop that will go through our body and do the check. And, basically, all we wanna do here is write a full loop above it, like surround it in a further full loop, and we'll do the same thing. So we'll go let, snake singular because each iteration is going to be a single snake of snakes. We'll do the open squiggly bracket here on line 44, remove that exactly input precisely, and we'll put that outside the outside of the other one. And all we wanna do here is instead of my body, it will be snake dot body. Oh, Kevin. It's like you've done this many times before. That is just like It is. That is beautiful. So in my hearing and the We we don't know it works yet. No. But I like aesthetically, it's very pleasing. Thank you. You're welcome. Thank you. So now in theory, we're running the same loop for all of for all the snakes. Right? Should we test it? Yeah. Yeah. Let's test. Alright. So let's I'm I was wrong. We do need to stop and start it. So let's see. This should work fine. Perfect. Okay. Let's head back over here. Gotta do a new game now, because we What? Are actually gonna add another set. Of course. Of course. We may as well use one of these bot snakes. I love that scared bot just disappears in this dark mode. In dark mode. Just not there. That's fine. It doesn't matter. We're gonna add him, and we're gonna add in ready, set, and battle snake. Right. Alright. Let's add that in there. Alright. And so we've got a game running now. Now this is another thing about playing this is, like, you can see a lot of these things from your logs. So if you're ever playing BattleSync competitively and, like, there's a competition, like, it's almost like you have to close your logs. Otherwise, it gives too much away. It's like you know Woah. What happened. The other the other nice thing about this is, of course, we get the whole board state every time. So as we start to integrate this with Directus, we can we can consume and store as much of this as we want. Let's, let let's play it. Yeah. Game over. 101 moves. Let's see what happens. Okay. So avoiding body, avoiding other snakes as well. Oh, I think I know how this is. Yeah. I think I know how it's gonna end for this snake. Yeah. Me too. Womp womp. Womp womp. Womp womp. And look how close the food is. Boom. Game over. So it can can we do a rematch? Can we get something hopefully a little more vibrant? Let's do a rematch. Let's see what happens here. Yeah. And we'll play it just so that we can see it in real time. And and this way, you can actually see this What is going on with our snake? Why is it happening? Our snake actually oh, there's an error with our snake because there was a viable direction there. It was to go right, and it did not. No safe moves detected. So that makes sense. So why was it no safe moves? So we have it set that it's not going to go is that it's not gonna go no. Because he's been going up there. So she should just the final move? He should have gone right. Yeah. He should have gone right or he should have gone wrong. Loop. So our logic is wrong. Let's take a look at that. But but and right was the only move. It couldn't go up based on our heuristics. Even though, in theory, to avoid our body, we can remove the tails. We can remove the final piece. But what's interesting is he was doing that. Like, if you look at this, so he was here and he was going here. So, technically, when he was in this spot, he could have actually done this again. Right? Oh, yes. So he could have gone up or he could have gone right. Of course. Interesting. Okay. But let's go to our code and see why that didn't so why did you decide? It's because of the other snake. So it is it does have something to do with the fact that he was right next to a snake, and so he didn't think what about oh, no. No. It's right. My head is still correct. And we wanna be checking the piece of every snake. P sex minus 1, p sex plus 1. Yes. That's right. I feel like it's because we do actually need to bring this logic inside because we're running these this and then we're running through this loop. It shouldn't make a difference, though. So? If it's set force once, it's we never set anything's true. We're never undoing the work we did. We're just kind of repeating it. You know? Yep. Okay. So I guess my head is in there. We don't need the my body anymore. We're not referencing my body anymore. Sninks does include us. Right? Yeah. Well, let's let's figure that out. I think Let's I think it does. I think you is the name of the the object as a convenience. Snakes snake squad. No. That's not important to us. No. That's the snake squad. That and then board. So, yeah, you are getting snake 1, snake 2, snake 3. Can we see the description? Snakes. All snakes on the game board, including yourself if you have not been eliminated. Yep. So it should be working. You're right. So what is going on here? So for snake of snakes, that's good. Again, people watch it people watching this on director's TV are gonna be like, god. It's so obvious. This is the thing. Well, let's hold on. Let's remove some some let's comment out some I mean, sure. Sure. But, I mean, that's literally gonna matter for anything. But okay. So if my head and let's go back to our let's go back to our sheet, drive. 94% of storage used? Yeah. I should probably, go in here and, you know Oh, not pay not pay more for it. Just act stuff. Yeah. That that's the other solution. Okay. So let's say we have let's let's actually reimagine the board state that we were in I love that. Fine. What one step back? I if it's playing, what's going on here? Oh. And we just need to go one step back. We're at the end of the game. Okay. There we go. Alright. So let's bring this to we will actually bring this to a 10 by 10 board. And let's pull this over. No. No. No. No. No. We we don't need the whole board. We only need, like, however wide. We only need, like, the cluster around around what we're doing. We we don't need to recreate the whole board. Alright. So let's go Hang on. I'll, on my side, I'll take a little a little cheeky screenshot, and I can I can call that out for you if you want? K. If you if you head if you head back. Go back to the game. There we go. Okay. So here's what we're doing. Let's go to our sheet. So we only need 1 like, we we can do it all within here, basically. So put our snake on, a 1b 1, a 2, and b 2. The head is b 2. And then, that that snake's gonna go, a 3. There. Yes. One more to the left. We can stop there. The rest is irrelevant. So that's that's what the snake is doing. And so first thing we're doing is we're avoiding ourselves. So we're saying can't go left. We can't go. The thing that's got me is why is it going right? That is I'm sorry. Why isn't it going right when that is a legal option? Yep. That's the question. The right logic is bust. Okay. So let's look let's pull this side by side. Let's grab this over here and let's go get this over here in our logic and see if we can make sure that our logic addresses this situation. Alright. So let's go here. Okay. So yeah, our first code here, my head, y. Yeah. So my head, y, is currently at On on b. Sure. Yeah. Right. On on 1. If it's 0 indexed in the bottom left. Yep. So we're both on 1. Sure. And the x, there is a piece one step down. Correct. Oh, hang on a moment. I think we've got our things muddled here. If my head y, but x is my so now that's correct. So that that accounts for a 2. Left is no longer viable. Yep. Going down 1, it's the same. We're on the same column, but right, this one is what's got me, but the piece dot x plus 1, but that is not the case. It's an it's an and statement. So, you know, both those things have to be true for it to be met. So if y is the same, but the my head dot x equals piece dot x plus 1, then it's on the right, but it isn't. I don't know what's going on here. My head okay. Well, hold on. So this technically, these are x aligned, but they're y they're not equal for y. They're they're they're y's match. They're wise match. They're on the same column. That means they're the same do you think I've just got the accent? No. No. No. I think that my I'm trying to work this out in my head. So this is Call that x1 or x. No. No. That's yes. Yes. No. You're right. You're right. You're right. You're right. Sorry. Yes. Oh, sorry. X1, x2, x3, x4, x5. Yeah. Y1y2y3y4. Yeah. So right now these are the same x, but they're different y's. Well, the yeah. So if we hang on. Let's let's start at the top. So let's do the left first. So the x matches. We've got them flipped, Andrew. We flipped them. Did we? Yeah. Okay. Look, the y is the if the y is the same no, we haven't. We got it right. So if the y is the same, let's say let's take, b 2 and c 2. Right? Yep. The y is the same. Yep. So that they they exist in the same yeah. But the x is minus 1. That means underneath. No. That means To the to the left. Something on the left. Fine. Then y is the same once again. They're in the same row. Are you sure we haven't flipped them? I I think we might have hold on. So okay. My head y, my piece and piece y are equal. So yeah. You're right. These 2 are technically there, and then my head x, so this is my head x, piece x minus 1. So, yeah, this removes left. That that totally makes sense. So we're good there. So next up, my head y equals piece y. Okay. Well, what would apply here, I guess? What would apply to this one right here? It would have to be on the right. I think we got it right. I don't know what's going wrong. My head x. Okay. So right now, this is they are the same for these are the same for x. So my head equals piece x. My head y equals piece y minus 1. Down is false. Yes. That that's right. That's good. My head pieces We flipped them. We flipped them. And what's getting me is the 1 on 1 on line 107. So my head dot x means they are in the same it means they're in the same row. Yes. It means so it means they're in the same column. It means they're in the same column. Yeah. Right? They're in the same column, but the y piece is minus 1. They're in the same column, but the but the y is is 1 to the left. They're in the same column, but the y I I'm struggling to visualize that based on our head. They're on the same Okay. Hold on. So my head ached I think we've, I think we've muddled these. I think I think, yeah, these are wrong. And I know we we know this and the audience like, yeah, it's wrong. And here's exactly how, But, I don't think it's as simple as comparing the y's and then comparing the x's. I think only one piece wants to be I think the Right. So can you just put, like, an a in d two for us? So we're we're gonna test no. No. No. A d 2. So so so so we're gonna test h versus a. Right? So the y is the same. The the y the y is the same. The x is plus 1. The the y is the same and the x is plus 1. Yeah. Right gets removed. So right yeah. Right should definitely So but at least one of these is wrong because we're removing too many options. Yep. If if x is the same, so they're in the same column So let's say y here. So these guys are in the same column. But the y is minus 1. Then we're gonna get that here. Fine. Then the y's are the same, the x is plus 1, then we're going right. Dude, this looks correct to me. It does I don't know what's going on. I okay. So I feel like this we've worked through this. I do think it must have something to do with this logic then. Have we screwed something up here? No. I don't think so. If my head equals 0, head x equals 0. It's anywhere in that line. You can't go left. If it's at the board if y is at the height, you can't go up. So here, this was at the height minus 1. So wait. What is height returning? Am I wrong? Have we changed the rules, and is height actually returning the height of the board and not 11? Oh, no. No. Returns 11. Oh. Oh. Wait. No. That No. That's correct. That's correct. Board width minus 1. Yeah. So that's that's fine. That would be the one that would have mattered that it would have removed the right, and that logic makes sense. Yeah. It's not there. Yeah. This logic is all correct. Let's run another game and see. We are. I am full on at the point where I'm just gonna find a snake because I know I know it's less fun. I know it's less fun, but I just, but I also I also don't don't fancy doing this forever. Let's take a look. K. I wanna see how this game plays out if something similar happens. K. Why did you run into his head? Why was that a safe move? Okay. What was the logic there? Did you have no safe moves again? No. So here, he thought he could go right. So oh, no. Because there. Okay. That makes sense. That tracks because he wasn't directly next. So there's no look ahead right now. So this takes So that's so so that'll happen sometimes. Yeah. So that tracks. That that game worked the way it should have. There's no buggy things there. It worked the way it should. Let's see if we can get another game because I feel like maybe that is it. Like, our code is right and there was just some sort of a glitch, but I don't know. K. So he's going in the circle. He's going in the circle. So he's gonna starve out anyways. We're not gonna get to see much there. Anyone? That's so weird. Can we can we run it again and again and again? So he's not making the same mistake again? I don't I don't like that it's just doing that. That feel it feels weird to me that it keeps chicken whatever you call it. Chicken Chicken snaking? Chicken snaking. That feels very odd to me that it does that consistently. Okay. So he's not doing this as well. It isn't. Okay. Fine. Okay. And, again, so this ish situation, was that a safe move? So he's gotta finish the game. Come on. Come on. Go back. Okay. So this does that make sense? Yeah. Again, this one makes sense because he didn't see right? So every one of these games, it's just the one game that was the one that was very strange. I think that there was some sort of a there was some sort of a an issue there with the actual way that it was reading our logic. I I hate seeing bugs that don't get resolved, but it seems like it's not happening again. It seems to have been okay since. Yeah. Well, let's try again. Maybe Okay. So why did he do that? So he shouldn't have done that either. Okay. So here's the thing. So why did he do that? So right. Right. Right. Game over. So he should not have gone right there. Why did he go right? Why did he think right Something's wrong. Was a safe move. Okay. So let's look at this again. And we're gonna have these guys here. So let's go, I'm actually gonna do color with these this time because I feel like that will actually help us. And then we'll do here and then we'll do him gray green and gray, green, green, green. That's all. I'm literally this is driving me potty. It's alright. This is the joy. I and, we'll fix it in post. Right? Yeah. We'll fix it. We'll fix it in post. Okay. Okay. Do do do do you want them to know what lovely editor, Nat? Let's jump cut here to the point where we fix it, and then we'll explain what went wrong. Yeah. Welcome. Welcome back. We worked it out. Andrew did a lot more like debugging, adding print statements. Andrew, do you want to show the code? And for those of you who are, let's zoom in like many, many, many times over, what was the issue? I'm yeah. But but what was the issue? So the issue was we had things flipped with the Yes. We did. Actual thing that we were removing. And the way that we discovered that, and this is kind of an interesting way to do it. I actually, like, find this as a really good way to do any debugging because I threw a console log into each one of these pieces with whatever we had been removing. So, initially, we so let's, like, put this back to what it was before. Originally, this was is moved left, right, down Down down and up. Yep. And so, originally, we had this. And so I wanted to look here and see where, where we sort of messed up here. And so if you look sort of in this log so, and I think this is the latest game. Is it the latest game? No. We ran it once more since. We ran it once more since. Did he did he go out for the same reason? That's my question. Let's find out. Oh, no. Because this was what he was buying correctly. So Yeah. Did I see But but but but but we we we don't necessarily need to find it or or replicate it. But, yeah, you you basically post it in a in the state just before you died, just before it died. Yeah. And then where and then did kind of what we did with the spreadsheet again. And, basically, we had it flipped. So up and down needed to flip, left and right needed to flip. And then our snake has also been a lot more interesting as a result. Yeah. So technically, like, even with bad code, it worked. Change it back. Change change it back now before Yeah. Before we forget. So let's go and I'll actually go in here, and I'll remove these console logs because they're false now. Let's go right. Mhmm. And remove this one and left. And and I feel like this is kind of the fun of this game is it's like you orienting yourself is also, like, I think it's part of the challenge here. But now, you'll see here so, like, well, in that last game, he didn't follow the rules like we thought he was going to. Now he, she, they, if we go back in here and create a rematch, we're going to see that, like Kevin said, this game is far, far more interesting now. And so here so now he's not constantly going in that loop. He's not running into these other snakes. And there we go. Now we're starting to get some wins. Yes. Now I think that might be where we call this snake because the reality is this snake's doing pretty well. For the extent of our series, we don't need to do much. However, there are some other end statements here. Did our snake die or did no. No. No. No. No. That was good. Nope. We did the right thing. He he just did head to head. So head to head is the other thing to consider. If you collide with a snake head to head in any configuration, right, if you both enter the same square, the snake with the lowest to health, I think. Right? Yeah. Or the shortest snake? Yeah. No. Which one? I just gave you 2 options. Oh, sorry. Shortest so it's it's the snake snake with the it's the snake with the lowest health, I believe. No. Wait. Hold on. Let's talk a little bit. The shortest snake. Always consult the docs whenever you're not sure. And so and so what you will need to do then is also look around the heads of each snake and have an exclusion zone of one one valid direction in any way they can go. You can also remove the tail as well because next move, the tail is gonna have moved out of place. So these are the little bits of logic you can do. The longer Longer about the snake will survive. Shorter will be eliminated. If they're both the same length, they both die. Fine. Fine. So there is more logic we can add to this, Nate. But the reality is it's gonna perform pretty well. Apart from head to heads, it should perform or running out of food legitimately because it currently is just hitting food randomly. It should perform pretty well. Good enough for ready set battlesnake. But, yes, in reality, you'd also have an exclusion zone around heads, and you would be able to take the last item of each snake body and remove that from your from your checks because it's going to move out of the tail space. Or rather, the tail will not be in that space anymore. So you can stop. Ahead might be, but the tail won't be. Sick. Okay. Ready, set, battle snake episode 1. I think the last thing I'd love to do before we just say bye and and stop recording, shall we just do a little bit of cleanup on this on this, file from the top to the bottom, make it feel good, and then we can wrap up. And next episode, we will take this snake and see if we can run it inside of a director's project. Amazing. Alright. So, yeah, let's clean this up. Let's leave those comments in there because I think they're great. Let's leave that step 4 in there as well. So let's go up here. Now we do need to add a couple of things. So let's do, let's call this Directus TV as our author. And we're going to leave our stuff until next week, I think -I think so. - for our default. But, we've got that in there. This is all good. This is all good. Do we wanna leave this or do we wanna move this inside? What do we wanna do, Kevin? What do you think? What do you mean inside? Like, do we wanna deal with moving this logic for the head and neck inside of our inside of our other logic? You can straight up remove it. Leave the variables at the top because my head and my neck might are used. My head is used. My neck is not used. We can remove those. They're they're captured in the other logic. Yep. You're absolutely right. Yeah. Okay. So we can remove and we can remove my neck because we don't need that anymore. And This is all good. I actually think we should put all of these together. Is there a reason that we should have our board width and height as let and our my head is const, or should we just have them all the same? I feel like they should all the same. It literally makes no difference. Like, in reality, I would make them all cons because we don't reassign them. And I think inside of the 4 loops, you can also use const instead of let, if memory serves me right. I feel like there's probably a way to select all of the lets in here. Command d. Command d. Or control control d. Control d. There we go. Let's call these all const. There we go. Lovely. And the reality is we're still being overly verbose here. Like, line 79 could just be put inside of line 81. Like, we don't we don't need to be declaring all these variables, but I think this is fine. We're gonna move it over next time. I think we said we're gonna we're gonna try using direct automate to make this work, which I'm really excited about. There are some interesting quirks. I'm not sure I've quite figured out yet. We have a a pressure based rate limiter that I think we might hit, so we'll we'll have to explore that. But we'll we'll see. Yeah. But I think that's I think that's everything. I think we've pulled out any unnecessary variables in here. I think this is looking pretty pretty good right now. Sounds good. Great. Hit Save, and let's let's wrap up. I think this was a really nice first episode. Very happy we cut that that bit in the middle of working out what we were doing wrong. So thank you so much for joining us for the first episode of Ready, Set, Battlesnake. We won't see you next week. This is every 2 weeks. So if you are watching at the time it's coming out and not binge watching at the end, you will find the next episode right here on DIRECTV in 2 weeks' time. I've been Kevin. I've been Andrew. There we go. And until next time, you ready for the catchphrase? Ready. Set Battle Snake. We'll get there. We've got 4 episodes. We've got 4 episodes. Bye. Bye.","published",[142,152],{"people_id":143},{"id":144,"first_name":145,"last_name":146,"avatar":147,"bio":148,"links":149},"82b3f7e5-637b-4890-93b2-378b497d5dc6","Kevin","Lewis","a662f91b-1ee9-4277-8c9d-3ac1878e44ad","Director of Developer Experience at Directus",[150],{"url":131,"service":151},"website",{"people_id":153},{"id":154,"first_name":155,"last_name":156,"avatar":157,"bio":158,"links":159},"e7311cbc-d404-4e18-83d9-bca26206057e","Andrew","MacLean","6ac0ee16-495a-4316-859f-1af70f83c618","Developer Relations Manager at DevCycle",[160,162],{"url":134,"service":161},"twitter",{"service":151,"url":163},"https://edulinqs.com/andrewdmaclean",[],{"id":166,"number":135,"year":167,"episodes":168,"show":172},"398d2955-6ca4-4847-810d-a07f4f48a319","2024",[122,169,170,171],"7c58048d-ab8e-42cc-823d-541848ad4a7d","5a14d9c9-0b37-4655-b45a-b4783c0bb92f","fa776fca-1f88-44ac-8c54-96232474282d",{"title":173,"tile":174},"Ready Set Battlesnake","a9af3e01-33c2-4e06-8836-bcb759570406",{"id":169,"slug":176,"season":166,"vimeo_id":177,"description":178,"tile":179,"length":180,"resources":8,"people":181,"episode_number":184,"published":185,"title":186,"video_transcript_html":187,"video_transcript_text":188,"content":8,"seo":8,"status":140,"episode_people":189,"recommendations":192},"automate","925447352","Kevin and Andrew migrate their snake to run entirely in Directus Automate's low-code builder Flows. Is this the right way to run a Battlesnake? Tune in and find out.","37419656-e608-48d3-8d79-6fdb4fbcfac2",110,[182,183],{"name":130,"url":131},{"name":133,"url":134},2,"2024-04-04","Automate","\u003Cp>Kevin: Hello, and welcome back to we've got a catchphrase, Andrew. Are you ready? Ready, set, That's easy. We got 4 more We got 4 episodes. Exactly.\u003C/p>\n\u003Cp>We're we're we're we're cutting our losses for this one. In this show, we are continuing to build a Battlesnake, and progressively enhancing it, using Directus and Devcycle. My name is Kevin. I work at Directus, which we'll be using a little bit today. And My\u003C/p>\n\u003Cp>Andrew: name's Andrew, and I work at Devcycle, which we'll be using in a future episode. And this is Battlesnake.\u003C/p>\n\u003Cp>Kevin: Yeah. Give us the give us the 90 seconds for people just dropping in now. What is Battlesnake?\u003C/p>\n\u003Cp>Andrew: Alright. Battlesnake is the way you wish that you had learned how to, program in a new framework or language from the very beginning. And now as a senior developer, Imagine you were playing the old classic snake game where you go around a board trying to eat food and survive. Now transform that into a programming game where you have a web server that's communicating with the Battlesnake game engine to communicate through code and tell your snake whether to go up, down, left, or right, and to try and survive as long as possible.\u003C/p>\n\u003Cp>Kevin: Yeah. And we do that by implementing a web server, which implements the Battlesnake API. We've already had one episode of Ready, Set, Battlesnake. So we're not going to recap everything we did. If you are still a little fuzzy on how this works, it will probably become clear.\u003C/p>\n\u003Cp>But if you're completely fresh and you're like, I'm lost, go watch the first episode and watch a struggle through building the Node. Js starter snake. But today, we're gonna further build on top of that snake. Last episode, we built a battle snake based on the Node. Js starter, and we implemented here we are.\u003C/p>\n\u003Cp>And we implemented some logic. That logic, what what did the logic do? The logic stop listening dying by going hitting into walls. That's good. Then we got the snake to not hit itself or any other snake parts, because that also is instant kill.\u003C/p>\n\u003Cp>So that's all our snake does. Right? Yeah. Yeah. That's all our snake does.\u003C/p>\n\u003Cp>And we're probably not gonna make our snake much more clever today, but we are now going to introduce a new tool into the stack and get it out of Replit and into another environment. Anything else you think that's important, Andrew?\u003C/p>\n\u003Cp>Andrew: So the great thing is you can follow along with kind of all of the base code for all of this over on the GitHub repositories that exist around. Snake. So if you're watching this and you're like, I want to do it in my own language or framework, you can go and check out all the\u003C/p>\n\u003Cp>Kevin: awesome Angular projects\u003C/p>\n\u003Cp>Andrew: that are over there.\u003C/p>\n\u003Cp>Kevin: So actually, let's take pause for a moment because this is important. What is a Battlesnake? So you have to implement a web server that has a few specific route handlers. The a few specific endpoints. Firstly, this just route route.\u003C/p>\n\u003Cp>Right? And all this one does is it returns information about the snake, metadata about the snake. And we'll play around with that a little bit more today. The mode then we have the start endpoint, which, Andrew, I think that's the before the first move in any game. Right?\u003C/p>\n\u003Cp>Andrew: So we got our start end point, which is great. We've got our root end point. What is the kind of most important endpoint of all the endpoints though, Kevin?\u003C/p>\n\u003Cp>Kevin: It is this move endpoint. As we discovered last time, the move endpoint, every single turn of every single game will receive a request with the state of that game and the board, which includes every other snake, all the hazards, all the food. You have 500 milliseconds to respond with a string up, down, left, or right. And that is this is the most important endpoint. But you there is also an end endpoint, which is what you would potentially use to, like, wind down any resources or, you know, do any analytics storage, you know, and you just do it at the end.\u003C/p>\n\u003Cp>So we have these 4 endpoints that we need to implement. Move is is kind of the most critical. I think only move in the the root are required for any given snake. So that's worth noting because that's gonna be important. So what we're gonna do today, we are going to be building this snake inside of Directus.\u003C/p>\n\u003Cp>If you've not heard of Directus before, I hope you have because you're watching this on Directus TV. But Directus is is a back end toolkit to build applications. It has 2 parts. One part which is all around API generation from your database and asset storage, and the other side, which is a web application to kind of work with that data. There's a whole bunch of other stuff in there.\u003C/p>\n\u003Cp>So we're gonna be implementing a Battlesnake inside of a director's project. So we'll we'll we'll kinda see how this shakes out over the next over the next little while. Now originally, until about 5 minutes before we started recording, I thought that we would perhaps use, Directus' automation UI tool in order to build our snake because it is it feels quite viable on the surface. It does. And then I realized it ain't it ain't viable.\u003C/p>\n\u003Cp>And the reason it isn't is because one of the triggers that can begin a flow is a webhook, an inbound webhook, but it is unique, and randomly generated at the time the flow is created, which means we can't implement a root endpoint and then slash move, slash start, slash end. And that's gonna be a challenge. So rather than just trying to to power on through that, rather than sorry, rather than just trying to power on through that, we instead are gonna build an extension. Flows is effectively a UI layer or a UI version of, hooks of hooks. So, you know, we can we can do it in code.\u003C/p>\n\u003Cp>We also have endpoints, which is probably more suited for this where we can literally create complete endpoints, and this is a no doubt. So we'd probably lift and drop a lot of our logic. This might end up being a bit of a lighter episode, but there would be nothing wrong with that. But I've done the thing. I've jinxed it.\u003C/p>\n\u003Cp>Andrew: You have. I did it last time, though. So in fairness, we're we're each one in, and and so I feel like Indeed. This is way to do it. Indeed.\u003C/p>\n\u003Cp>And so we're also we're gonna be implementing some some, like, very like, this whole rate limiting thing has caused us to have to think about a lot of other technologies as well too. Right? So it's not just this concept of of sort of how we're gonna implement Directus. It's also\u003C/p>\n\u003Cp>Kevin: You're right.\u003C/p>\n\u003Cp>Andrew: How it's gonna be able to interact with with the Battlesync platform. Right?\u003C/p>\n\u003Cp>Kevin: Yes. So here here's the plan. Here's what I think the game plan is. We're gonna spin up, direct us locally using Docker. And that is an environment in which we can build extensions.\u003C/p>\n\u003Cp>And we could then just deploy it somewhere and be happy days, you know, deploy it on some some web service, or we could just, like, open up a tunnel to our local machine. And ngrok is kind of the tool that we've as as developer educator types have have historically jumped to, so I think it will be the tool we use today. I also found out today I'm apparently still paying for it on a grandfathered plan that gives us the pro features. So, you know, I think it's one I might wanna\u003C/p>\n\u003Cp>Andrew: Let's do it.\u003C/p>\n\u003Cp>Kevin: Get off the card, but I'll use it today.\u003C/p>\n\u003Cp>Andrew: I saw a I saw a really great, idea from someone recently just to, like, automatically, not only list all of the subscriptions that you have, but actually unsubscribe you from something if you haven't accessed it in a while. And I was like, that's a brilliant idea because I have so many things to subscribe for that I'd like to remove my credit card from.\u003C/p>\n\u003Cp>Kevin: Yes. But I'm happy in this moment in this moment that it's working. Now one thing that's really nice here is the extension entry point. If we look at this, example, the way it's built is you give an endpoint an ID, which becomes the kind of root path. So this would be like our director's project slash greet, and then you can create the root, the slash move, the slash start, the slash end, and so on.\u003C/p>\n\u003Cp>So this part should be pretty straightforward. Let's let's see, and if the docs end up being misleading, that's literally my job. So it's it will be incredibly self inflicted. So we'll we'll see. So we're gonna start by following the Docker guide for getting started with directors.\u003C/p>\n\u003Cp>No. We're not. We're gonna look at the self hosted quick stuff, which which\u003C/p>\n\u003Cp>Andrew: is super smooth. It is a very smooth Docker process, I will say. Like, setting it for the first time, it was it was chef's kiss.\u003C/p>\n\u003Cp>Kevin: I like it, and it's pretty, we we kinda sometimes refer to it. I mean, we will use different words, but I call it like full fat. This is the full thing. There's directors cloud, which is like, you know, a a managed platform. But this if you self host it, it's full fat, which is really nice.\u003C/p>\n\u003Cp>So I already have Docker running in the background and I already have a code editor here, completely completely blank code editor and a new directory, which I've opened up. So I think we're just gonna we're just gonna crack on straightaway in here. So first thing we need to do is create a Docker Compose file. It's a Docker dash compose dot YML file that describes all of the settings that we have with directors. We may need to fiddle with this later, But for now, docker compose dot yml.\u003C/p>\n\u003Cp>And let's make my font size significantly bigger. There we go. We can copy and paste the value in here. Keys and secrets are meant to be random values. They're used for, identifying, your account in, like, a horizontally scaled setup and the secret is used for JWT validation, and we don't care about that right now.\u003C/p>\n\u003Cp>So we're just gonna leave those. Hunter 2 is when I set up projects my default. So we're gonna Good\u003C/p>\n\u003Cp>Andrew: to know. Good to know.\u003C/p>\n\u003Cp>Kevin: Good to know. Good to know.\u003C/p>\n\u003Cp>Andrew: I'm searching around for past Kevin projects and just trying to break in.\u003C/p>\n\u003Cp>Kevin: Absolutely not. And no. No. That will that will not be good. We're gonna use, yeah.\u003C/p>\n\u003Cp>Sorry. Go on.\u003C/p>\n\u003Cp>Andrew: No. I was gonna say an interesting note here is I discovered with the self hosted version, you can't use a fake email address. You can't use dot test. It won't actually accept it as an email address in the platform.\u003C/p>\n\u003Cp>Kevin: Yeah. Interesting. Interesting.\u003C/p>\n\u003Cp>Andrew: I was when I was building out that railway sort of like starter kit for it, I was trying to just set it up with a test and it would not it wouldn't go. You had to put it in an actual address.\u003C/p>\n\u003Cp>Kevin: Interesting. As in, like, it follows the structure of an email address, but it isn't real because it should do. That should be fine.\u003C/p>\n\u003Cp>Andrew: I think it was because it was a dot test, t, like, t Yeah.\u003C/p>\n\u003Cp>Kevin: But that that's they're legit characters in an email address. So anyway anyway. Things that's important yeah. One thing that's important to know about directors is it doesn't provide a database. It connects to an existing database.\u003C/p>\n\u003Cp>We're gonna use this lightweight file based database called SQLite. We're gonna point it at the file. And on first run, it will create the file for us. That isn't Directus, that's a SQL like database that Directus connects to. So just a little bit of important distinction there.\u003C/p>\n\u003Cp>10.8.3 is the latest version at the time of recording. By the time of publishing, that will not be the case. I think we might be on 10.9 by now. That's pretty exciting. Yeah.\u003C/p>\n\u003Cp>All good Database persistence, file persistence, extension persistence. WebSockets are enabled even though I'm not sure we're gonna use them. And instead of, continuing to talk through every line in excruciating detail, I think we can just write Docker Compose up.\u003C/p>\n\u003Cp>Andrew: It should kick off.\u003C/p>\n\u003Cp>Kevin: Great. It's attaching. Boom. Boom. Boom.\u003C/p>\n\u003Cp>Doing a bunch of stuff first time and running now on local host 8055. So if I hit local host 8055, brand new directors project with randomly auto filled credentials, which are not I think I have to move them out of, yeah, manage passwords, but that's not for today. I bet you that was a hunt to 2 password too. But this is a blank director's project ready to go. So that was that was great.\u003C/p>\n\u003Cp>What else is important here? If I open up oh, I haven't opened up the folder. This is annoying because obviously the terminals attached to it. So let's just, let's just stop that running. Let's open this snake folder here.\u003C/p>\n\u003Cp>I think I might have been able to add folder to workplace. We're here now. Let's just run Docker compose up again. Great. And just refresh that and everything should still be fine and dandy as it is.\u003C/p>\n\u003Cp>Now the first time we ran that, it created some directories here on the side, which I think are gonna be quite small right now on people's screens. But as a database directory with our SQL like database and extensions directory and then uploads directory. Grand. So we have this direct as project and it's great that we, you know, can go in and create, you know, collections in our database and upload files and create dashboards and all of that stuff. But really, all we care about is implementing these endpoints from our Replit and bringing them over.\u003C/p>\n\u003Cp>So let's go back to the docs. Let's talk about building extensions and get that get that game get that game underway. Directus has a whole bunch of extensions. Some of them affect the UI that that web app that we just had open. Some of them are API side like custom endpoints and hooks.\u003C/p>\n\u003Cp>Yeah. As it says here, hooks are similar to flows, but they do not have the UI, which is in the director's data studio. I think to create an extension, we're gonna go I'm sounding a little uncertain. I don't know why.\u003C/p>\n\u003Cp>Andrew: Like No. I love it. It makes me feel much better about about episode 1, now that you're feeling unconfident about the thing that you deal with every day. I feel like imposter syndrome is real, but at least you haven't had to Google how to make a JavaScript loop yet. So\u003C/p>\n\u003Cp>Kevin: Oh, good.\u003C/p>\n\u003Cp>Andrew: The episode is young. Run\u003C/p>\n\u003Cp>Kevin: so I'm gonna run this MPX create directors extension. I'll pick an endpoint, pick a name, directus dash extension dash, snake. Snake. Snake. I it doesn't it doesn't really matter.\u003C/p>\n\u003Cp>We'll use JavaScript. We'll auto install dependencies, and we'll give it a moment to scaffold that extension for.\u003C/p>\n\u003Cp>Andrew: This is a nice CLI. Like, I gotta say, this is a very enjoyable experience.\u003C/p>\n\u003Cp>Kevin: Yeah. There's still work that needs to happen, and it is happening. But, yeah, this boiler plating isn't too bad, actually. I, yeah, I I I quite like it. So inside of our extensions directory, we have this new snake.\u003C/p>\n\u003Cp>We have source. We have this index dot JS. Grand. Now what we want and so this, I think I think this might be available, I think, at directus dash extension dashnet like slash. It's a little bit clunky, but we're not going to use this format.\u003C/p>\n\u003Cp>It doesn't really matter. We're going to use this. We looked at it earlier, this alternate format, where we can do all of the subroutes straight in here. So I think I think I can just copy and paste this.\u003C/p>\n\u003Cp>Andrew: Kevin, is this just is this just vanilla, or is this React? Like, I this looks very clean, but it doesn't Yeah.\u003C/p>\n\u003Cp>Kevin: So this so the front end of Directus is a view app, but this what you're seeing right now and ding, ding, ding, I think you've just spotted it. Endpoints use oh, directors also uses the express router. So it is very much what we did in the first night, which is why being able to lift and drop it is gonna be gonna be quite nice.\u003C/p>\n\u003Cp>Andrew: It's so clean. I dig it. I love this. This is beautiful.\u003C/p>\n\u003Cp>Kevin: Yeah. Thank you. So we have snake slash snake intro snake goodbye. So let's get this running. So we're gonna c d into our Directus snake directory and we're gonna run npm run build.\u003C/p>\n\u003Cp>That's built the extension into a disk directory. And now we need to restart Directus now. I think I think it might be broken, but I think we can get it to I think we might be able to get it to, like, auto, like, load the the changes. What am I looking for? Self hosted config.\u003C/p>\n\u003Cp>Okay. So we are looking for extensions, extensions auto reload. Here we go. So Boolean will automatically reload extensions when they have changed. So we're back to our Docker Compose.\u003C/p>\n\u003Cp>We'll throw that in and make the value true. Maybe that will work. Maybe that will work. So run Docker compose up again. It's now gonna use this Docker compose file again with this new variable.\u003C/p>\n\u003Cp>Let's take a little look through the logs because hopefully yes. It says loaded extension, direct us extension snake. And then the hope is if we run npm run build again, it hopefully would have auto loaded, but that isn't the case. That's fine. That means we're just gonna have a slightly clunky development experience.\u003C/p>\n\u003Cp>So I'm gonna have to control C up enter, you know, off the baton.\u003C/p>\n\u003Cp>Andrew: That's fine. I gotta say though, like I remember like outside of this, I feel like we've gotten very spoiled in the development world now. Like, that used to be just the way that you did it. I used to use some.\u003C/p>\n\u003Cp>Kevin: Dragging files with Filezilla or Cybernet. Yes. A 100%. Yeah. Yeah.\u003C/p>\n\u003Cp>Andrew: I that's so I thought that's how you did it. I genuinely thought that that was the only way to do things.\u003C/p>\n\u003Cp>Kevin: No. Yeah. But not here. Like, this this, I'm not quite sure what the deal is. And by the time this is published, maybe this won't be the case anymore.\u003C/p>\n\u003Cp>Just for the last couple of versions, if you're running under Docker, I've noticed this environment variable isn't working. Our team's aware that's fine. I just wanna try it on the off chance there. Yeah. Whoops.\u003C/p>\n\u003Cp>So if we hit 8055 snake, we get the hello world. If we try snake slash intro, we get the nice to meet you. So these are endpoints that are returning stuff, which means we should now be able to lift and drop our snake pretty expediently. Yep. So what we what are we gonna do here?\u003C/p>\n\u003Cp>We have handlers dot info for the root. Yep. So you're gonna grab that. Return that. So I am just gonna make this slightly more verbose so I can space it out nicely.\u003C/p>\n\u003Cp>Yeah. So, can you bump up the\u003C/p>\n\u003Cp>Andrew: size a little bit too?\u003C/p>\n\u003Cp>Kevin: A little bit more?\u003C/p>\n\u003Cp>Andrew: Of course. Is that any any better? That's that's much better. Yeah.\u003C/p>\n\u003Cp>Kevin: Lovely. Rez got Jason. Yep. Do you need to return it?\u003C/p>\n\u003Cp>Andrew: I I believe so. Yeah.\u003C/p>\n\u003Cp>Kevin: Cool. Nice.\u003C/p>\n\u003Cp>Andrew: Yeah. I think everything you need to return.\u003C/p>\n\u003Cp>Kevin: Whoops. Got a little too a little too direct there. Let's, let's while we're here, maybe let's do some customization of the snake. That feels good. Yeah.\u003C/p>\n\u003Cp>That's good. So head over What color do we wanna make it?\u003C/p>\n\u003Cp>Andrew: Oh, what's the direct is it a direct purple? Is the is the color purple that you're using?\u003C/p>\n\u003Cp>Kevin: It is a purple. And, honestly, my lot are gonna kill me for, like, not remembering it, but I think it's, like, 6 6. I wanna say it's like 6644 f f.\u003C/p>\n\u003Cp>Andrew: I like it. Let's see. We'll find out momentarily whether this is Yes. Yes. That's right.\u003C/p>\n\u003Cp>I got it. 6644ff.\u003C/p>\n\u003Cp>Kevin: I logged into my Battlesnake account. We're gonna look at the customizations. And these are the customizations we can have for our snake. Andrew, you you may do the honors from the ones I have.\u003C/p>\n\u003Cp>Andrew: Oh my goodness. So I'm a big, big fan of mustache snake, but I'm pretty sure that there if we scroll down, there may be a rabbit in here now. I thought I thought we\u003C/p>\n\u003Cp>Kevin: had play around seeing if I could get the director's Bunny to look good in one of these, and I had just I couldn't with, like, the it has to be full width on the left. The Bunny, let's take a look.\u003C/p>\n\u003Cp>Andrew: Do we have a Bunny? If not, I know he exists in the backlog. So we may we may be able to get Bunny out at some point here, or he may be locked down. Either way, if not, if we can't get our bunny Oh,\u003C/p>\n\u003Cp>Kevin: I have 200 I have 200 coins as well, so I can unlock any one.\u003C/p>\n\u003Cp>Andrew: Oh, so what do we see? Do we see any that we really like? So we got chicken. I quite got\u003C/p>\n\u003Cp>Kevin: I quite like this dragon head here. I have to be honest. Yeah.\u003C/p>\n\u003Cp>Andrew: Take the dragon. But is\u003C/p>\n\u003Cp>Kevin: it was really funny. No. They're all 200. I don't see a bunny.\u003C/p>\n\u003Cp>Andrew: No bunny. That's disappointing. So let's go for dragon. I feel like that dragon\u003C/p>\n\u003Cp>Kevin: head Well, hang on. Let's let's look at the tails too. Let's let's, you know, maybe not spend all of our coins at once. True. No.\u003C/p>\n\u003Cp>I think I think the I think I like the heads. Well, yeah, let let's do the dragon. I've done it. Right. So the head we want is dragon, and the tail is So,\u003C/p>\n\u003Cp>Andrew: I mean, let's go I think cosmic horror's tail is pretty fun.\u003C/p>\n\u003Cp>Kevin: I like that. I like that. Okay. Cosmic Chorus. So that's our that's our snake.\u003C/p>\n\u003Cp>And once again, actually, should we get all the logic in? I think we should do this bit by bit. Like, we could now go off and make sure that this works, which is gonna be a whole task in itself. Does that feel okay?\u003C/p>\n\u003Cp>Andrew: Yeah. Yeah. I think let's do that because then once we know it's working, then we can kinda go through. Is that what you're saying? You're thinking, like, let's go in and actually add it to the platform.\u003C/p>\n\u003Cp>I am with NVIDIA because we gotta get we gotta get ngrok set up now.\u003C/p>\n\u003Cp>Kevin: Yeah. So do you wanna explain what ngrok is while I\u003C/p>\n\u003Cp>Andrew: get sucked in? Yeah. Yeah. Absolutely. So if you've never used ngrok before, it is a way to publicly expose your local, development environment to the outside world, whoever you would like to be able to access it.\u003C/p>\n\u003Cp>So if you often use, say, Gitpod or, Codespaces, there's often the way that you can make that public u that URL from private to public. That's fundamentally what this ngrok, endpoint that it's giving you is doing. But you can do it on a on a, case by case basis. And you can kinda keep it in one place, and you have a bit more control over the power of that and who can see it and all the rest of that stuff. It's our and it's really great, especially if you're, like, say, somebody that's building a site and you wanna see what it looks like on mobile.\u003C/p>\n\u003Cp>I think they might still do it. But I know there's some services that I've used that it would automatically generate a QR code from the n grok address so you could just, like, scan with your camera and then view on mobile. Doesn't impact us here, but, really, really good. And ngrok has taken a lot of steps to make things more secure as well. So it used to be that sort of anybody could spin up an ngrok address and there was no issues at all.\u003C/p>\n\u003Cp>And they've added a lot more security and ensuring that the things that need to be in place are. Yeah. And I will say around ngrok, if you are, on a local development environment on a Windows device, so a big Windows developer, there's a service called Laragon, which is like, an alternative to like a LAMP stack. And it has ngrok built in. So in there, you can just click share and then it automatically will, like, push that out to ngrok that you could share with people.\u003C/p>\n\u003Cp>But, yeah, powerful, powerful service.\u003C/p>\n\u003Cp>Kevin: So there's a little bit of a moment here. I'm not quite I don't quite have the memory of how this works. I think it works like this. I think based on what I've read, So you do ngrok HTTP, the port, which is 8055 and then dash dash domain and then your your domain. No.\u003C/p>\n\u003Cp>Reserve this name on your dashboard.\u003C/p>\n\u003Cp>Andrew: You don't need to do that. It'll automatically just generate a random one for you. So just No.\u003C/p>\n\u003Cp>Kevin: Yeah. But I don't want that because I'm gonna have to keep updating it every time it restarts.\u003C/p>\n\u003Cp>Andrew: I think I\u003C/p>\n\u003Cp>Kevin: have I have a static. I have a static.\u003C/p>\n\u003Cp>Andrew: Oh, I see.\u003C/p>\n\u003Cp>Kevin: Like, because I because I'm on this plat this old plan. Right? Yeah. So I wanna work out\u003C/p>\n\u003Cp>Andrew: Yeah. I haven't touched ngrok in in a little while. It's funny, like, it stopped working in that environment. There was, like, they hadn't updated the way that was integrated, and they added an authentication key. And so, it switched things up.\u003C/p>\n\u003Cp>So your guess is as good as mine.\u003C/p>\n\u003Cp>Kevin: We're gonna get oh, alright. Here we I mean, yeah. I suppose I could just do the help, right? So start engrop. That's cool.\u003C/p>\n\u003Cp>Basic auth. Cool. OAuth 2 cool. Here we are. Use it the same time by using dash dash domain.\u003C/p>\n\u003Cp>But, and I thought maybe I, maybe I.\u003C/p>\n\u003Cp>Andrew: What's your domain?\u003C/p>\n\u003Cp>Kevin: I thought it was that. That's why I that's why I paused. So if I look at domains, there it is. Unless I have to do the whole domain.\u003C/p>\n\u003Cp>Andrew: Try the whole domain and see what happens.\u003C/p>\n\u003Cp>Kevin: Because it because it did just say the ngrok.io is only for, like, legacy accounts. Yep. And that was it. Yeah.\u003C/p>\n\u003Cp>Andrew: There you go.\u003C/p>\n\u003Cp>Kevin: Great. So we've now got we've now got engrok rocking and rolling over here. Great. So now what we're gonna do is go over to battles go over to Battlesnake. We'll create a new snake like we did last time.\u003C/p>\n\u003Cp>So this is ready, set, battlesnake. Ready, set, battlesnake. Cake.\u003C/p>\n\u003Cp>Andrew: Yes. That's it. Nope. Nope.\u003C/p>\n\u003Cp>Kevin: K for Kevin.\u003C/p>\n\u003Cp>Andrew: That's it. I love it. Beautiful.\u003C/p>\n\u003Cp>Kevin: So https phzn.ngrok. Io/snake. Engine region, Netherlands or Netherlands? Yeah. Well, Europe.\u003C/p>\n\u003Cp>So yeah. Sure.\u003C/p>\n\u003Cp>Andrew: Yeah.\u003C/p>\n\u003Cp>Kevin: Programming language, JavaScript, and platform Director. Should be\u003C/p>\n\u003Cp>Andrew: there. Directus. Now my question here is, does the logo look good?\u003C/p>\n\u003Cp>Kevin: Oh, let's see what happened to it.\u003C/p>\n\u003Cp>Andrew: So I used the I got them to add Yeah. It doesn't look too bad.\u003C/p>\n\u003Cp>Kevin: Yeah. It's an old it's an old one. So we'll fix it by the next episode, but it's good. It's just colors just colors and details. But yeah, that's that's our little bunny rabbit boy.\u003C/p>\n\u003Cp>Unknown API version. So there was an error. Yep. Even though we copied\u003C/p>\n\u003Cp>Andrew: You should paste it. So what I would say is, I think I think I think I think you might need to just reset. Because this used to happen on\u003C/p>\n\u003Cp>Kevin: Reset reset what bit?\u003C/p>\n\u003Cp>Andrew: Like oh, sorry. Reset everything. So just, like, ping it again. And if it doesn't work, then actually start running, like, restart your direct to server. Okay.\u003C/p>\n\u003Cp>This used to happen with replit all the time is it would get this, and then it would just need a couple minutes to start syncing up in the right way.\u003C/p>\n\u003Cp>Kevin: I don't know what that mean. I don't know what that means.\u003C/p>\n\u003Cp>Andrew: No. It's no. That's right.\u003C/p>\n\u003Cp>Kevin: So if I hit that endpoint Yep. Oh, it still says hello world. Oh. Why? Oh, why?\u003C/p>\n\u003Cp>Because we needed to rebuild the extension, then we needed to restart director. So there you go. That was our little people.\u003C/p>\n\u003Cp>Andrew: What are you doing?\u003C/p>\n\u003Cp>Kevin: No bill. What what what are you doing? Hit ping. Perfect. There it is.\u003C/p>\n\u003Cp>Oh, battle snake. It looks sick. Yeah. I love that. Yeah.\u003C/p>\n\u003Cp>So now we have a snake. Right? But we haven't implemented any other endpoints. So this is the time to do it. Now this is the point where maybe, like, we split out the move logic into a separate file to stop it.\u003C/p>\n\u003Cp>No. Do you wanna know what?\u003C/p>\n\u003Cp>Andrew: I actually wish that the move logic was in with everything, even in the JavaScript starter snake. I understand why it's not, but I actually think it's way better to have everything in one place just so all of your routes are are there and you're you're able to change that data. So I think I think let's do exactly what we That\u003C/p>\n\u003Cp>Kevin: works for me. So there we there we go. And I am just gonna shrink this slightly and shrink this slightly so we can get the replet up and kind of do a little do a little moving from one to the other. Now can I, can I shrink this sidebar down? Yes.\u003C/p>\n\u003Cp>Perfect. And maybe even shrink that. Okay. Rock and roll. Get rid of that.\u003C/p>\n\u003Cp>Oh, and get rid of that. There we go. So first thing we're doing is is move safe? So move, get some data in. Let's console log the request just so we can make sure, like, is it in request dot body?\u003C/p>\n\u003Cp>I I mean, I'm assuming it's in request dot body. Yep. Let's let's just double check that, and just respond with hello.\u003C/p>\n\u003Cp>Andrew: I like that after our last adventure where we had to disappear and through the magic of editing come back, we've decided to now add console logs earlier as we go so we can save ourselves some trust down the road.\u003C/p>\n\u003Cp>Kevin: That's my style. That's my style. Discum. Okay. Experiential.\u003C/p>\n\u003Cp>This is the point where and these these logs are gonna get noisy in a moment. Yep. I may even take them down inside until we need them, and then I can make them smaller still and then I can bump them back up. So what are we gonna do here in Battlesnake? We have a Battlesnake.\u003C/p>\n\u003Cp>Let's create a game, create game. Add ready set Battlesnake standard board 11 by 11.\u003C/p>\n\u003Cp>Andrew: And that's good start game.\u003C/p>\n\u003Cp>Kevin: Good. 404, 404, 404, 404.\u003C/p>\n\u003Cp>Andrew: Well, great. So but here's the thing. If you didn't watch episode 1 so here's the interesting thing. Is technically, technically in Battlesnake, you can actually win if you 404 or have a 500 error every single time because you have to set a default move that your snake makes. And I think that there's something, I mean depending on the implementation, I think there's something cool that you could do about actually having a way to change that default.\u003C/p>\n\u003Cp>Anyways, but then\u003C/p>\n\u003Cp>Kevin: game's still in progress?\u003C/p>\n\u003Cp>Andrew: Yeah. It's been weird and slow. It's, like, not actually still in progress, but the platform's taking a bit of time to catch up with, I think, what's actually going on. So Why is it 404ing?\u003C/p>\n\u003Cp>Kevin: Root to talk. Kevin. Host. So we'll rebuild that, and we'll restart directors. I was using the wrong method right here.\u003C/p>\n\u003Cp>It's a post request to slash move. Okey dokey. So create game, add ready set battlesnake, hit start game. That should be better. There we go.\u003C/p>\n\u003Cp>So move gets hit. Oh, so this is it. So the data comes in. Yes. Req dot, req dot body.\u003C/p>\n\u003Cp>Fantastic. So now let's move all of this over. I might do a little bit of cleaning up as we go.\u003C/p>\n\u003Cp>Andrew: It'd be interesting. Yeah. Never mind. Let's let's get to it.\u003C/p>\n\u003Cp>Kevin: Let's get to it.\u003C/p>\n\u003Cp>Andrew: Go ahead. I was gonna say it's it'll be interesting if we if we wanna add the start and end point and log what's coming through there. I think there's something interesting in that as well, just to kinda see what that looks like before the logic is implemented. Because it does get really busy once the logic is implemented. At least right now, we're just getting those 404 errors or, like, the basic logs.\u003C/p>\n\u003Cp>Kevin: It's a start. And is it a post request? I think it is. Yep. Yep.\u003C/p>\n\u003Cp>Post. We probably should respond. Right?\u003C/p>\n\u003Cp>Andrew: Yeah. And and it'll it'll get angry with us. But\u003C/p>\n\u003Cp>Kevin: And and. Yep. And just because they are gonna get in the way, I'm just gonna pop them down there. Okay. Let me just, cough.\u003C/p>\n\u003Cp>Let me mute.\u003C/p>\n\u003Cp>Andrew: Yeah. And so what's interesting here is so I think we we said this earlier, like, the start and end points. You don't really need them for anything, but they're useful if you wanna implement some more serious logic, which we may do sort of with our direct as Battlesink down the road. So you'll see here once we rebuild and then save again, you'll actually be able to kinda see the stuff that comes in\u003C/p>\n\u003Cp>Kevin: Yeah.\u003C/p>\n\u003Cp>Andrew: Through there.\u003C/p>\n\u003Cp>Kevin: So we need the width The height. And the and the height and the Head. Snakes. I think that's all we need. From rec.body.board.\u003C/p>\n\u003Cp>Right? Yeah. It's all in this thing called board. Yeah. Great.\u003C/p>\n\u003Cp>And the other thing we need is my head, and I am just gonna copy and paste that little convenience there because that's that's wicked.\u003C/p>\n\u003Cp>Andrew: If you by the way, if you really don't wanna have those 2 constant, like, lines that you have there, if you're just, like, really focused on compressing, you can technically pull it from that sneaks variable that you're defining in there. It's just\u003C/p>\n\u003Cp>Kevin: a little bit more more to do it. Absolutely. Yeah. Just can't I mean, because\u003C/p>\n\u003Cp>Andrew: be bothered.\u003C/p>\n\u003Cp>Kevin: Can't be bothered. Right. So so so we've got the we've got the width and the height. So first thing we were doing is don't don't move out of avoid walls, and we're just gonna copy and paste it. Now we're not.\u003C/p>\n\u003Cp>First thing we're gonna do is set do the is moves we're gonna do the is moves safe thing. That's the other bit of, boiler plating, I guess.\u003C/p>\n\u003Cp>Andrew: Yeah. And to be honest with you, you don't I mean, so this is like the the default logic. Technically, you can implement logic that doesn't use this, but this is just like the most straightforward way to do it. So\u003C/p>\n\u003Cp>Kevin: Sure. So this is avoid walls. So my head exists. It's movesafe.leftforce. Great.\u003C/p>\n\u003Cp>Board height. Interesting. I think we just called that\u003C/p>\n\u003Cp>Andrew: We call it height Height. So we just need to change all of those heads to my head and all of those heights to\u003C/p>\n\u003Cp>Kevin: No. Head to head is correct. My head. Oh, you just\u003C/p>\n\u003Cp>Andrew: got to use my head? Okay.\u003C/p>\n\u003Cp>Kevin: Yeah. But board height. So what we're gonna do here is say height. We'll put bring that in as board height so I don't have to rewrite everything. We'll bring this in as board width.\u003C/p>\n\u003Cp>There we go. Job done. I'm also just while we're here, I'm just gonna just gonna we'll make things just a little more little more succinct, perhaps. This is valid. Right?\u003C/p>\n\u003Cp>Just so it's 4 lines as opposed to so many so many lines.\u003C/p>\n\u003Cp>Andrew: This is valid JavaScript. Really? Yeah. I hate indenting so much.\u003C/p>\n\u003Cp>Kevin: I would But indentation doesn't matter. So we avoid we avoid the walls. Great. And then it's avoid bodies. And we've already got the snakes.\u003C/p>\n\u003Cp>We've already got snakes stored here. So that is the equivalent of that line there. And so we're gonna take this for loop. We will dump that in here. And once again, I'm just gonna take this moment to just, to just clean up a little bit.\u003C/p>\n\u003Cp>This time because the conditionals are longer, I probably am inclined to leave them to leave them like this, but just just remove a bunch of, you know, white spacing. And there's some funky indentation going on here. There, boom. There we go. All right.\u003C/p>\n\u003Cp>Then if there's any save moves left, the console log and we return move down. Oh, if if there are none left, we go down. I got it. I got it. I got it.\u003C/p>\n\u003Cp>So, all the safe moves if no go down. Great. There we go. And it won't be return. It'll be red stop return red stop JSON.\u003C/p>\n\u003Cp>And then it won't go further down. Alright. And it will have returned there, so it won't continue. So I don't need to announce or anything. We pick the next move.\u003C/p>\n\u003Cp>I am noticing hang on. Hang on. Game state dot turn is not correct. Let's make sure my head piece. Yep.\u003C/p>\n\u003Cp>Snakes. Everything there is fine. It's just it's just here. Game state doesn't exist. That's req.body.tan, which means oh, no.\u003C/p>\n\u003Cp>Req. Yeah. That's fine. Req.body.tan. And then res.json, then we'll look at safe moves.length, pick the next move.\u003C/p>\n\u003Cp>We'll log it. And we will return it. I'm sorry. It isn't a string. It's a it's an object, isn't it, with a move value?\u003C/p>\n\u003Cp>Andrew: It is\u003C/p>\n\u003Cp>Kevin: Next move. So I think I think that is that's it. That's that's\u003C/p>\n\u003Cp>Andrew: a whole efficient, Kevin. That was wonderful. Okay.\u003C/p>\n\u003Cp>Kevin: Thank you very much. Thank you very much. Yeah. I think that is our our snake as implemented last time. Let's rebuild the extension.\u003C/p>\n\u003Cp>Let's restart the. Once again, that shouldn't need to be the case, but it is just at this point we're recording, so so be it. And oh, that game in progressing has persisted to be a challenge.\u003C/p>\n\u003Cp>Andrew: It has. So ignore. If I refresh,\u003C/p>\n\u003Cp>Kevin: does it know it's done? No. Okay. So New game. We'll have to keep.\u003C/p>\n\u003Cp>New game, and we'll send in, I don't know, loopy bot. Or does loopy bot just do the\u003C/p>\n\u003Cp>Andrew: Just does the loop. Yeah. Yeah. Hungry is good.\u003C/p>\n\u003Cp>Kevin: Hungry is probably a good little test.\u003C/p>\n\u003Cp>Andrew: Hungry is good. He was a good test for us last time. So I feel like we can see how he responds.\u003C/p>\n\u003Cp>Kevin: Okay? Obviously, it's a little more verbose down here. You can reduce the amount of logs with an environment variable. We died that, you know, that's the end state. So, oh, wait.\u003C/p>\n\u003Cp>If it won't, can I hit play? Yeah.\u003C/p>\n\u003Cp>Andrew: You can hit play.\u003C/p>\n\u003Cp>Kevin: And sorry. Show the coordinates. Fast, please. Save game.\u003C/p>\n\u003Cp>Andrew: No. Just go back. Just go\u003C/p>\n\u003Cp>Kevin: back. No. Oh, do I just I'll back back back back back. Alright. So r one is the orange is the, oh, we won.\u003C/p>\n\u003Cp>Andrew: So what did\u003C/p>\n\u003Cp>Kevin: it say\u003C/p>\n\u003Cp>Andrew: in the logs that you thought we lost?\u003C/p>\n\u003Cp>Kevin: No. No. We we didn't lose. It ended. I sorry.\u003C/p>\n\u003Cp>I said we died, but I meant it ended.\u003C/p>\n\u003Cp>Andrew: What does the what does the actual response say though? I'm not I'm curious. I don't have any idea.\u003C/p>\n\u003Cp>Kevin: It is game ID rule set map stand up source. The oh, it's the it's an n the last 10.\u003C/p>\n\u003Cp>Andrew: Yeah. Yeah. But does it say 1?\u003C/p>\n\u003Cp>Kevin: Let's find out.\u003C/p>\n\u003Cp>Andrew: I feel like it somewhere should say 1.\u003C/p>\n\u003Cp>Kevin: I think no. I think snakes is just one long. Oh, yeah. But it could be you or anyone else, I suppose. Fair\u003C/p>\n\u003Cp>Andrew: enough. It may not say it in there. I'm just curious.\u003C/p>\n\u003Cp>Kevin: Maybe it's the fact you still exist. I mean, let's find out when we die. Do you know? Oh, yeah. If we look at you, it has the ID oh, let me, woah.\u003C/p>\n\u003Cp>Andrew: There we go. I was gonna say I feel I felt like I wasn't seeing it, but I\u003C/p>\n\u003Cp>Kevin: feel like Sorry. That was, that was a keyboard shortcut thing going on. Alright. It has a health. I wonder if the health knows that.\u003C/p>\n\u003Cp>I mean, we'll just do it a couple of times, but let's let's watch. Let's watch our our little sneaky there.\u003C/p>\n\u003Cp>Andrew: You do it well. Hey. Like, that logic is good. Okay.\u003C/p>\n\u003Cp>Kevin: Head to head combat, which we haven't built logic for. Maybe we'll do that this time.\u003C/p>\n\u003Cp>Andrew: It's a good idea. I\u003C/p>\n\u003Cp>Kevin: think we because I because I kind of feel like that was what we intended to do this whole episode. Yeah. Congratulations. We're done because we can't build it in flows, and that's the that's the thing here. I have one other I maybe you can execute a flow from Yeah.\u003C/p>\n\u003Cp>From this, and then this just becomes the entry point into the flow.\u003C/p>\n\u003Cp>Andrew: That's what I was just gonna say. I was like, is there a way that we could set up the one of the endpoints in here and then have the trigger in flows? You're able to do everything from there?\u003C/p>\n\u003Cp>Kevin: Maybe.\u003C/p>\n\u003Cp>Andrew: That might be fun. I feel like that's an interesting way because I I do think that flows is like this interesting.\u003C/p>\n\u003Cp>Kevin: I've never done it, but, I'm sure it will be fine. So let let's take another look at some new extensions documentation that was recently written. The resources on the not this one. I'm looking for resources, components, packages, extension services. Here we are.\u003C/p>\n\u003Cp>So underneath directives, every time you make a request, it's actually going off to one of these services, which then, you know, which then executes your your request. And inside of extensions, you can also access these services. Various services are available within directors, including item service, collection service, file service, and they're available within the extensions context. So there is a router here in the handler, but I think we can also pass in this context. Right?\u003C/p>\n\u003Cp>Let me just think about the best way to do this. I think it might be just playing around with this router dot get here. So, so we have this context. I'm gonna bump that back up actually. And if we console dot log, the context and we see just here, we, destructure get schema and services and then we destructure the individual service.\u003C/p>\n\u003Cp>So let's let's just do that outside of the individual. Outside of the individual. No. I think for just a moment, we'll do it just inside of this one just because this is the one we're gonna hit. So we don't we don't just have to mess with that.\u003C/p>\n\u003Cp>And then instead of doing this, let's just console log the the services and just see what happens. I'm actually gonna do a console dot here, services dex null. And what this will do is effectively a console log that never does this kind of cut off thing. It'll always show you all of the nested layers just because I'm not sure what it looks like and I don't wanna I'd rather just be a little more verbose once. So dotcom.\u003C/p>\n\u003Cp>So what we're gonna do here is go back to our root endpoint and hit enter. Oh, sorry. Not root. R snake.\u003C/p>\n\u003Cp>Andrew: There we go.\u003C/p>\n\u003Cp>Kevin: And what happened here? So we have some services. Let's, yeah, let's just expand this for a moment. Webhook service. I, there is a flow.\u003C/p>\n\u003Cp>I, I believe a flow service.\u003C/p>\n\u003Cp>Andrew: Oh, nice.\u003C/p>\n\u003Cp>Kevin: Gonna that's gonna wanna be the one that we I mean, is this the one we wanna I don't know. I mean, all we wanna do is hit all we wanna do is hit an endpoint. But Yeah. Let\u003C/p>\n\u003Cp>Andrew: let's go for have\u003C/p>\n\u003Cp>Kevin: a let's have let's have a play. Sorry. Go on. No.\u003C/p>\n\u003Cp>Andrew: I was just gonna say, do we wanna go in? I don't know. Never mind. Let's let's test this out and then and then we'll go forward from there.\u003C/p>\n\u003Cp>Kevin: Sounds good. So let so what you do here is you create a new service with the collection there. So you know what we'll do here. There are some commonly used services. We can just refer to the full list of services directly in the code base here, which is actually what I should have just done.\u003C/p>\n\u003Cp>So we have flows here. So we can create flows, create many, update, delete. This actually isn't what we want because this is all about running flows. Sorry. And the the crud of flows.\u003C/p>\n\u003Cp>And we don't wanna do that. We just wanna we just wanna run a flow. So maybe the first thing we sorry. Go ahead.\u003C/p>\n\u003Cp>Andrew: No. No. No. Is it just the webhooks that we want, the webhooks service then? No.\u003C/p>\n\u003Cp>Because that's to create a webhook. That's\u003C/p>\n\u003Cp>Kevin: not Yeah. Exactly. That's outbound. So so what we'll do here is we'll go to the admin. Oh, wow.\u003C/p>\n\u003Cp>We will create a little flow and we'll see if we can trigger that from our code. That's basically the test here that it works. So we create a flow. We'll call this info. Snake info.\u003C/p>\n\u003Cp>All of that feels good. Maybe traffic activity in logs. I think that's fine. Then we have the webhook. Webhook.\u003C/p>\n\u003Cp>You're right. It will be a get request, response body, data of last operation.\u003C/p>\n\u003Cp>Andrew: Feed all the data just to have it?\u003C/p>\n\u003Cp>Kevin: That that that's happened. So oh, no. So this is the response body. This is what it will respond with. We only want to we wanna create the response and send it.\u003C/p>\n\u003Cp>But, actually, what you're describing is it was here. It was this option here, track activity in the box.\u003C/p>\n\u003Cp>Andrew: Alright. There we go.\u003C/p>\n\u003Cp>Kevin: So back to the trigger setup, we'll turn cash off. We don't want it to be asynchronous, get request, save, And we will re- we- it will be the data from the last operation. So we'll just run a script and we will just return this, I think. I mean, that makes sense. Yeah.\u003C/p>\n\u003Cp>That works. I've not done this before. So we are we are really finding out together how this works.\u003C/p>\n\u003Cp>Andrew: Works is very smooth. I like just being able to have it.\u003C/p>\n\u003Cp>Kevin: I really like it too. So we've got a save. So now we have this idea of a flow, and I think that's the thing that's interesting to me at least.\u003C/p>\n\u003Cp>Andrew: So you'd rather use the ID than actually just use the flow endpoint, like the webhook endpoint?\u003C/p>\n\u003Cp>Kevin: I could. I don't think that's, like, the proper way of doing it. But could we do that? Yeah.\u003C/p>\n\u003Cp>Andrew: I mean, I feel like I feel like Okay. I'm interested in seeing both ways, right? I'm interested in seeing ID flows, which I think is the proper way, and then just calling the webhook from within the code. Right?\u003C/p>\n\u003Cp>Kevin: Yeah. I'm gonna be I I don't even know how to make a web request in these off the top of my head.\u003C/p>\n\u003Cp>Andrew: Just I think it's just Axios, isn't it?\u003C/p>\n\u003Cp>Kevin: I think it's just Axios. But but how is Axios, like, exposed? And do you wanna know what? I'm pretty confident there are just some guides that were written around this that I think will just help us. Endpoints create a public API proxy.\u003C/p>\n\u003Cp>Here we go. This will this will help. Yeah. It's a it's a fetch.\u003C/p>\n\u003Cp>Andrew: Oh, alright.\u003C/p>\n\u003Cp>Kevin: Cool. So we will so we hit slash. So what we're gonna do here, we're we're forget all these services for a minute. They don't I don't think they're gonna matter.\u003C/p>\n\u003Cp>Andrew: No. They won't matter because literally we're just basically now that we've created that flow, we're just doing a call to that webhook and then\u003C/p>\n\u003Cp>Kevin: Yeah. We're gonna do a response, await, fetch, and then slash flows, async. Okay. And then, yes, this is response okay, response Jason await Jason, all of this jazz. I normally, honestly, just do this pretty low rent, then r r dot JSON and our response is the data.\u003C/p>\n\u003Cp>So I think we can just return reds dot JSON response. Yeah? Yep. I might just be explicit here. Flow response.\u003C/p>\n\u003Cp>Flow response. Yeah.\u003C/p>\n\u003Cp>Andrew: Yeah.\u003C/p>\n\u003Cp>Kevin: And maybe yeah. That yeah. Screw it. Let's try it.\u003C/p>\n\u003Cp>Andrew: Let's do it. Gotta get this I feel like this is why I enjoy, like, non typed languages because you just mess around and see what happens.\u003C/p>\n\u003Cp>Kevin: Yeah. I mean, you can build extensions just as an FYI with TypeScript. I just didn't oh, yeah. I thought this might be a little easier. So if I hit refresh here, we should see the same the same thing the same thing.\u003C/p>\n\u003Cp>Oh, wait. Hang on. I don't know why that's happening. Oh, was there an error? You have triggered an unhandled rejection.\u003C/p>\n\u003Cp>Failed to pass URL. So it didn't like the\u003C/p>\n\u003Cp>Andrew: Yes. So just add\u003C/p>\n\u003Cp>Kevin: the link to the I mean, sure. But that that doesn't make this portable. Right? That isn't let me just have a quick think here.\u003C/p>\n\u003Cp>Andrew: Oh, I see what you mean. You wanna be able to pat yes. Okay. I see what you mean.\u003C/p>\n\u003Cp>Kevin: Because then if we deploy it somewhere else, this will Yeah. This will still work. That's that's that's gonna have another little look. Let's keep having a little look here. So still sort here.\u003C/p>\n\u003Cp>No. Because now I'm right because this is the flows. All I wanna do is know, yeah, how do I run a flow? Let's just do you wanna know I think I've just had I think I've just had an idea on how this works,\u003C/p>\n\u003Cp>Andrew: which is\u003C/p>\n\u003Cp>Kevin: actually not looking at the services. It's looking at the the way the SDK does it. So if we look at the, extensions, packages, sure. The SDK just like type, type doc. This is just the the full dump of everything the SDK can do.\u003C/p>\n\u003Cp>There is an endpoint in here called something there's something in here for running flows. Andrew, I'm going It is I love a c.\u003C/p>\n\u003Cp>Andrew: So even if you write the documentation, everybody, you still need to read the documentation.\u003C/p>\n\u003Cp>Kevin: You do still need to run it. Here it is. Right. Create a flow, retrieve a flow, list flow. So this is all the stuff we just saw, but Yes.\u003C/p>\n\u003Cp>Here we are flow with get webhook trigger, trigger flow. What is going on here? Let's take a little look. Failed to pass URL from /flow/trigger/uid.\u003C/p>\n\u003Cp>Andrew: Yeah. That I mean, that makes sense to me because it's not a full URL. Right?\u003C/p>\n\u003Cp>Kevin: Do you wanna know what I did sneakily on on the side here. I have a chat with one of my colleagues because, of course, I did because I have that power. It does just need to be the full URL. So let's stop. Let let's stop battling against I was right.\u003C/p>\n\u003Cp>You're right.\u003C/p>\n\u003Cp>Andrew: You're right. But you're right. It's not portable. You're very true. It's like you'd now need to, like, worry about changing this if you change where you're you're hosting it.\u003C/p>\n\u003Cp>Kevin: So I do think Which I think won't matter for the scope of this. So now built that, restarted that. So now if we hit this, it did return and it did it by getting by by getting the the, yeah. So, oh, that's really exciting. Okay.\u003C/p>\n\u003Cp>Let's abstract this logic out then. Let's get this whole move thing. Let's just comment it out. We know it works. Okay.\u003C/p>\n\u003Cp>And what we're gonna do here instead is we have a post. And so, let's set up a new flow. Not here. Let's set up a new flow. Oh, that's so exciting.\u003C/p>\n\u003Cp>Okay. Cool. Snake.\u003C/p>\n\u003Cp>Andrew: So we're gonna we're gonna create a move we're gonna create literally recreate this entire logic as separate flows. Why not do it as one flow, though?\u003C/p>\n\u003Cp>Kevin: Oh, because it No. No. No. Just because it won't be each endpoint. So everything move is gonna happen in one flow, and that that's yeah.\u003C/p>\n\u003Cp>Yeah. It's cool, isn't it? I think track activity and logs, I'm going to level with you. I'm not I'm going to say don't track anything because it's just gonna it's gonna absolutely explode the logs because it can be every like, the full body every time. And we have the the the logs over here.\u003C/p>\n\u003Cp>So we won't do that. That will be a webhook. Data of lost operation, that's fine. Not asynchronous. Don't cache.\u003C/p>\n\u003Cp>Post. Okay. So exciting. Okay. And we will, run a script and we will return move left.\u003C/p>\n\u003Cp>Right. We'll just we'll just do that to start and just test test it works. Return move. Hit save. And we have an ID for this one.\u003C/p>\n\u003Cp>Great. And, what we're gonna do here? We're gonna do we're gonna copy this. We are gonna change the ID and we're just gonna go post, sorry, methods. I wanna say it's post and I think it's body equals JSON dot stringifyreq.body.\u003C/p>\n\u003Cp>I think that's I think that's the fetch. I think that's the fetch way of doing it. So What\u003C/p>\n\u003Cp>Andrew: is the fetch way of doing it?\u003C/p>\n\u003Cp>Kevin: Is it good? Okay. Fetch. My memory has not failed me today. I'm literally I'm so pumped that we're able to do it in flows.\u003C/p>\n\u003Cp>That was a really good I I think that was yours. You can have that one.\u003C/p>\n\u003Cp>Andrew: No. We're gonna I'm gonna give that that's that was a 5050. We left brain, right brain thing here. I feel like it was one of those days.\u003C/p>\n\u003Cp>Kevin: Okay. Okay. Alright. So we're ready set. Ready set Battlesnake, Hungry Bot.\u003C/p>\n\u003Cp>Sure. And start game. What's happening?\u003C/p>\n\u003Cp>Andrew: It's happening. It's happening. It's happening. It's happening.\u003C/p>\n\u003Cp>Kevin: But it will just go left, left, left, left, and die. Yep. Right? That's fine. Yeah.\u003C/p>\n\u003Cp>That's fine. It's still\u003C/p>\n\u003Cp>Andrew: it's still going into\u003C/p>\n\u003Cp>Kevin: the world. Awesome. Which means we are done with the code. We're not done. We'll need it for reference.\u003C/p>\n\u003Cp>Yeah. But we are in flows now. It's happening.\u003C/p>\n\u003Cp>Andrew: What's interesting here too, folks, is, like, you like, literally with those two endpoints, like, you don't actually need to implement start and end. Like, you can stop with just those 2 if you're like, I don't wanna have to manage 4 flows. Like, you don't actually need start and end at this point. And so I think, like, don't use them.\u003C/p>\n\u003Cp>Kevin: So first thing we did was avoid walls. I'm gonna run a script here. We'll return it, and then I'm just gonna do the it's annoying. You have to kind of create it from an existing path. Yeah.\u003C/p>\n\u003Cp>And then we're gonna take that and dump it in there. Okay. Avoid walls. Back to the back to the primitives. Now, you know what we didn't do?\u003C/p>\n\u003Cp>We didn't because we don't have the logs. We actually don't quite know what it looks like in here, which is annoying. Just a thought I've had.\u003C/p>\n\u003Cp>Andrew: Yeah. It's true.\u003C/p>\n\u003Cp>Kevin: But I think I know.\u003C/p>\n\u003Cp>Andrew: Well, I mean, let's see. Let's see what happens here. And I think the cool thing here is, like, now we return to, like, traditional programming as well. Right? There's a lot of different ways you can implement this within the flow.\u003C/p>\n\u003Cp>Like, there's so many different operations. Technically, you could feedback a lot of the information and then make, like, decisions there or just do it.\u003C/p>\n\u003Cp>Kevin: Let's let's return the data. Like, that's the whole data chain. And then so this first time, this is gonna fail absolutely miserably. But, oh, no. It won't log anywhere, will it?\u003C/p>\n\u003Cp>Do we\u003C/p>\n\u003Cp>Andrew: wanna turn on those logs then? I know we didn't want\u003C/p>\n\u003Cp>Kevin: to, but Yeah. Yeah. Can I turn them on then turn them off? Yes. Fine.\u003C/p>\n\u003Cp>Yeah. That's fine. Yeah. Yeah. Yeah.\u003C/p>\n\u003Cp>Sorry. I thought it was a one and done kinda deal. So let's create a new game. Create rematch. Okay.\u003C/p>\n\u003Cp>Cool. Whatever. Sure. Refresh. And there should be many Yeah.\u003C/p>\n\u003Cp>8. That was 8 moves. So it's it's gonna get unwieldy, but this is what matters.\u003C/p>\n\u003Cp>Andrew: That's great. That's awesome. Yeah. So we get\u003C/p>\n\u003Cp>Kevin: Except the distinct so the trigger where's where's all the, not being oh, so Are we not sending it? Are we not sending it precisely? And this is why I wanted to check. Yeah. Yeah.\u003C/p>\n\u003Cp>Oh, wait, what\u003C/p>\n\u003Cp>Andrew: did that say failed up there? Go back up to the options.\u003C/p>\n\u003Cp>Kevin: No, no, no, no, no. Force. Okay. Cache enabled force, cache enabled force. So cool.\u003C/p>\n\u003Cp>We have this fetch. We send that is how you that is how you do it. Right?\u003C/p>\n\u003Cp>Andrew: I mean, I could have been wrong. I was assuming, but ah, here we go. I'm glad that it has happened.\u003C/p>\n\u003Cp>Kevin: Yeah. Body.stringify. Body data type must match content type header, but I I don't think sure. Do you wanna layer what? Sure.\u003C/p>\n\u003Cp>Let's just whack that header in. Just in case it's that.\u003C/p>\n\u003Cp>Andrew: Yeah. See what happens.\u003C/p>\n\u003Cp>Kevin: I'm not losing any sleep over over adding that. Is that an error? Oh, no. We've left a log we've left a login somewhere. All the serve hang on.\u003C/p>\n\u003Cp>They're all the services.\u003C/p>\n\u003Cp>Andrew: Yeah. Didn't we didn't we remove that?\u003C/p>\n\u003Cp>Kevin: No. It's the it's the context. It's this console log context.\u003C/p>\n\u003Cp>Andrew: Oh, there we go.\u003C/p>\n\u003Cp>Kevin: I was like, that's a big that's a big object. So right. Restarting. Okay. Okay.\u003C/p>\n\u003Cp>Okay. We're gonna create rematch.\u003C/p>\n\u003Cp>Andrew: Let's get some logs.\u003C/p>\n\u003Cp>Kevin: Nice. Oh, head to head. Some quick a nice quick death. Okay. Are we getting Payload.\u003C/p>\n\u003Cp>There we go. There we go. There we go. So it's in trigger dot. Body.\u003C/p>\n\u003Cp>Body, I think.\u003C/p>\n\u003Cp>Andrew: Yep. Yeah. Trigger dot body. Yeah.\u003C/p>\n\u003Cp>Kevin: That looks correct. So, I mean, there's one way to find out, right, which is, so, trigger data dot trigger dot Bobby. Nice one. Bobby. So let's go and take this first up.\u003C/p>\n\u003Cp>So first thing we'll do, of course, sorry, is we will is move safe. We have to think about how we, because we, we need to kind of alter this value as we go. Maybe we return that. Maybe we return that with each step. Right?\u003C/p>\n\u003Cp>So we'll start with a is move safe and we'll just return it every time. So Okay. We'll start this time, we'll create it. I also think that could be a const. Anyway, avoid walls.\u003C/p>\n\u003Cp>So we need these values. Do you\u003C/p>\n\u003Cp>Andrew: wanna bump up the text size there a little bit more? Thank you.\u003C/p>\n\u003Cp>Kevin: You know what? I'm actually inclined. Let's rename this one. Let's call this one set up variables. Yeah.\u003C/p>\n\u003Cp>Like that. Let's call them let's call it globals. We'll just make the key global so it's a little shorter. All we're gonna do is return is return. We're gonna return what was it called?\u003C/p>\n\u003Cp>Is move safe. We will also do forward width. It's going to be data.trigger.body.width. Old height. What was the other thing?\u003C/p>\n\u003Cp>Oh, my head. So that's all of that. And then, we yeah. Just return that. Right?\u003C/p>\n\u003Cp>Yep. Sponsored global. Yeah. Yeah. We will.\u003C/p>\n\u003Cp>Just just I I wanna be I wanna be testing early in Austin even though, you know, we're not doing much there. I just wanna I just wanna be validating that we haven't broken something there. So we will create a rematch. So all we should be getting now is an extra property in the data chain. Wow.\u003C/p>\n\u003Cp>That was a really short, really short game. I think it was, like, 2 moves. Yeah. Oh, rec is not defined. I think I left in a a remnant of what it was before.\u003C/p>\n\u003Cp>Rec.body. Yeah. Data. Trigger dot body. That's why we test.\u003C/p>\n\u003Cp>Create a rematch. What else have you used Flows for in the past?\u003C/p>\n\u003Cp>Andrew: So I did the, the DevCycle Directus integration that I built out. So this was, it's worth checking out, just to see, like, the different use cases here. So it basically allowed for you to do an API call to a patch API on the dev cycle, patch API endpoint on the dev cycle platform to, like, pass basic data into into the service and to, like, put, like, an edge database for feature flag management. We might use that actually, when we start to do the dev cycle integration just because it's a really fast way, and I know that it already works with Directus. So, nice.\u003C/p>\n\u003Cp>But yeah.\u003C/p>\n\u003Cp>Kevin: That's called EdgeDB. EdgeDB. Yeah.\u003C/p>\n\u003Cp>Andrew: So it's just, it's just, like, a faster way to pass data. So how are we doing here?\u003C/p>\n\u003Cp>Kevin: No. No. But if I refresh, I think I fixed it.\u003C/p>\n\u003Cp>Andrew: Yeah. Right.\u003C/p>\n\u003Cp>Kevin: That's everything in the in the global. Now I'm not sure. So I think is move safe is one that we might need to pass, like every move we're going to need to we're going to need to reset that, but that's fine. So cool. Next thing we'll do then is avoid walls.\u003C/p>\n\u003Cp>Avoid walls. We're gonna run a script. We have data, and we have our avoid walls logic here.\u003C/p>\n\u003Cp>Andrew: Yeah. I feel like this is also just a really nice visual way to represent this whole\u003C/p>\n\u003Cp>Kevin: This those are the steps.\u003C/p>\n\u003Cp>Andrew: I really wanna go and find my Node JS snake or my, my Node RED snake that I created because I did the same it was the same process that I went through.\u003C/p>\n\u003Cp>Kevin: Was it sorry. Just very quickly. Well, did I call it my head still? I think I did. Yeah?\u003C/p>\n\u003Cp>Yep. You did. Yep. So the nice thing about this is we have is say is move safe left and all of this. So I think we wanna create a new variable called is move safe, and the value of that, I think this works, is gonna be data dot globals.\u003C/p>\n\u003Cp>Was it multiple? No. Global.\u003C/p>\n\u003Cp>Andrew: Yeah. Global.\u003C/p>\n\u003Cp>Kevin: Yeah. I think so. Yeah. Dot is move safe. Right?\u003C/p>\n\u003Cp>Andrew: Yeah. This this\u003C/p>\n\u003Cp>Kevin: is And then yeah. This is\u003C/p>\n\u003Cp>Andrew: something that's really interesting to know having used flows before. I was not taking advantage of the globals like that or not the globals because that's the thing you're creating here, but, like, the But the data chain. Touch on data chain. I thought you lost the data, basically No. As you went through.\u003C/p>\n\u003Cp>So that's interesting.\u003C/p>\n\u003Cp>Kevin: And I've had another thought about this. I think the way we're gonna do this is using last. So last, dollar sign last is a dynamic variable that will always be the output of the last step. But that means this line will become basically a boilerplate first line on every step in, I think. I think this creates a copy.\u003C/p>\n\u003Cp>We'll find out. We'll find out together. So next thing we're gonna do is we're going to destructure, my head board width, and board height from data dot globals. And then the rest of the code should be able to be untouched. Right?\u003C/p>\n\u003Cp>Exactly. Yeah.\u003C/p>\n\u003Cp>Andrew: It looks good. The\u003C/p>\n\u003Cp>Kevin: only and the only thing we wanna the only thing we wanna return is is move safe. Only thing we care about. Yeah. If this works, I'm gonna be so pleased with myself. I have a hunch it won't just because, of course, why would it?\u003C/p>\n\u003Cp>Let me just move return move out the way. In fact, we can remove that. So no. Of course not. Sorry.\u003C/p>\n\u003Cp>Ah, I've deleted it now. It's fine. We're here. So return move because what we're gonna do in this step is we're gonna just do that last bit of logic. If all there safe moves, if no go down.\u003C/p>\n\u003Cp>So we're gonna get rid of that. All we care about is next move and return. Yep. Because that is a a step between where we are and where and where we're going. So I have in my here we are.\u003C/p>\n\u003Cp>This is what we just had in our last step. So we have beta dot globals. Now is move safe. There we go. So next move, safe moves.\u003C/p>\n\u003Cp>Is it safe safe? Why is it called safe moves? Oh, here. I need this line too. I'm gonna call that one.\u003C/p>\n\u003Cp>Safe moves. Object dot keys is move safe. Filter down is move safe key. Fine. Fine.\u003C/p>\n\u003Cp>And that's just getting the the the values. Then next move, is safe moves, math floor safe moves. So that that should be it, And then we should just be able to return move next move like so. So that's the last step in. That's the last step in the chain.\u003C/p>\n\u003Cp>Let me bump that up one more time. Sorry. So that's all the logic again. We have that boilerplate starts. We don't quite know if that works yet, but in theory\u003C/p>\n\u003Cp>Andrew: It should.\u003C/p>\n\u003Cp>Kevin: Theory, it should. It should. Dangerous last words. Those. Sorry.\u003C/p>\n\u003Cp>So we'll just set ready set battlesnake in there because we're not equipped to have multisnake yet.\u003C/p>\n\u003Cp>Andrew: Nope. Did not work. What are our logs saying?\u003C/p>\n\u003Cp>Kevin: Thank you. Thank you very much. Yes. It did not work.\u003C/p>\n\u003Cp>Andrew: You're welcome. I feel like I need to add these\u003C/p>\n\u003Cp>Kevin: useful Last is not defined. Absolutely. I know exactly where the typo was. It's data dot last, and it will be wrong there as well. Data dot last.\u003C/p>\n\u003Cp>Right? Yep. Yeah. Cool. And what's nice now is you're not having to restart Directus every time because now it's handled by the flow.\u003C/p>\n\u003Cp>That's wonderful. It is cool. There was a little bit of of, let's call it friction first time. Okay. That's not ideal.\u003C/p>\n\u003Cp>42, 44, payload. Cannot convert undefined or null type. Okay. What are we? Payload after after but here's the thing.\u003C/p>\n\u003Cp>After avoid walls, look at that. It did say up force, which means everything's working until the return move. So that's fine. So that means it works, this whole passing passing is move safe each step. Yeah.\u003C/p>\n\u003Cp>But where it's breaking is this last one.\u003C/p>\n\u003Cp>Andrew: Okay. So let's look at this again. So async function\u003C/p>\n\u003Cp>Kevin: the error was cannot let's actually read the error. The error says, cannot confer undefined or null to object, which means the issue is here in object dot keys. So we have is move move safe. I think it can just be data dot last if that's all we're passing step to step because we don't return an object with is move safe. We just return is move safe, which means here again, although\u003C/p>\n\u003Cp>Andrew: I mean, let's see. Let's see what happens.\u003C/p>\n\u003Cp>Kevin: Yeah. I think I think that'll fix it. So if we hit create rematch Yes. It avoided pause. Nice.\u003C/p>\n\u003Cp>Lovely stuff. And let's just, let's just validate that was indeed what we needed it to be. Left.\u003C/p>\n\u003Cp>Andrew: Hey. There we go.\u003C/p>\n\u003Cp>Kevin: Heck, yeah. Which means we're onto we're we're now onto a winner, basically. It's this is the starting logic for our for the no. It isn't. Oh, it's it's somewhere in between that we haven't quite got the standard because this is the first one after the global and this is the last one.\u003C/p>\n\u003Cp>So that's fine. We need to create one more here. Yep. And, what's next? Avoid bodies.\u003C/p>\n\u003Cp>Andrew: Avoid others. Yep.\u003C/p>\n\u003Cp>Kevin: Run script. Paste that in. And we don't need is move safe anymore. We have the data dot globals. And where are the where are where is the logic?\u003C/p>\n\u003Cp>It's here. And just because I think I think it's gonna be easier, I'm just gonna great. Great. And I don't think we need board width or board height anymore. We just need my head.\u003C/p>\n\u003Cp>We have snakes. So I believe we had bored. I think we got bored out. Yes. I'm not sure we did.\u003C/p>\n\u003Cp>Let's look at the globals again. The actual board itself needs to come with 2. So, let's call it snakes. Let's just add snakes here. So data dot trigger dot body dot board dot snakes.\u003C/p>\n\u003Cp>Then let's create this last one again, as avoid bodies and that should have saved, but it's fine. Okay. So we have my head and we have snakes. I think I gen oh, yeah. I genuinely think nothing needs touching here.\u003C/p>\n\u003Cp>Andrew: No, I think it's good. And I think we've the, the code works and we're even past.\u003C/p>\n\u003Cp>Kevin: Yeah. I don't see any point of weakness in this at the moment. So we hit say, oh no, we don't, we just,\u003C/p>\n\u003Cp>Andrew: Famous last words.\u003C/p>\n\u003Cp>Kevin: We do that. Then we do that. So I'm gonna just Very good. We'll hit save. Oh,\u003C/p>\n\u003Cp>Andrew: what's going on? Value fulfilled resolving collection, direct us operations.\u003C/p>\n\u003Cp>Kevin: Value fulfilled resolve. In fact, it has to be I, don't know what that is. Record not unique.\u003C/p>\n\u003Cp>Andrew: For field, resolve and click direct operations. Maybe if we turn off that logging now. Just turn off the logging because I think that's Yeah.\u003C/p>\n\u003Cp>Kevin: But that isn't logging. That's a database save error, but I don't know why. Let let's just forget this was here for a moment like it was before, and it was fine. Okay. That does save.\u003C/p>\n\u003Cp>So if I take this instead and send it to avoid bodies and hit save, it's fine. And then if I go here to return move, fine. Do you wanna know why I'm just gonna walk away slowly?\u003C/p>\n\u003Cp>Andrew: That's the right that's the right answer. If the thing starts working\u003C/p>\n\u003Cp>Kevin: So we don't wanna create a rematch now because we wanna create a game with another snake. Yeah. Yeah. Star hungry\u003C/p>\n\u003Cp>Andrew: in there. Alright. Let's see how this works. Okay. We got it.\u003C/p>\n\u003Cp>He Hang on.\u003C/p>\n\u003Cp>Kevin: We've not had to Yes. Hey. There we go. Yes. Nice.\u003C/p>\n\u003Cp>Get in. Okay. Done. Nice. So the final thing here was this, if there's no safe moves, go down.\u003C/p>\n\u003Cp>Andrew: I don't think we need that. I genuinely it's like a Oh, yeah. Backup. It'll always Yeah.\u003C/p>\n\u003Cp>Kevin: Well, because if there are no safe moves, you're toast anyway.\u003C/p>\n\u003Cp>Andrew: Exactly. So it's really just, like, if you want to have, it I don't know. It's good programming practice for you to build it in, but, like, I think here, like, we can worry about that down the\u003C/p>\n\u003Cp>Kevin: road. Do you wanna know what? Given that this was basically the scope for this episode, I'm gonna add it. Why don't we add 1 one new block in?\u003C/p>\n\u003Cp>Andrew: Right.\u003C/p>\n\u003Cp>Kevin: Because I wanna do avoid avoid head to head.\u003C/p>\n\u003Cp>Andrew: K. Yep. That seems easy. Yeah. Because we're just basically doing look ahead here.\u003C/p>\n\u003Cp>Right? We're looking at, like, one extra block ahead. So so yeah. I mean, so this is the if you didn't catch it on the last stream or on the last, the last episode, we so head to heads, you can do and you can win, but it's all about size and rules, but, like, these head to heads here. But with the logic we currently have, we're only ever looking at what's directly next to us.\u003C/p>\n\u003Cp>So ensuring that, like, if we have another snake beside us or directly in front of us, we'll never go that direction. But if there's a snake that's 2 away in the same direction, so basically, we're repeating the logic that's in here and just or we could technically revise this logic. I think it's similar because it's just like Yeah. Yeah.\u003C/p>\n\u003Cp>Kevin: It will be similar, but I don't I do not think it's the same. So it's not the same. If we ditch this for a moment, we'll leave it as we could see it. So we care about the snakes, every snake, and we're gonna get rid of us. Now there is a a fancy way of doing this, which is, js return array without first item.\u003C/p>\n\u003Cp>To remove the first element in the in the array, you can use shift. Shift removes the first element of the array and returns it. So I think we can do this just to get rid of us first.\u003C/p>\n\u003Cp>Andrew: Yeah. And then we have to find our\u003C/p>\n\u003Cp>Kevin: because then we would have no valid no valid way to go. So So now we care about every other snake. So I'm gonna say head, it's gonna be snake dot body. Does snake have a head too? Does every snake have a head?\u003C/p>\n\u003Cp>Andrew: Everything has a head.\u003C/p>\n\u003Cp>Kevin: Snake dot head. So okay. Cool. And what we wanna do is look one space left, right, up, or down and remove if that's gonna be the direction we go in. Right?\u003C/p>\n\u003Cp>But we I'm just trying to have a think here because I think these are actually much more complex if statements.\u003C/p>\n\u003Cp>Andrew: They are. It's basically if I remember having done this before, it's basically all of those if statements that we had there repeated 4 times, if that makes sense.\u003C/p>\n\u003Cp>Kevin: Which we absolutely will not do. We will we will do, like, a nested loop. But I'm just trying to think through that. I'm just trying to think through, like, what is the logic here? Well, the first thing we wanna do is check every feasible space we can move into.\u003C/p>\n\u003Cp>That's the way we're gonna do it. So feasible directions. I remember encoding Valdez to do stuff like that, and then we had to remember what it meant. Possible next steps. And we actually don't wanna do this inside of this loop of every snake.\u003C/p>\n\u003Cp>We wanna do this just for us. So possible next steps are, is I don't know that because that's gonna be possible next steps is an array is an array. Cool. And we're gonna push into this array everything up, down, left, or right of us. Yeah.\u003C/p>\n\u003Cp>Then we're gonna remove our body piece, our neck. We're gonna remove our neck. Yeah. Okay. Cause we don't want our neck in there.\u003C/p>\n\u003Cp>So that, that will release 3 directions. And then for every snake, we're gonna repeat that logic. We're basically gonna say if any of these match, you remove it. So when we store them in here, we also have to store whether it's up, down, left, or right.\u003C/p>\n\u003Cp>Andrew: K. Alright. Let's see. You have a plan, and I'm very curious to see how this\u003C/p>\n\u003Cp>Kevin: will be implemented. First thing we wanna do basically is say up, down, left, or right. What is the coordinate? So what are the coordinates of that? So we're gonna say, in fact, I I think this might be easier.\u003C/p>\n\u003Cp>So we're gonna go possible next steps dot push. We'll we'll start with left. No. Left is going to be x is, come on, Kevin, you can do this. X is going to be our current X position.\u003C/p>\n\u003Cp>So this is going to be I don't just want my head. I want I want you. So I'm gonna save this. We'll come back here. I don't think we have you.\u003C/p>\n\u003Cp>No. No. We have my hand, which is great. Let's just throw you in there. Then we'll come to avoid head to head and what just while I'm here.\u003C/p>\n\u003Cp>And return move. Right. Return head to head. So now we have access to you in here. So we want Datastock Global's my head, you, and my head.\u003C/p>\n\u003Cp>Cool. So that's gonna be you dot, why why did I do you? We just care about my head. What are you doing, Kevin?\u003C/p>\n\u003Cp>Andrew: Yo. Because you wanted to remove the neck. You were this\u003C/p>\n\u003Cp>Kevin: Yeah. But not oh, yes. I suppose that will be that will become important, but the neck comes later. Yes. So we just wanna say my head dot x minus 1 and y equals my head dot y y.\u003C/p>\n\u003Cp>That's left. Bright. So that's the the same. Up. And so that's gonna be x remains the same, but y this time, r is minus 1 and down, plus 1.\u003C/p>\n\u003Cp>No. It starts the other way around. Down because bottom left is 0. Up. So that's pushing in push in all I mean, it's it's pretty obvious actually by the, by by the name of what's going on.\u003C/p>\n\u003Cp>Then we wanna remove our neck from that. Then there'll only be 3 items in the array. So we'll go possible next steps. How do I do this? Equals poss that becomes a let.\u003C/p>\n\u003Cp>Possible next step, stop filter. Possible next steps. So steps, where the step is not equal to you. You dot what is the it's a bit disruptive, but I'm gonna just what is the what's it called? U.body.body.\u003C/p>\n\u003Cp>Andrew: I love that my my many, many if statements, my heuristic was not okay, but there's this will be so much cleaner though when it's done. I will agree with you there.\u003C/p>\n\u003Cp>Kevin: Thank you. So this is remove net. I think that's what that does. So every item where that because all the body parts are is this. It's an x and y.\u003C/p>\n\u003Cp>Right?\u003C/p>\n\u003Cp>Andrew: Yep. Yep.\u003C/p>\n\u003Cp>Kevin: I I'm a little bit I think I think object, object comparison is a little bit hunky. So what I'm gonna do just to be on the safe side here is say, where s dot where s dot x is not equal to x and where it's not equal to y. So if both those things, no or no and hang on. This is this is important. I'm gonna do it the other way around.\u003C/p>\n\u003Cp>So where they are equal to x and they are equal to y, that means, hey, this item matches or wrap the whole thing in another bracket and we will negate it. Okay. That should be removing. Does that make sense?\u003C/p>\n\u003Cp>Andrew: I'm so glad we have a video because that's super unreadable, but I get the logic makes sense. No. No. No. Not not unreadable.\u003C/p>\n\u003Cp>Unreadable. I mean, like, I feel like if somebody looked at this, they would be like, what is happening in this line?\u003C/p>\n\u003Cp>Kevin: So, I mean, I mean, we're removing the yeah. Yeah. Right. Okay. Sure.\u003C/p>\n\u003Cp>Yeah. So Who needs to\u003C/p>\n\u003Cp>Andrew: read this code except for us?\u003C/p>\n\u003Cp>Kevin: Exactly. No. This makes sense. Okay.\u003C/p>\n\u003Cp>Andrew: Yeah. I\u003C/p>\n\u003Cp>Kevin: think that works. So we removed the neck. So that's removing that's saying all of our possible neck positions. Now we wanna basically figure out all of the every other snake's possible next steps. And if there's any matching item oh, there's a there's a silly, silly little thing going on here, which is we're gonna push in.\u003C/p>\n\u003Cp>I'm gonna just call the variable c to mean coordinates and that and this is where it all starts falling apart in terms of, like, clarity. And I am gonna I am I I've decided I am gonna be more explicit here.\u003C/p>\n\u003Cp>Andrew: No. I think it was\u003C/p>\n\u003Cp>Kevin: I mean, I\u003C/p>\n\u003Cp>Andrew: think it's I think it's very clean code before, but, yeah, I think that this makes a little bit more sense.\u003C/p>\n\u003Cp>Kevin: Yeah. So we have the cohorts. And the reason this matters, It's because we don't just want to store the coordinates. We also wanna store the actual reference to which direction it is. So as well as the quotes, we are gonna say direction left, and we can get rid of that.\u003C/p>\n\u003Cp>We can get rid of that. So direction left, direction right, direction down and direction up. Right? So now we just have to change this bit here because it's not s dot x anymore. It's s dot quartz x and that's dot quartz y.\u003C/p>\n\u003Cp>But it will when it removes it, will physically the directions will no longer and then at the end, we're gonna just return the those directions. So I think that that's an important thing. So we can actually ultimately at the end change is move safe and know what values we are we are removing. Yeah. Because before, there's no how do we know which one's which other than the order we initially push them in?\u003C/p>\n\u003Cp>Andrew: Mhmm. Not a\u003C/p>\n\u003Cp>Kevin: nice. The next thing we want to do is go around every snake, and we wanna basically do this same game here where we go left, right, up, down, push it into an array, cross reference them. If any of them are the same, we know the direction in which they match. Oh, that That's funny. Off reactions gone.\u003C/p>\n\u003Cp>Are you familiar with these?\u003C/p>\n\u003Cp>Andrew: I am, but you're in Arc. Right? Is that where\u003C/p>\n\u003Cp>Kevin: it actually is?\u003C/p>\n\u003Cp>Andrew: Or is it within Riverside?\u003C/p>\n\u003Cp>Kevin: No. It's it's macOS.\u003C/p>\n\u003Cp>Andrew: Oh, it's in Mac. Really? No way.\u003C/p>\n\u003Cp>Kevin: Yeah. But I don't Well,\u003C/p>\n\u003Cp>Andrew: I'm not I'm on Windows. Windows is like, no. We don't we don't think these are things that we need.\u003C/p>\n\u003Cp>Kevin: That is so funny. So now we now we wanna do the same thing for this snake. And this is this is the important thing is that for every snake, we are literally gonna do this exact same logic, except we're not gonna remove the neck. We're just gonna say, oh,\u003C/p>\n\u003Cp>Andrew: are we gonna remove the neck? No. No. We'll just remove the head.\u003C/p>\n\u003Cp>Kevin: No. No. No. No. Because if we you know, because if we're colliding into the neck, we're colliding like that would have been handed by the dome.\u003C/p>\n\u003Cp>Yep. Yeah.\u003C/p>\n\u003Cp>Andrew: Exactly. Yeah. So it's just the head. Exactly. Exactly.\u003C/p>\n\u003Cp>Kevin: So we just care about this logic. So possible next steps. And I am just gonna just shrink this down slightly because it'll be contextually clear what's going on here. So it's no longer my head. It's no longer my head.\u003C/p>\n\u003Cp>It's head. Head. Okay. And so that's so that's that. We're doing that for every single snake.\u003C/p>\n\u003Cp>And now this is the important thing we are going to compare. Yeah. We are going to compare. Let's just have a think about this. We actually don't care about the directions this time.\u003C/p>\n\u003Cp>The directions are irrelevant. I think, I think we'll leave them in for the sake of having the same data structure. So we know exactly what we're doing, but this bit's irrelevant. We just yeah. It's it's irrelevant.\u003C/p>\n\u003Cp>So this n is going to go before it's just one big array of every snake. We don't need to have it on a per per snake basis. So this is us populating and with every viable direction that could ever be in. Actually, I've had a change of heart. We are we are gonna Sure.\u003C/p>\n\u003Cp>That down.\u003C/p>\n\u003Cp>Andrew: And then we're just gonna be comparing our end versus our possible next steps. Hence, look, we're\u003C/p>\n\u003Cp>Kevin: just gonna be You absolutely you absolutely got it.\u003C/p>\n\u003Cp>Andrew: I like it. Okay. This is cleaner than I thought. I was definitely you were, I get where your head is at with removing some of this stuff now. I love it.\u003C/p>\n\u003Cp>It took it took you getting to the end of this for me to be like, yeah. I I this makes sense. Good. Good. Good.\u003C/p>\n\u003Cp>Thank you very much. Thank you, Ro. Smart code. Very much.\u003C/p>\n\u003Cp>Kevin: So now what we're gonna do is compare every single value in n. So we're so what we're gonna do now is and yeah. Yeah. Perfect. So we'll we'll loop now.\u003C/p>\n\u003Cp>So it's a for let n of, can't do n.\u003C/p>\n\u003Cp>Andrew: Yeah. If you just change n to to next moves or something like that or or yeah. Yeah. There you go.\u003C/p>\n\u003Cp>Kevin: Sure. Oh, I see. So for so next, I'd rather that's fine. For Yep. So I can use the shorter version inside the list.\u003C/p>\n\u003Cp>I'm about to use it, I think, a reasonable amount. So for every single value in there, is it one of those? It's all we care about. Let's have a think let's have a quick think about how we're gonna achieve that. Okay.\u003C/p>\n\u003Cp>So for every single one, we're gonna say, does next possible Does value in one array appear in another?\u003C/p>\n\u003Cp>Andrew: Hey. There we go. Nice little vanilla JavaScript there.\u003C/p>\n\u003Cp>Kevin: Absolutely. Include some and include. Some text element against the test function that return. Yeah. It's great.\u003C/p>\n\u003Cp>Cool. I don't think this is, oh, but it's that's no. It's that same thing again with objects. So I think the object nature of it, like, object comparisons are are specific. Yeah.\u003C/p>\n\u003Cp>It's a find and a size I think this is actually flipped.\u003C/p>\n\u003Cp>Andrew: What are the responses? Did they say it actually works?\u003C/p>\n\u003Cp>Kevin: I think so. That's a bit of a it's a bit of a big big example. Got it. Got it. Lovely.\u003C/p>\n\u003Cp>That's the answer. So I'm gonna just I'm gonna just pop it here and comment it out so we just have a little reference at the point where we're writing it. So this is an array. Let's consider this as our possible next steps. Yeah.\u003C/p>\n\u003Cp>So we wanna say, for, matches r.sum. It's not called r, is it? It's called next possible steps. Possible\u003C/p>\n\u003Cp>Andrew: next steps. Possible next steps.\u003C/p>\n\u003Cp>Kevin: Possible. I'll fix that in a moment. So sorry. The sum method of an array test whether at least one element in the array passes the test implemented. Okay.\u003C/p>\n\u003Cp>So next possible did I make a typo?\u003C/p>\n\u003Cp>Andrew: Yep. Possible next steps, not next possible steps.\u003C/p>\n\u003Cp>Kevin: Just Thank you.\u003C/p>\n\u003Cp>Andrew: It's what I'm here for\u003C/p>\n\u003Cp>Kevin: Possible next steps. And it immediately changes color to be like, yeah, you can spell now. Thanks. Possible next steps dot sum item. We'll do that again, and it's item dotcoords dotcoords.\u003C/p>\n\u003Cp>Dotxmatchn dotx. Dotxanditem.coords.y. For n of next. Is this is this how is this really I I think I I think there's some redundancy in here, actually. Yeah.\u003C/p>\n\u003Cp>What? Yeah. This is all we're this is this is trying to, like but we're already in a loop. We're already in a loop. So all we wanna know was, I've got it.\u003C/p>\n\u003Cp>Matching collision. Collision. Is that how you spell it? Collision Yep. Equals possible I got it.\u003C/p>\n\u003Cp>I got it. I got it. I got it. Next steps dot find and because we just wanna find does does one match. Right?\u003C/p>\n\u003Cp>And what we wanna know is step in there, is there a value where the cohorts dot x are the same as n.xandstep.cowards.y equals m.y. If this returns a value\u003C/p>\n\u003Cp>Andrew: It works.\u003C/p>\n\u003Cp>Kevin: Then that yeah. Then that collision it's gonna be a little bit of a long winded one to test because also we're gonna have to go we're gonna have to go back through the logs. This one's gonna actually be really painful to test because in theory, if it works, you know, but, so what this will return is a possible next step. And so what we will then do is if this this will have the value of possible next step in it. Mhmm.\u003C/p>\n\u003Cp>If it matches, so what we will then do is say if collision, because it will be 4 to undefined, like, some faulty value if if there's nothing returned in there, then possible just get myself a few characters because I think I'm gonna go quite far to the right here. Possible next steps equals possible next steps dot filter, and we wanna remove this item. And it's this. It's this logic right here that we already wrote, but slightly different. So we wanna say we're s.coawards.x, where collision by collision.cohorts.x.\u003C/p>\n\u003Cp>Oops. This one here, where it is the same as collision collision. Am I spelling it right? I I swear I swear I swear I\u003C/p>\n\u003Cp>Andrew: That's right. No. You're good. You're good.\u003C/p>\n\u003Cp>Kevin: I'm literally just like, you know, when words start to look wrong.\u003C/p>\n\u003Cp>Andrew: Yep. No. But it's catching it. It's catching it, turning it purple if you're right.\u003C/p>\n\u003Cp>Kevin: And this is the same as collision dotcoorg.y. Okay. I think I think this is\u003C/p>\n\u003Cp>Andrew: it.\u003C/p>\n\u003Cp>Kevin: Then oh, no. There's one more step. So now possible net, possible next steps is a shortened array which has just items which are viable. Yep. Just items which are viable.\u003C/p>\n\u003Cp>Let's just have a think because we we don't wanna\u003C/p>\n\u003Cp>Andrew: What is that actually gonna look like, though? Do we know right now?\u003C/p>\n\u003Cp>Kevin: It it will be an array of objects that look like this.\u003C/p>\n\u003Cp>Andrew: Is it just gonna be a same case?\u003C/p>\n\u003Cp>Kevin: Yeah. Yeah. But just a shortened a shortened list. Yeah. Now what we actually wanna do now I think about it is we kind of want the others, which I've just realized we want we want the other items.\u003C/p>\n\u003Cp>We want the ones that are being removed. So Oh, to So removed from his move. Yes. Yes. Yes.\u003C/p>\n\u003Cp>Yes. So let make false. This is we're starting to get a little hunky now in terms of, like, code quality, but, like, it's fine. So if collision we don't wanna screw around with possible next steps. We don't care about that.\u003C/p>\n\u003Cp>All we're gonna do is add collision dot direction to make force, and we're not even gonna do that. We are gonna just straight up say is move safe dot left, and the value of left will be in collision dot the equals false. And that's the direct we are making the the value that we came in with. Yeah. We're setting it to false because we're gonna collide.\u003C/p>\n\u003Cp>And I'm not sure if this is valid, syntax.\u003C/p>\n\u003Cp>Andrew: I will find out.\u003C/p>\n\u003Cp>Kevin: We will find out. I might I might just save ourselves some effort here. Commission dot the okay. Alright. Sorry for bringing oh, don't don't play this game.\u003C/p>\n\u003Cp>I, I'm sorry. I felt like that wasn't an overly, like, collaborative exercise, and I'm sorry.\u003C/p>\n\u003Cp>Andrew: That was it was wonderfully collab I don't know what you're talking about. See, my favorite collaborative experiences are the ones where I can nod along and say yes, And I can I can help pick out when you've misspelled something? That's, I feel like I've I've contributed in my own YouTube. I don't\u003C/p>\n\u003Cp>Kevin: know don't know what that little error is at times. Anyway\u003C/p>\n\u003Cp>Andrew: It's weird.\u003C/p>\n\u003Cp>Kevin: Let's and this one is gonna be a little bit of a hard one to to test. So we're gonna just have to watch watch this carefully. The snake's going up the whole time.\u003C/p>\n\u003Cp>Andrew: Okay. So there's a bug somewhere.\u003C/p>\n\u003Cp>Kevin: There's a bug somewhere, but we will be able to See debug it. Oh, it all died here. Un un there's a problem in the setup of the globals. There's a comma.\u003C/p>\n\u003Cp>Andrew: Change in here.\u003C/p>\n\u003Cp>Kevin: Comma.\u003C/p>\n\u003Cp>Andrew: Comma. Those commas.\u003C/p>\n\u003Cp>Kevin: It's always the commas.\u003C/p>\n\u003Cp>Andrew: Grammar's out to you.\u003C/p>\n\u003Cp>Kevin: I'm loving I'm loving now that we don't have to touch the code editor at all.\u003C/p>\n\u003Cp>Andrew: Yeah. Agreed.\u003C/p>\n\u003Cp>Kevin: Okay. See. So where K. Avoid head to head. Fine.\u003C/p>\n\u003Cp>Unexpected token line 8. Great. Okay. 8. There is an extra bracket here and an extra bracket.\u003C/p>\n\u003Cp>No. No. No. The one at the end is the one at the end is correct. There's an extra bracket here too.\u003C/p>\n\u003Cp>Great. Let's see if that does it. Yeah. I I literally cannot believe we're okay. I was gonna say we're getting it to work.\u003C/p>\n\u003Cp>Andrew: We're getting things are happening. We're debugging, and that's the important thing.\u003C/p>\n\u003Cp>Kevin: Alright. Snakes is not defined. Okay. Not a problem.\u003C/p>\n\u003Cp>Andrew: What's the I mean,\u003C/p>\n\u003Cp>Kevin: this is good. Oh, snakes. Fine. It's all really small, like, little errors, quite well defined, quite quick to fix, allegedly. Alright.\u003C/p>\n\u003Cp>Alright. Alright. I need everyone to know at the time of recording, it is 11:30 at night. Snakes dot shift is not a function or its return valuable value is not iterable. Right.\u003C/p>\n\u003Cp>That's that's fair. And that is here, snake dot shift. So what we're gonna do is just it really doesn't matter. Like, snake star shift, and I I'm assuming it that's how it like, it needs to happen on its own line first.\u003C/p>\n\u003Cp>Andrew: Kevin, if this is what you programming at 11:30 at night does, I don't wanna see you programming when you're fully rested and awake.\u003C/p>\n\u003Cp>Kevin: Well, here's here's the joke. I'm I'm never fully rested. I mean, children. Children. Yeah.\u003C/p>\n\u003Cp>Fair enough. Well, it's going it's going up, but I also didn't set that up correctly. But let's let's keep having a look at the logs. S is not iterable. Okay.\u003C/p>\n\u003Cp>I think I've misunderstood how shift works. 1st element. Oh, it returns the first element. I don't want that. I I want to return them.\u003C/p>\n\u003Cp>Right. Right. Right. It returns just the element. It pops out of the top, but I want everything else.\u003C/p>\n\u003Cp>Andrew: Oh, everything but. Yeah. So what's the option of the shift?\u003C/p>\n\u003Cp>Kevin: It is to do the head, avoid head to head. So it is to do the work. So it's to do the shift snake stop shift, and then I think it might actually be to put snakes back in there. Yep. But I'm not sure if snakes is re I'm not sure if that will work.\u003C/p>\n\u003Cp>I think it will. Okay. I think it's not doing that anymore. This is obviously not the test, the,\u003C/p>\n\u003Cp>Andrew: we need to But we're not we're we've got no actual errors in the code that we've well, that we I use we very liberally. The code that has been produced in that final card is working and it's definitely a little bit slower now. So I think that we're definitely getting a, there's a lot more compute going into this, which totally makes sense.\u003C/p>\n\u003Cp>Kevin: Yes. Okay. We're we're still going. Woah. That was a okay.\u003C/p>\n\u003Cp>Okay. It did end up giving up. Why? Oh, because there was no viable choice. Yep.\u003C/p>\n\u003Cp>So that's Which is yeah.\u003C/p>\n\u003Cp>Andrew: Wow. Hey. We wanna move fast oh, sorry.\u003C/p>\n\u003Cp>Kevin: What do you mean?\u003C/p>\n\u003Cp>Andrew: I was gonna say if we wanna move faster for the head to heads, put multiple snakes in more than just one.\u003C/p>\n\u003Cp>Kevin: Okay. I I think we I think we got a snake.\u003C/p>\n\u003Cp>Andrew: I think we did too. I think it's working.\u003C/p>\n\u003Cp>Kevin: I'll stick 2 hungry bots in that There we go. Cough.\u003C/p>\n\u003Cp>Andrew: That should do it.\u003C/p>\n\u003Cp>Kevin: Should have hit start game first, so it did its job. Okay. Head to heads are obviously gonna be hard to to start.\u003C/p>\n\u003Cp>Andrew: Yeah. But we can\u003C/p>\n\u003Cp>Kevin: kind of see we can kind of see here when it ends it ended. Okay. So now we can watch the whole thing.\u003C/p>\n\u003Cp>Andrew: Yep. So he's not what's he turn why is he turning? Was there a safe move there?\u003C/p>\n\u003Cp>Kevin: There was a safe move. How do I go back? Pause back. No. There wasn't.\u003C/p>\n\u003Cp>Andrew: Nope. There wasn't.\u003C/p>\n\u003Cp>Kevin: It got itself into a corner. Fine. I'm confident I mean, I'm not confident enough. I do that were there any head to head opportunities? And I didn't see one, did you?\u003C/p>\n\u003Cp>Andrew: Nope. No. But I think I think we're not getting any errors at that final stage, and I think that's a good sign that the logic in there makes sense.\u003C/p>\n\u003Cp>Kevin: You yeah. Yeah. But it might not be doing what we want. So what other few do you think 11 by 11 is still a good size, or maybe I should make it small?\u003C/p>\n\u003Cp>Andrew: Make it small, and then we can see faster. And, yeah, give that a try. Yeah. Yeah. There we go.\u003C/p>\n\u003Cp>Yeah. Run that and see what happens.\u003C/p>\n\u003Cp>Kevin: Oh, it's it it went on for a reasonable length of time.\u003C/p>\n\u003Cp>Andrew: K. So there looks like\u003C/p>\n\u003Cp>Kevin: No. Our snake didn't didn't need to didn't have a head to head moment. Well, I mean, it avoided a potential head to head moment there, but But it's I'm happy I'm happy in no. Yeah. Because we'll never know, will we?\u003C/p>\n\u003Cp>Yeah. We'll never know.\u003C/p>\n\u003Cp>Andrew: We'll know if we play enough games over a long enough period of time, but I think the code is there.\u003C/p>\n\u003Cp>Kevin: And we would know it doesn't work if there is a head to head, but they don't happen often enough. Hey. We leveled up our snake.\u003C/p>\n\u003Cp>Andrew: That's solid. So not only move it to a different platform where it's running, same logic, and then adding that extra step and super visual. Super visual. I'm very I'm very,\u003C/p>\n\u003Cp>Kevin: very satisfied. I'm very satisfied by it that working. Awesome. I think that brings us to time. I mean, we we have to be at time at this time.\u003C/p>\n\u003Cp>You gotta go to sleep. I've got yeah. My kids will be up in 5 minutes. So, awesome. Thank you for for for for doing this again.\u003C/p>\n\u003Cp>Andrew: Yeah. Thanks for joining us, everybody. I feel like I'm glad that you were driving this time because had I been driving, this would have not gone as smoothly in any way, shape, or form. So I feel like this was gonna be\u003C/p>\n\u003Cp>Kevin: be silly.\u003C/p>\n\u003Cp>Andrew: But I I am excited to eventually drive when we, again, in episode 3 or 4 when we start to implement some other technology. So do we know what we're doing on our next episode yet, or is it all\u003C/p>\n\u003Cp>Kevin: In our next episode, we're gonna stay in Directus, and we're not gonna be leveling up our snake. But given that Directus is backed by a database, we're gonna start actually storing data about games and then seeing what we might be able to learn with Directus Insights.\u003C/p>\n\u003Cp>Andrew: I love it. I love it. That's gonna be an awesome next episode. So, we've got a snake. You've seen how it works.\u003C/p>\n\u003Cp>That's all of the steps for the starter snake that are worked out in there. It's actually just a functional JavaScript snake. You could pull all of that logic out. Well, most of that logic out and just put it into a JavaScript Express server and just go to town. But, but we've got it working in here.\u003C/p>\n\u003Cp>And so now let's do a little bit more. Let's see how powerful you can make Directus with Battlesync data. I'm very excited.\u003C/p>\n\u003Cp>Kevin: Yeah. This is awesome. So until next time, this has been ready, set, battles, stake.\u003C/p>\n\u003Cp>Andrew: We're getting better. We're getting better.\u003C/p>\n\u003Cp>Kevin: Some some would say. Some would say. Till next time, folks. Bye, buddy.\u003C/p>","Hello, and welcome back to we've got a catchphrase, Andrew. Are you ready? Ready, set, That's easy. We got 4 more We got 4 episodes. Exactly. We're we're we're we're cutting our losses for this one. In this show, we are continuing to build a Battlesnake, and progressively enhancing it, using Directus and Devcycle. My name is Kevin. I work at Directus, which we'll be using a little bit today. And My name's Andrew, and I work at Devcycle, which we'll be using in a future episode. And this is Battlesnake. Yeah. Give us the give us the 92nd for people just dropping in now. What is Battlesnake? Alright. Battlesnake is the way you wish that you had learned how to, program in a new framework or language from the very beginning. And now as a senior developer, Imagine you were playing the old classic snake game where you go around a board trying to eat food and survive. Now transform that into a programming game where you have a web server that's communicating with the Battlesnake game engine to communicate through code and tell your snake whether to go up, down, left, or right, and to try and survive as long as possible. Yeah. And we do that by implementing a web server, which implements the Battlesnake API. We've already had one episode of Ready, Set, Battlesnake. So we're not going to recap everything we did. If you are still a little fuzzy on how this works, it will probably become clear. But if you're completely fresh and you're like, I'm lost, go watch the first episode and watch a struggle through building the Node. Js starter snake. But today, we're gonna further build on top of that snake. Last episode, we built a battle snake based on the Node. Js starter, and we implemented here we are. And we implemented some logic. That logic, what what did the logic do? The logic stop listening dying by going hitting into walls. That's good. Then we got the snake to not hit itself or any other snake parts, because that also is instant kill. So that's all our snake does. Right? Yeah. Yeah. That's all our snake does. And we're probably not gonna make our snake much more clever today, but we are now going to introduce a new tool into the stack and get it out of Replit and into another environment. Anything else you think that's important, Andrew? So the great thing is you can follow along with kind of all of the base code for all of this over on the GitHub repositories that exist around. Snake. So if you're watching this and you're like, I want to do it in my own language or framework, you can go and check out all the awesome Angular projects that are over there. So actually, let's take pause for a moment because this is important. What is a Battlesnake? So you have to implement a web server that has a few specific route handlers. The a few specific endpoints. Firstly, this just route route. Right? And all this one does is it returns information about the snake, metadata about the snake. And we'll play around with that a little bit more today. The mode then we have the start endpoint, which, Andrew, I think that's the before the first move in any game. Right? So we got our start end point, which is great. We've got our root end point. What is the kind of most important endpoint of all the endpoints though, Kevin? It is this move endpoint. As we discovered last time, the move endpoint, every single turn of every single game will receive a request with the state of that game and the board, which includes every other snake, all the hazards, all the food. You have 500 milliseconds to respond with a string up, down, left, or right. And that is this is the most important endpoint. But you there is also an end endpoint, which is what you would potentially use to, like, wind down any resources or, you know, do any analytics storage, you know, and you just do it at the end. So we have these 4 endpoints that we need to implement. Move is is kind of the most critical. I think only move in the the root are required for any given snake. So that's worth noting because that's gonna be important. So what we're gonna do today, we are going to be building this snake inside of Directus. If you've not heard of Directus before, I hope you have because you're watching this on Directus TV. But Directus is is a back end toolkit to build applications. It has 2 parts. One part which is all around API generation from your database and asset storage, and the other side, which is a web application to kind of work with that data. There's a whole bunch of other stuff in there. So we're gonna be implementing a Battlesnake inside of a director's project. So we'll we'll we'll kinda see how this shakes out over the next over the next little while. Now originally, until about 5 minutes before we started recording, I thought that we would perhaps use, Directus' automation UI tool in order to build our snake because it is it feels quite viable on the surface. It does. And then I realized it ain't it ain't viable. And the reason it isn't is because one of the triggers that can begin a flow is a webhook, an inbound webhook, but it is unique, and randomly generated at the time the flow is created, which means we can't implement a root endpoint and then slash move, slash start, slash end. And that's gonna be a challenge. So rather than just trying to to power on through that, rather than sorry, rather than just trying to power on through that, we instead are gonna build an extension. Flows is effectively a UI layer or a UI version of, hooks of hooks. So, you know, we can we can do it in code. We also have endpoints, which is probably more suited for this where we can literally create complete endpoints, and this is a no doubt. So we'd probably lift and drop a lot of our logic. This might end up being a bit of a lighter episode, but there would be nothing wrong with that. But I've done the thing. I've jinxed it. You have. I did it last time, though. So in fairness, we're we're each one in, and and so I feel like Indeed. This is way to do it. Indeed. And so we're also we're gonna be implementing some some, like, very like, this whole rate limiting thing has caused us to have to think about a lot of other technologies as well too. Right? So it's not just this concept of of sort of how we're gonna implement Directus. It's also You're right. How it's gonna be able to interact with with the Battlesync platform. Right? Yes. So here here's the plan. Here's what I think the game plan is. We're gonna spin up, direct us locally using Docker. And that is an environment in which we can build extensions. And we could then just deploy it somewhere and be happy days, you know, deploy it on some some web service, or we could just, like, open up a tunnel to our local machine. And ngrok is kind of the tool that we've as as developer educator types have have historically jumped to, so I think it will be the tool we use today. I also found out today I'm apparently still paying for it on a grandfathered plan that gives us the pro features. So, you know, I think it's one I might wanna Let's do it. Get off the card, but I'll use it today. I saw a I saw a really great, idea from someone recently just to, like, automatically, not only list all of the subscriptions that you have, but actually unsubscribe you from something if you haven't accessed it in a while. And I was like, that's a brilliant idea because I have so many things to subscribe for that I'd like to remove my credit card from. Yes. But I'm happy in this moment in this moment that it's working. Now one thing that's really nice here is the extension entry point. If we look at this, example, the way it's built is you give an endpoint an ID, which becomes the kind of root path. So this would be like our director's project slash greet, and then you can create the root, the slash move, the slash start, the slash end, and so on. So this part should be pretty straightforward. Let's let's see, and if the docs end up being misleading, that's literally my job. So it's it will be incredibly self inflicted. So we'll we'll see. So we're gonna start by following the Docker guide for getting started with directors. No. We're not. We're gonna look at the self hosted quick stuff, which which is super smooth. It is a very smooth Docker process, I will say. Like, setting it for the first time, it was it was chef's kiss. I like it, and it's pretty, we we kinda sometimes refer to it. I mean, we will use different words, but I call it like full fat. This is the full thing. There's directors cloud, which is like, you know, a a managed platform. But this if you self host it, it's full fat, which is really nice. So I already have Docker running in the background and I already have a code editor here, completely completely blank code editor and a new directory, which I've opened up. So I think we're just gonna we're just gonna crack on straightaway in here. So first thing we need to do is create a Docker Compose file. It's a Docker dash compose dot YML file that describes all of the settings that we have with directors. We may need to fiddle with this later, But for now, docker compose dot yml. And let's make my font size significantly bigger. There we go. We can copy and paste the value in here. Keys and secrets are meant to be random values. They're used for, identifying, your account in, like, a horizontally scaled setup and the secret is used for JWT validation, and we don't care about that right now. So we're just gonna leave those. Hunter 2 is when I set up projects my default. So we're gonna Good to know. Good to know. Good to know. Good to know. I'm searching around for past Kevin projects and just trying to break in. Absolutely not. And no. No. That will that will not be good. We're gonna use, yeah. Sorry. Go on. No. I was gonna say an interesting note here is I discovered with the self hosted version, you can't use a fake email address. You can't use dot test. It won't actually accept it as an email address in the platform. Yeah. Interesting. Interesting. I was when I was building out that railway sort of like starter kit for it, I was trying to just set it up with a test and it would not it wouldn't go. You had to put it in an actual address. Interesting. As in, like, it follows the structure of an email address, but it isn't real because it should do. That should be fine. I think it was because it was a dot test, t, like, t Yeah. But that that's they're legit characters in an email address. So anyway anyway. Things that's important yeah. One thing that's important to know about directors is it doesn't provide a database. It connects to an existing database. We're gonna use this lightweight file based database called SQLite. We're gonna point it at the file. And on first run, it will create the file for us. That isn't Directus, that's a SQL like database that Directus connects to. So just a little bit of important distinction there. 10.8.3 is the latest version at the time of recording. By the time of publishing, that will not be the case. I think we might be on 10.9 by now. That's pretty exciting. Yeah. All good Database persistence, file persistence, extension persistence. WebSockets are enabled even though I'm not sure we're gonna use them. And instead of, continuing to talk through every line in excruciating detail, I think we can just write Docker Compose up. It should kick off. Great. It's attaching. Boom. Boom. Boom. Doing a bunch of stuff first time and running now on local host 8055. So if I hit local host 8055, brand new directors project with randomly auto filled credentials, which are not I think I have to move them out of, yeah, manage passwords, but that's not for today. I bet you that was a hunt to 2 password too. But this is a blank director's project ready to go. So that was that was great. What else is important here? If I open up oh, I haven't opened up the folder. This is annoying because obviously the terminals attached to it. So let's just, let's just stop that running. Let's open this snake folder here. I think I might have been able to add folder to workplace. We're here now. Let's just run Docker compose up again. Great. And just refresh that and everything should still be fine and dandy as it is. Now the first time we ran that, it created some directories here on the side, which I think are gonna be quite small right now on people's screens. But as a database directory with our SQL like database and extensions directory and then uploads directory. Grand. So we have this direct as project and it's great that we, you know, can go in and create, you know, collections in our database and upload files and create dashboards and all of that stuff. But really, all we care about is implementing these endpoints from our Replit and bringing them over. So let's go back to the docs. Let's talk about building extensions and get that get that game get that game underway. Directus has a whole bunch of extensions. Some of them affect the UI that that web app that we just had open. Some of them are API side like custom endpoints and hooks. Yeah. As it says here, hooks are similar to flows, but they do not have the UI, which is in the director's data studio. I think to create an extension, we're gonna go I'm sounding a little uncertain. I don't know why. Like No. I love it. It makes me feel much better about about episode 1, now that you're feeling unconfident about the thing that you deal with every day. I feel like imposter syndrome is real, but at least you haven't had to Google how to make a JavaScript loop yet. So Oh, good. The episode is young. Run so I'm gonna run this MPX create directors extension. I'll pick an endpoint, pick a name, directus dash extension dash, snake. Snake. Snake. I it doesn't it doesn't really matter. We'll use JavaScript. We'll auto install dependencies, and we'll give it a moment to scaffold that extension for. This is a nice CLI. Like, I gotta say, this is a very enjoyable experience. Yeah. There's still work that needs to happen, and it is happening. But, yeah, this boiler plating isn't too bad, actually. I, yeah, I I I quite like it. So inside of our extensions directory, we have this new snake. We have source. We have this index dot JS. Grand. Now what we want and so this, I think I think this might be available, I think, at directus dash extension dashnet like slash. It's a little bit clunky, but we're not going to use this format. It doesn't really matter. We're going to use this. We looked at it earlier, this alternate format, where we can do all of the subroutes straight in here. So I think I think I can just copy and paste this. Kevin, is this just is this just vanilla, or is this React? Like, I this looks very clean, but it doesn't Yeah. So this so the front end of Directus is a view app, but this what you're seeing right now and ding, ding, ding, I think you've just spotted it. Endpoints use oh, directors also uses the express router. So it is very much what we did in the first night, which is why being able to lift and drop it is gonna be gonna be quite nice. It's so clean. I dig it. I love this. This is beautiful. Yeah. Thank you. So we have snake slash snake intro snake goodbye. So let's get this running. So we're gonna c d into our Directus snake directory and we're gonna run npm run build. That's built the extension into a disk directory. And now we need to restart Directus now. I think I think it might be broken, but I think we can get it to I think we might be able to get it to, like, auto, like, load the the changes. What am I looking for? Self hosted config. Okay. So we are looking for extensions, extensions auto reload. Here we go. So Boolean will automatically reload extensions when they have changed. So we're back to our Docker Compose. We'll throw that in and make the value true. Maybe that will work. Maybe that will work. So run Docker compose up again. It's now gonna use this Docker compose file again with this new variable. Let's take a little look through the logs because hopefully yes. It says loaded extension, direct us extension snake. And then the hope is if we run npm run build again, it hopefully would have auto loaded, but that isn't the case. That's fine. That means we're just gonna have a slightly clunky development experience. So I'm gonna have to control C up enter, you know, off the baton. That's fine. I gotta say though, like I remember like outside of this, I feel like we've gotten very spoiled in the development world now. Like, that used to be just the way that you did it. I used to use some. Dragging files with Filezilla or Cybernet. Yes. A 100%. Yeah. Yeah. I that's so I thought that's how you did it. I genuinely thought that that was the only way to do things. No. Yeah. But not here. Like, this this, I'm not quite sure what the deal is. And by the time this is published, maybe this won't be the case anymore. Just for the last couple of versions, if you're running under Docker, I've noticed this environment variable isn't working. Our team's aware that's fine. I just wanna try it on the off chance there. Yeah. Whoops. So if we hit 8055 snake, we get the hello world. If we try snake slash intro, we get the nice to meet you. So these are endpoints that are returning stuff, which means we should now be able to lift and drop our snake pretty expediently. Yep. So what we what are we gonna do here? We have handlers dot info for the root. Yep. So you're gonna grab that. Return that. So I am just gonna make this slightly more verbose so I can space it out nicely. Yeah. So, can you bump up the size a little bit too? A little bit more? Of course. Is that any any better? That's that's much better. Yeah. Lovely. Rez got Jason. Yep. Do you need to return it? I I believe so. Yeah. Cool. Nice. Yeah. I think everything you need to return. Whoops. Got a little too a little too direct there. Let's, let's while we're here, maybe let's do some customization of the snake. That feels good. Yeah. That's good. So head over What color do we wanna make it? Oh, what's the direct is it a direct purple? Is the is the color purple that you're using? It is a purple. And, honestly, my lot are gonna kill me for, like, not remembering it, but I think it's, like, 6 6. I wanna say it's like 6644 f f. I like it. Let's see. We'll find out momentarily whether this is Yes. Yes. That's right. I got it. 6644ff. I logged into my Battlesnake account. We're gonna look at the customizations. And these are the customizations we can have for our snake. Andrew, you you may do the honors from the ones I have. Oh my goodness. So I'm a big, big fan of mustache snake, but I'm pretty sure that there if we scroll down, there may be a rabbit in here now. I thought I thought we had play around seeing if I could get the director's Bunny to look good in one of these, and I had just I couldn't with, like, the it has to be full width on the left. The Bunny, let's take a look. Do we have a Bunny? If not, I know he exists in the backlog. So we may we may be able to get Bunny out at some point here, or he may be locked down. Either way, if not, if we can't get our bunny Oh, I have 200 I have 200 coins as well, so I can unlock any one. Oh, so what do we see? Do we see any that we really like? So we got chicken. I quite got I quite like this dragon head here. I have to be honest. Yeah. Take the dragon. But is it was really funny. No. They're all 200. I don't see a bunny. No bunny. That's disappointing. So let's go for dragon. I feel like that dragon head Well, hang on. Let's let's look at the tails too. Let's let's, you know, maybe not spend all of our coins at once. True. No. I think I think the I think I like the heads. Well, yeah, let let's do the dragon. I've done it. Right. So the head we want is dragon, and the tail is So, I mean, let's go I think cosmic horror's tail is pretty fun. I like that. I like that. Okay. Cosmic Chorus. So that's our that's our snake. And once again, actually, should we get all the logic in? I think we should do this bit by bit. Like, we could now go off and make sure that this works, which is gonna be a whole task in itself. Does that feel okay? Yeah. Yeah. I think let's do that because then once we know it's working, then we can kinda go through. Is that what you're saying? You're thinking, like, let's go in and actually add it to the platform. I am with NVIDIA because we gotta get we gotta get ngrok set up now. Yeah. So do you wanna explain what ngrok is while I get sucked in? Yeah. Yeah. Absolutely. So if you've never used ngrok before, it is a way to publicly expose your local, development environment to the outside world, whoever you would like to be able to access it. So if you often use, say, Gitpod or, Codespaces, there's often the way that you can make that public u that URL from private to public. That's fundamentally what this ngrok, endpoint that it's giving you is doing. But you can do it on a on a, case by case basis. And you can kinda keep it in one place, and you have a bit more control over the power of that and who can see it and all the rest of that stuff. It's our and it's really great, especially if you're, like, say, somebody that's building a site and you wanna see what it looks like on mobile. I think they might still do it. But I know there's some services that I've used that it would automatically generate a QR code from the n grok address so you could just, like, scan with your camera and then view on mobile. Doesn't impact us here, but, really, really good. And ngrok has taken a lot of steps to make things more secure as well. So it used to be that sort of anybody could spin up an ngrok address and there was no issues at all. And they've added a lot more security and ensuring that the things that need to be in place are. Yeah. And I will say around ngrok, if you are, on a local development environment on a Windows device, so a big Windows developer, there's a service called Laragon, which is like, an alternative to like a LAMP stack. And it has ngrok built in. So in there, you can just click share and then it automatically will, like, push that out to ngrok that you could share with people. But, yeah, powerful, powerful service. So there's a little bit of a moment here. I'm not quite I don't quite have the memory of how this works. I think it works like this. I think based on what I've read, So you do ngrok HTTP, the port, which is 8055 and then dash dash domain and then your your domain. No. Reserve this name on your dashboard. You don't need to do that. It'll automatically just generate a random one for you. So just No. Yeah. But I don't want that because I'm gonna have to keep updating it every time it restarts. I think I have I have a static. I have a static. Oh, I see. Like, because I because I'm on this plat this old plan. Right? Yeah. So I wanna work out Yeah. I haven't touched ngrok in in a little while. It's funny, like, it stopped working in that environment. There was, like, they hadn't updated the way that was integrated, and they added an authentication key. And so, it switched things up. So your guess is as good as mine. We're gonna get oh, alright. Here we I mean, yeah. I suppose I could just do the help, right? So start engrop. That's cool. Basic auth. Cool. OAuth 2 cool. Here we are. Use it the same time by using dash dash domain. But, and I thought maybe I, maybe I. What's your domain? I thought it was that. That's why I that's why I paused. So if I look at domains, there it is. Unless I have to do the whole domain. Try the whole domain and see what happens. Because it because it did just say the ngrok.io is only for, like, legacy accounts. Yep. And that was it. Yeah. There you go. Great. So we've now got we've now got engrok rocking and rolling over here. Great. So now what we're gonna do is go over to battles go over to Battlesnake. We'll create a new snake like we did last time. So this is ready, set, battlesnake. Ready, set, battlesnake. Cake. Yes. That's it. Nope. Nope. K for Kevin. That's it. I love it. Beautiful. So https phzn.ngrok. Io/snake. Engine region, Netherlands or Netherlands? Yeah. Well, Europe. So yeah. Sure. Yeah. Programming language, JavaScript, and platform Director. Should be there. Directus. Now my question here is, does the logo look good? Oh, let's see what happened to it. So I used the I got them to add Yeah. It doesn't look too bad. Yeah. It's an old it's an old one. So we'll fix it by the next episode, but it's good. It's just colors just colors and details. But yeah, that's that's our little bunny rabbit boy. Unknown API version. So there was an error. Yep. Even though we copied You should paste it. So what I would say is, I think I think I think I think you might need to just reset. Because this used to happen on Reset reset what bit? Like oh, sorry. Reset everything. So just, like, ping it again. And if it doesn't work, then actually start running, like, restart your direct to server. Okay. This used to happen with replit all the time is it would get this, and then it would just need a couple minutes to start syncing up in the right way. I don't know what that mean. I don't know what that means. No. It's no. That's right. So if I hit that endpoint Yep. Oh, it still says hello world. Oh. Why? Oh, why? Because we needed to rebuild the extension, then we needed to restart director. So there you go. That was our little people. What are you doing? No bill. What what what are you doing? Hit ping. Perfect. There it is. Oh, battle snake. It looks sick. Yeah. I love that. Yeah. So now we have a snake. Right? But we haven't implemented any other endpoints. So this is the time to do it. Now this is the point where maybe, like, we split out the move logic into a separate file to stop it. No. Do you wanna know what? I actually wish that the move logic was in with everything, even in the JavaScript starter snake. I understand why it's not, but I actually think it's way better to have everything in one place just so all of your routes are are there and you're you're able to change that data. So I think I think let's do exactly what we That works for me. So there we there we go. And I am just gonna shrink this slightly and shrink this slightly so we can get the replet up and kind of do a little do a little moving from one to the other. Now can I, can I shrink this sidebar down? Yes. Perfect. And maybe even shrink that. Okay. Rock and roll. Get rid of that. Oh, and get rid of that. There we go. So first thing we're doing is is move safe? So move, get some data in. Let's console log the request just so we can make sure, like, is it in request dot body? I I mean, I'm assuming it's in request dot body. Yep. Let's let's just double check that, and just respond with hello. I like that after our last adventure where we had to disappear and through the magic of editing come back, we've decided to now add console logs earlier as we go so we can save ourselves some trust down the road. That's my style. That's my style. Discum. Okay. Experiential. This is the point where and these these logs are gonna get noisy in a moment. Yep. I may even take them down inside until we need them, and then I can make them smaller still and then I can bump them back up. So what are we gonna do here in Battlesnake? We have a Battlesnake. Let's create a game, create game. Add ready set Battlesnake standard board 11 by 11. And that's good start game. Good. 404, 404, 404, 404. Well, great. So but here's the thing. If you didn't watch episode 1 so here's the interesting thing. Is technically, technically in Battlesnake, you can actually win if you 404 or have a 500 error every single time because you have to set a default move that your snake makes. And I think that there's something, I mean depending on the implementation, I think there's something cool that you could do about actually having a way to change that default. Anyways, but then game's still in progress? Yeah. It's been weird and slow. It's, like, not actually still in progress, but the platform's taking a bit of time to catch up with, I think, what's actually going on. So Why is it 404ing? Root to talk. Kevin. Host. So we'll rebuild that, and we'll restart directors. I was using the wrong method right here. It's a post request to slash move. Okey dokey. So create game, add ready set battlesnake, hit start game. That should be better. There we go. So move gets hit. Oh, so this is it. So the data comes in. Yes. Req dot, req dot body. Fantastic. So now let's move all of this over. I might do a little bit of cleaning up as we go. It'd be interesting. Yeah. Never mind. Let's let's get to it. Let's get to it. Go ahead. I was gonna say it's it'll be interesting if we if we wanna add the start and end point and log what's coming through there. I think there's something interesting in that as well, just to kinda see what that looks like before the logic is implemented. Because it does get really busy once the logic is implemented. At least right now, we're just getting those 404 errors or, like, the basic logs. It's a start. And is it a post request? I think it is. Yep. Yep. Post. We probably should respond. Right? Yeah. And and it'll it'll get angry with us. But And and. Yep. And just because they are gonna get in the way, I'm just gonna pop them down there. Okay. Let me just, cough. Let me mute. Yeah. And so what's interesting here is so I think we we said this earlier, like, the start and end points. You don't really need them for anything, but they're useful if you wanna implement some more serious logic, which we may do sort of with our direct as Battlesink down the road. So you'll see here once we rebuild and then save again, you'll actually be able to kinda see the stuff that comes in Yeah. Through there. So we need the width The height. And the and the height and the Head. Snakes. I think that's all we need. From rec.body.board. Right? Yeah. It's all in this thing called board. Yeah. Great. And the other thing we need is my head, and I am just gonna copy and paste that little convenience there because that's that's wicked. If you by the way, if you really don't wanna have those 2 constant, like, lines that you have there, if you're just, like, really focused on compressing, you can technically pull it from that sneaks variable that you're defining in there. It's just a little bit more more to do it. Absolutely. Yeah. Just can't I mean, because be bothered. Can't be bothered. Right. So so so we've got the we've got the width and the height. So first thing we were doing is don't don't move out of avoid walls, and we're just gonna copy and paste it. Now we're not. First thing we're gonna do is set do the is moves we're gonna do the is moves safe thing. That's the other bit of, boiler plating, I guess. Yeah. And to be honest with you, you don't I mean, so this is like the the default logic. Technically, you can implement logic that doesn't use this, but this is just like the most straightforward way to do it. So Sure. So this is avoid walls. So my head exists. It's movesafe.leftforce. Great. Board height. Interesting. I think we just called that We call it height Height. So we just need to change all of those heads to my head and all of those heights to No. Head to head is correct. My head. Oh, you just got to use my head? Okay. Yeah. But board height. So what we're gonna do here is say height. We'll put bring that in as board height so I don't have to rewrite everything. We'll bring this in as board width. There we go. Job done. I'm also just while we're here, I'm just gonna just gonna we'll make things just a little more little more succinct, perhaps. This is valid. Right? Just so it's 4 lines as opposed to so many so many lines. This is valid JavaScript. Really? Yeah. I hate indenting so much. I would But indentation doesn't matter. So we avoid we avoid the walls. Great. And then it's avoid bodies. And we've already got the snakes. We've already got snakes stored here. So that is the equivalent of that line there. And so we're gonna take this for loop. We will dump that in here. And once again, I'm just gonna take this moment to just, to just clean up a little bit. This time because the conditionals are longer, I probably am inclined to leave them to leave them like this, but just just remove a bunch of, you know, white spacing. And there's some funky indentation going on here. There, boom. There we go. All right. Then if there's any save moves left, the console log and we return move down. Oh, if if there are none left, we go down. I got it. I got it. I got it. So, all the safe moves if no go down. Great. There we go. And it won't be return. It'll be red stop return red stop JSON. And then it won't go further down. Alright. And it will have returned there, so it won't continue. So I don't need to announce or anything. We pick the next move. I am noticing hang on. Hang on. Game state dot turn is not correct. Let's make sure my head piece. Yep. Snakes. Everything there is fine. It's just it's just here. Game state doesn't exist. That's req.body.tan, which means oh, no. Req. Yeah. That's fine. Req.body.tan. And then res.json, then we'll look at safe moves.length, pick the next move. We'll log it. And we will return it. I'm sorry. It isn't a string. It's a it's an object, isn't it, with a move value? It is Next move. So I think I think that is that's it. That's that's a whole efficient, Kevin. That was wonderful. Okay. Thank you very much. Thank you very much. Yeah. I think that is our our snake as implemented last time. Let's rebuild the extension. Let's restart the. Once again, that shouldn't need to be the case, but it is just at this point we're recording, so so be it. And oh, that game in progressing has persisted to be a challenge. It has. So ignore. If I refresh, does it know it's done? No. Okay. So New game. We'll have to keep. New game, and we'll send in, I don't know, loopy bot. Or does loopy bot just do the Just does the loop. Yeah. Yeah. Hungry is good. Hungry is probably a good little test. Hungry is good. He was a good test for us last time. So I feel like we can see how he responds. Okay? Obviously, it's a little more verbose down here. You can reduce the amount of logs with an environment variable. We died that, you know, that's the end state. So, oh, wait. If it won't, can I hit play? Yeah. You can hit play. And sorry. Show the coordinates. Fast, please. Save game. No. Just go back. Just go back. No. Oh, do I just I'll back back back back back. Alright. So r one is the orange is the, oh, we won. So what did it say in the logs that you thought we lost? No. No. We we didn't lose. It ended. I sorry. I said we died, but I meant it ended. What does the what does the actual response say though? I'm not I'm curious. I don't have any idea. It is game ID rule set map stand up source. The oh, it's the it's an n the last 10. Yeah. Yeah. But does it say 1? Let's find out. I feel like it somewhere should say 1. I think no. I think snakes is just one long. Oh, yeah. But it could be you or anyone else, I suppose. Fair enough. It may not say it in there. I'm just curious. Maybe it's the fact you still exist. I mean, let's find out when we die. Do you know? Oh, yeah. If we look at you, it has the ID oh, let me, woah. There we go. I was gonna say I feel I felt like I wasn't seeing it, but I feel like Sorry. That was, that was a keyboard shortcut thing going on. Alright. It has a health. I wonder if the health knows that. I mean, we'll just do it a couple of times, but let's let's watch. Let's watch our our little sneaky there. You do it well. Hey. Like, that logic is good. Okay. Head to head combat, which we haven't built logic for. Maybe we'll do that this time. It's a good idea. I think we because I because I kind of feel like that was what we intended to do this whole episode. Yeah. Congratulations. We're done because we can't build it in flows, and that's the that's the thing here. I have one other I maybe you can execute a flow from Yeah. From this, and then this just becomes the entry point into the flow. That's what I was just gonna say. I was like, is there a way that we could set up the one of the endpoints in here and then have the trigger in flows? You're able to do everything from there? Maybe. That might be fun. I feel like that's an interesting way because I I do think that flows is like this interesting. I've never done it, but, I'm sure it will be fine. So let let's take another look at some new extensions documentation that was recently written. The resources on the not this one. I'm looking for resources, components, packages, extension services. Here we are. So underneath directives, every time you make a request, it's actually going off to one of these services, which then, you know, which then executes your your request. And inside of extensions, you can also access these services. Various services are available within directors, including item service, collection service, file service, and they're available within the extensions context. So there is a router here in the handler, but I think we can also pass in this context. Right? Let me just think about the best way to do this. I think it might be just playing around with this router dot get here. So, so we have this context. I'm gonna bump that back up actually. And if we console dot log, the context and we see just here, we, destructure get schema and services and then we destructure the individual service. So let's let's just do that outside of the individual. Outside of the individual. No. I think for just a moment, we'll do it just inside of this one just because this is the one we're gonna hit. So we don't we don't just have to mess with that. And then instead of doing this, let's just console log the the services and just see what happens. I'm actually gonna do a console dot here, services dex null. And what this will do is effectively a console log that never does this kind of cut off thing. It'll always show you all of the nested layers just because I'm not sure what it looks like and I don't wanna I'd rather just be a little more verbose once. So dotcom. So what we're gonna do here is go back to our root endpoint and hit enter. Oh, sorry. Not root. R snake. There we go. And what happened here? So we have some services. Let's, yeah, let's just expand this for a moment. Webhook service. I, there is a flow. I, I believe a flow service. Oh, nice. Gonna that's gonna wanna be the one that we I mean, is this the one we wanna I don't know. I mean, all we wanna do is hit all we wanna do is hit an endpoint. But Yeah. Let let's go for have a let's have let's have a play. Sorry. Go on. No. I was just gonna say, do we wanna go in? I don't know. Never mind. Let's let's test this out and then and then we'll go forward from there. Sounds good. So let so what you do here is you create a new service with the collection there. So you know what we'll do here. There are some commonly used services. We can just refer to the full list of services directly in the code base here, which is actually what I should have just done. So we have flows here. So we can create flows, create many, update, delete. This actually isn't what we want because this is all about running flows. Sorry. And the the crud of flows. And we don't wanna do that. We just wanna we just wanna run a flow. So maybe the first thing we sorry. Go ahead. No. No. No. Is it just the webhooks that we want, the webhooks service then? No. Because that's to create a webhook. That's not Yeah. Exactly. That's outbound. So so what we'll do here is we'll go to the admin. Oh, wow. We will create a little flow and we'll see if we can trigger that from our code. That's basically the test here that it works. So we create a flow. We'll call this info. Snake info. All of that feels good. Maybe traffic activity in logs. I think that's fine. Then we have the webhook. Webhook. You're right. It will be a get request, response body, data of last operation. Feed all the data just to have it? That that that's happened. So oh, no. So this is the response body. This is what it will respond with. We only want to we wanna create the response and send it. But, actually, what you're describing is it was here. It was this option here, track activity in the box. Alright. There we go. So back to the trigger setup, we'll turn cash off. We don't want it to be asynchronous, get request, save, And we will re- we- it will be the data from the last operation. So we'll just run a script and we will just return this, I think. I mean, that makes sense. Yeah. That works. I've not done this before. So we are we are really finding out together how this works. Works is very smooth. I like just being able to have it. I really like it too. So we've got a save. So now we have this idea of a flow, and I think that's the thing that's interesting to me at least. So you'd rather use the ID than actually just use the flow endpoint, like the webhook endpoint? I could. I don't think that's, like, the proper way of doing it. But could we do that? Yeah. I mean, I feel like I feel like Okay. I'm interested in seeing both ways, right? I'm interested in seeing ID flows, which I think is the proper way, and then just calling the webhook from within the code. Right? Yeah. I'm gonna be I I don't even know how to make a web request in these off the top of my head. Just I think it's just Axios, isn't it? I think it's just Axios. But but how is Axios, like, exposed? And do you wanna know what? I'm pretty confident there are just some guides that were written around this that I think will just help us. Endpoints create a public API proxy. Here we go. This will this will help. Yeah. It's a it's a fetch. Oh, alright. Cool. So we will so we hit slash. So what we're gonna do here, we're we're forget all these services for a minute. They don't I don't think they're gonna matter. No. They won't matter because literally we're just basically now that we've created that flow, we're just doing a call to that webhook and then Yeah. We're gonna do a response, await, fetch, and then slash flows, async. Okay. And then, yes, this is response okay, response Jason await Jason, all of this jazz. I normally, honestly, just do this pretty low rent, then r r dot JSON and our response is the data. So I think we can just return reds dot JSON response. Yeah? Yep. I might just be explicit here. Flow response. Flow response. Yeah. Yeah. And maybe yeah. That yeah. Screw it. Let's try it. Let's do it. Gotta get this I feel like this is why I enjoy, like, non typed languages because you just mess around and see what happens. Yeah. I mean, you can build extensions just as an FYI with TypeScript. I just didn't oh, yeah. I thought this might be a little easier. So if I hit refresh here, we should see the same the same thing the same thing. Oh, wait. Hang on. I don't know why that's happening. Oh, was there an error? You have triggered an unhandled rejection. Failed to pass URL. So it didn't like the Yes. So just add the link to the I mean, sure. But that that doesn't make this portable. Right? That isn't let me just have a quick think here. Oh, I see what you mean. You wanna be able to pat yes. Okay. I see what you mean. Because then if we deploy it somewhere else, this will Yeah. This will still work. That's that's that's gonna have another little look. Let's keep having a little look here. So still sort here. No. Because now I'm right because this is the flows. All I wanna do is know, yeah, how do I run a flow? Let's just do you wanna know I think I've just had I think I've just had an idea on how this works, which is actually not looking at the services. It's looking at the the way the SDK does it. So if we look at the, extensions, packages, sure. The SDK just like type, type doc. This is just the the full dump of everything the SDK can do. There is an endpoint in here called something there's something in here for running flows. Andrew, I'm going It is I love a c. So even if you write the documentation, everybody, you still need to read the documentation. You do still need to run it. Here it is. Right. Create a flow, retrieve a flow, list flow. So this is all the stuff we just saw, but Yes. Here we are flow with get webhook trigger, trigger flow. What is going on here? Let's take a little look. Failed to pass URL from /flow/trigger/uid. Yeah. That I mean, that makes sense to me because it's not a full URL. Right? Do you wanna know what I did sneakily on on the side here. I have a chat with one of my colleagues because, of course, I did because I have that power. It does just need to be the full URL. So let's stop. Let let's stop battling against I was right. You're right. You're right. But you're right. It's not portable. You're very true. It's like you'd now need to, like, worry about changing this if you change where you're you're hosting it. So I do think Which I think won't matter for the scope of this. So now built that, restarted that. So now if we hit this, it did return and it did it by getting by by getting the the, yeah. So, oh, that's really exciting. Okay. Let's abstract this logic out then. Let's get this whole move thing. Let's just comment it out. We know it works. Okay. And what we're gonna do here instead is we have a post. And so, let's set up a new flow. Not here. Let's set up a new flow. Oh, that's so exciting. Okay. Cool. Snake. So we're gonna we're gonna create a move we're gonna create literally recreate this entire logic as separate flows. Why not do it as one flow, though? Oh, because it No. No. No. Just because it won't be each endpoint. So everything move is gonna happen in one flow, and that that's yeah. Yeah. It's cool, isn't it? I think track activity and logs, I'm going to level with you. I'm not I'm going to say don't track anything because it's just gonna it's gonna absolutely explode the logs because it can be every like, the full body every time. And we have the the the logs over here. So we won't do that. That will be a webhook. Data of lost operation, that's fine. Not asynchronous. Don't cache. Post. Okay. So exciting. Okay. And we will, run a script and we will return move left. Right. We'll just we'll just do that to start and just test test it works. Return move. Hit save. And we have an ID for this one. Great. And, what we're gonna do here? We're gonna do we're gonna copy this. We are gonna change the ID and we're just gonna go post, sorry, methods. I wanna say it's post and I think it's body equals JSON dot stringifyreq.body. I think that's I think that's the fetch. I think that's the fetch way of doing it. So What is the fetch way of doing it? Is it good? Okay. Fetch. My memory has not failed me today. I'm literally I'm so pumped that we're able to do it in flows. That was a really good I I think that was yours. You can have that one. No. We're gonna I'm gonna give that that's that was a 5050. We left brain, right brain thing here. I feel like it was one of those days. Okay. Okay. Alright. So we're ready set. Ready set Battlesnake, Hungry Bot. Sure. And start game. What's happening? It's happening. It's happening. It's happening. It's happening. But it will just go left, left, left, left, and die. Yep. Right? That's fine. Yeah. That's fine. It's still it's still going into the world. Awesome. Which means we are done with the code. We're not done. We'll need it for reference. Yeah. But we are in flows now. It's happening. What's interesting here too, folks, is, like, you like, literally with those two endpoints, like, you don't actually need to implement start and end. Like, you can stop with just those 2 if you're like, I don't wanna have to manage 4 flows. Like, you don't actually need start and end at this point. And so I think, like, don't use them. So first thing we did was avoid walls. I'm gonna run a script here. We'll return it, and then I'm just gonna do the it's annoying. You have to kind of create it from an existing path. Yeah. And then we're gonna take that and dump it in there. Okay. Avoid walls. Back to the back to the primitives. Now, you know what we didn't do? We didn't because we don't have the logs. We actually don't quite know what it looks like in here, which is annoying. Just a thought I've had. Yeah. It's true. But I think I know. Well, I mean, let's see. Let's see what happens here. And I think the cool thing here is, like, now we return to, like, traditional programming as well. Right? There's a lot of different ways you can implement this within the flow. Like, there's so many different operations. Technically, you could feedback a lot of the information and then make, like, decisions there or just do it. Let's let's return the data. Like, that's the whole data chain. And then so this first time, this is gonna fail absolutely miserably. But, oh, no. It won't log anywhere, will it? Do we wanna turn on those logs then? I know we didn't want to, but Yeah. Yeah. Can I turn them on then turn them off? Yes. Fine. Yeah. That's fine. Yeah. Yeah. Yeah. Sorry. I thought it was a one and done kinda deal. So let's create a new game. Create rematch. Okay. Cool. Whatever. Sure. Refresh. And there should be many Yeah. 8. That was 8 moves. So it's it's gonna get unwieldy, but this is what matters. That's great. That's awesome. Yeah. So we get Except the distinct so the trigger where's where's all the, not being oh, so Are we not sending it? Are we not sending it precisely? And this is why I wanted to check. Yeah. Yeah. Oh, wait, what did that say failed up there? Go back up to the options. No, no, no, no, no. Force. Okay. Cache enabled force, cache enabled force. So cool. We have this fetch. We send that is how you that is how you do it. Right? I mean, I could have been wrong. I was assuming, but ah, here we go. I'm glad that it has happened. Yeah. Body.stringify. Body data type must match content type header, but I I don't think sure. Do you wanna layer what? Sure. Let's just whack that header in. Just in case it's that. Yeah. See what happens. I'm not losing any sleep over over adding that. Is that an error? Oh, no. We've left a log we've left a login somewhere. All the serve hang on. They're all the services. Yeah. Didn't we didn't we remove that? No. It's the it's the context. It's this console log context. Oh, there we go. I was like, that's a big that's a big object. So right. Restarting. Okay. Okay. Okay. We're gonna create rematch. Let's get some logs. Nice. Oh, head to head. Some quick a nice quick death. Okay. Are we getting Payload. There we go. There we go. There we go. So it's in trigger dot. Body. Body, I think. Yep. Yeah. Trigger dot body. Yeah. That looks correct. So, I mean, there's one way to find out, right, which is, so, trigger data dot trigger dot Bobby. Nice one. Bobby. So let's go and take this first up. So first thing we'll do, of course, sorry, is we will is move safe. We have to think about how we, because we, we need to kind of alter this value as we go. Maybe we return that. Maybe we return that with each step. Right? So we'll start with a is move safe and we'll just return it every time. So Okay. We'll start this time, we'll create it. I also think that could be a const. Anyway, avoid walls. So we need these values. Do you wanna bump up the text size there a little bit more? Thank you. You know what? I'm actually inclined. Let's rename this one. Let's call this one set up variables. Yeah. Like that. Let's call them let's call it globals. We'll just make the key global so it's a little shorter. All we're gonna do is return is return. We're gonna return what was it called? Is move safe. We will also do forward width. It's going to be data.trigger.body.width. Old height. What was the other thing? Oh, my head. So that's all of that. And then, we yeah. Just return that. Right? Yep. Sponsored global. Yeah. Yeah. We will. Just just I I wanna be I wanna be testing early in Austin even though, you know, we're not doing much there. I just wanna I just wanna be validating that we haven't broken something there. So we will create a rematch. So all we should be getting now is an extra property in the data chain. Wow. That was a really short, really short game. I think it was, like, 2 moves. Yeah. Oh, rec is not defined. I think I left in a a remnant of what it was before. Rec.body. Yeah. Data. Trigger dot body. That's why we test. Create a rematch. What else have you used Flows for in the past? So I did the, the DevCycle Directus integration that I built out. So this was, it's worth checking out, just to see, like, the different use cases here. So it basically allowed for you to do an API call to a patch API on the dev cycle, patch API endpoint on the dev cycle platform to, like, pass basic data into into the service and to, like, put, like, an edge database for feature flag management. We might use that actually, when we start to do the dev cycle integration just because it's a really fast way, and I know that it already works with Directus. So, nice. But yeah. That's called EdgeDB. EdgeDB. Yeah. So it's just, it's just, like, a faster way to pass data. So how are we doing here? No. No. But if I refresh, I think I fixed it. Yeah. Right. That's everything in the in the global. Now I'm not sure. So I think is move safe is one that we might need to pass, like every move we're going to need to we're going to need to reset that, but that's fine. So cool. Next thing we'll do then is avoid walls. Avoid walls. We're gonna run a script. We have data, and we have our avoid walls logic here. Yeah. I feel like this is also just a really nice visual way to represent this whole This those are the steps. I really wanna go and find my Node JS snake or my, my Node RED snake that I created because I did the same it was the same process that I went through. Was it sorry. Just very quickly. Well, did I call it my head still? I think I did. Yeah? Yep. You did. Yep. So the nice thing about this is we have is say is move safe left and all of this. So I think we wanna create a new variable called is move safe, and the value of that, I think this works, is gonna be data dot globals. Was it multiple? No. Global. Yeah. Global. Yeah. I think so. Yeah. Dot is move safe. Right? Yeah. This this is And then yeah. This is something that's really interesting to know having used flows before. I was not taking advantage of the globals like that or not the globals because that's the thing you're creating here, but, like, the But the data chain. Touch on data chain. I thought you lost the data, basically No. As you went through. So that's interesting. And I've had another thought about this. I think the way we're gonna do this is using last. So last, dollar sign last is a dynamic variable that will always be the output of the last step. But that means this line will become basically a boilerplate first line on every step in, I think. I think this creates a copy. We'll find out. We'll find out together. So next thing we're gonna do is we're going to destructure, my head board width, and board height from data dot globals. And then the rest of the code should be able to be untouched. Right? Exactly. Yeah. It looks good. The only and the only thing we wanna the only thing we wanna return is is move safe. Only thing we care about. Yeah. If this works, I'm gonna be so pleased with myself. I have a hunch it won't just because, of course, why would it? Let me just move return move out the way. In fact, we can remove that. So no. Of course not. Sorry. Ah, I've deleted it now. It's fine. We're here. So return move because what we're gonna do in this step is we're gonna just do that last bit of logic. If all there safe moves, if no go down. So we're gonna get rid of that. All we care about is next move and return. Yep. Because that is a a step between where we are and where and where we're going. So I have in my here we are. This is what we just had in our last step. So we have beta dot globals. Now is move safe. There we go. So next move, safe moves. Is it safe safe? Why is it called safe moves? Oh, here. I need this line too. I'm gonna call that one. Safe moves. Object dot keys is move safe. Filter down is move safe key. Fine. Fine. And that's just getting the the the values. Then next move, is safe moves, math floor safe moves. So that that should be it, And then we should just be able to return move next move like so. So that's the last step in. That's the last step in the chain. Let me bump that up one more time. Sorry. So that's all the logic again. We have that boilerplate starts. We don't quite know if that works yet, but in theory It should. Theory, it should. It should. Dangerous last words. Those. Sorry. So we'll just set ready set battlesnake in there because we're not equipped to have multisnake yet. Nope. Did not work. What are our logs saying? Thank you. Thank you very much. Yes. It did not work. You're welcome. I feel like I need to add these useful Last is not defined. Absolutely. I know exactly where the typo was. It's data dot last, and it will be wrong there as well. Data dot last. Right? Yep. Yeah. Cool. And what's nice now is you're not having to restart Directus every time because now it's handled by the flow. That's wonderful. It is cool. There was a little bit of of, let's call it friction first time. Okay. That's not ideal. 42, 44, payload. Cannot convert undefined or null type. Okay. What are we? Payload after after but here's the thing. After avoid walls, look at that. It did say up force, which means everything's working until the return move. So that's fine. So that means it works, this whole passing passing is move safe each step. Yeah. But where it's breaking is this last one. Okay. So let's look at this again. So async function the error was cannot let's actually read the error. The error says, cannot confer undefined or null to object, which means the issue is here in object dot keys. So we have is move move safe. I think it can just be data dot last if that's all we're passing step to step because we don't return an object with is move safe. We just return is move safe, which means here again, although I mean, let's see. Let's see what happens. Yeah. I think I think that'll fix it. So if we hit create rematch Yes. It avoided pause. Nice. Lovely stuff. And let's just, let's just validate that was indeed what we needed it to be. Left. Hey. There we go. Heck, yeah. Which means we're onto we're we're now onto a winner, basically. It's this is the starting logic for our for the no. It isn't. Oh, it's it's somewhere in between that we haven't quite got the standard because this is the first one after the global and this is the last one. So that's fine. We need to create one more here. Yep. And, what's next? Avoid bodies. Avoid others. Yep. Run script. Paste that in. And we don't need is move safe anymore. We have the data dot globals. And where are the where are where is the logic? It's here. And just because I think I think it's gonna be easier, I'm just gonna great. Great. And I don't think we need board width or board height anymore. We just need my head. We have snakes. So I believe we had bored. I think we got bored out. Yes. I'm not sure we did. Let's look at the globals again. The actual board itself needs to come with 2. So, let's call it snakes. Let's just add snakes here. So data dot trigger dot body dot board dot snakes. Then let's create this last one again, as avoid bodies and that should have saved, but it's fine. Okay. So we have my head and we have snakes. I think I gen oh, yeah. I genuinely think nothing needs touching here. No, I think it's good. And I think we've the, the code works and we're even past. Yeah. I don't see any point of weakness in this at the moment. So we hit say, oh no, we don't, we just, Famous last words. We do that. Then we do that. So I'm gonna just Very good. We'll hit save. Oh, what's going on? Value fulfilled resolving collection, direct us operations. Value fulfilled resolve. In fact, it has to be I, don't know what that is. Record not unique. For field, resolve and click direct operations. Maybe if we turn off that logging now. Just turn off the logging because I think that's Yeah. But that isn't logging. That's a database save error, but I don't know why. Let let's just forget this was here for a moment like it was before, and it was fine. Okay. That does save. So if I take this instead and send it to avoid bodies and hit save, it's fine. And then if I go here to return move, fine. Do you wanna know why I'm just gonna walk away slowly? That's the right that's the right answer. If the thing starts working So we don't wanna create a rematch now because we wanna create a game with another snake. Yeah. Yeah. Star hungry in there. Alright. Let's see how this works. Okay. We got it. He Hang on. We've not had to Yes. Hey. There we go. Yes. Nice. Get in. Okay. Done. Nice. So the final thing here was this, if there's no safe moves, go down. I don't think we need that. I genuinely it's like a Oh, yeah. Backup. It'll always Yeah. Well, because if there are no safe moves, you're toast anyway. Exactly. So it's really just, like, if you want to have, it I don't know. It's good programming practice for you to build it in, but, like, I think here, like, we can worry about that down the road. Do you wanna know what? Given that this was basically the scope for this episode, I'm gonna add it. Why don't we add 1 one new block in? Right. Because I wanna do avoid avoid head to head. K. Yep. That seems easy. Yeah. Because we're just basically doing look ahead here. Right? We're looking at, like, one extra block ahead. So so yeah. I mean, so this is the if you didn't catch it on the last stream or on the last, the last episode, we so head to heads, you can do and you can win, but it's all about size and rules, but, like, these head to heads here. But with the logic we currently have, we're only ever looking at what's directly next to us. So ensuring that, like, if we have another snake beside us or directly in front of us, we'll never go that direction. But if there's a snake that's 2 away in the same direction, so basically, we're repeating the logic that's in here and just or we could technically revise this logic. I think it's similar because it's just like Yeah. Yeah. It will be similar, but I don't I do not think it's the same. So it's not the same. If we ditch this for a moment, we'll leave it as we could see it. So we care about the snakes, every snake, and we're gonna get rid of us. Now there is a a fancy way of doing this, which is, js return array without first item. To remove the first element in the in the array, you can use shift. Shift removes the first element of the array and returns it. So I think we can do this just to get rid of us first. Yeah. And then we have to find our because then we would have no valid no valid way to go. So So now we care about every other snake. So I'm gonna say head, it's gonna be snake dot body. Does snake have a head too? Does every snake have a head? Everything has a head. Snake dot head. So okay. Cool. And what we wanna do is look one space left, right, up, or down and remove if that's gonna be the direction we go in. Right? But we I'm just trying to have a think here because I think these are actually much more complex if statements. They are. It's basically if I remember having done this before, it's basically all of those if statements that we had there repeated 4 times, if that makes sense. Which we absolutely will not do. We will we will do, like, a nested loop. But I'm just trying to think through that. I'm just trying to think through, like, what is the logic here? Well, the first thing we wanna do is check every feasible space we can move into. That's the way we're gonna do it. So feasible directions. I remember encoding Valdez to do stuff like that, and then we had to remember what it meant. Possible next steps. And we actually don't wanna do this inside of this loop of every snake. We wanna do this just for us. So possible next steps are, is I don't know that because that's gonna be possible next steps is an array is an array. Cool. And we're gonna push into this array everything up, down, left, or right of us. Yeah. Then we're gonna remove our body piece, our neck. We're gonna remove our neck. Yeah. Okay. Cause we don't want our neck in there. So that, that will release 3 directions. And then for every snake, we're gonna repeat that logic. We're basically gonna say if any of these match, you remove it. So when we store them in here, we also have to store whether it's up, down, left, or right. K. Alright. Let's see. You have a plan, and I'm very curious to see how this will be implemented. First thing we wanna do basically is say up, down, left, or right. What is the coordinate? So what are the coordinates of that? So we're gonna say, in fact, I I think this might be easier. So we're gonna go possible next steps dot push. We'll we'll start with left. No. Left is going to be x is, come on, Kevin, you can do this. X is going to be our current X position. So this is going to be I don't just want my head. I want I want you. So I'm gonna save this. We'll come back here. I don't think we have you. No. No. We have my hand, which is great. Let's just throw you in there. Then we'll come to avoid head to head and what just while I'm here. And return move. Right. Return head to head. So now we have access to you in here. So we want Datastock Global's my head, you, and my head. Cool. So that's gonna be you dot, why why did I do you? We just care about my head. What are you doing, Kevin? Yo. Because you wanted to remove the neck. You were this Yeah. But not oh, yes. I suppose that will be that will become important, but the neck comes later. Yes. So we just wanna say my head dot x minus 1 and y equals my head dot y y. That's left. Bright. So that's the the same. Up. And so that's gonna be x remains the same, but y this time, r is minus 1 and down, plus 1. No. It starts the other way around. Down because bottom left is 0. Up. So that's pushing in push in all I mean, it's it's pretty obvious actually by the, by by the name of what's going on. Then we wanna remove our neck from that. Then there'll only be 3 items in the array. So we'll go possible next steps. How do I do this? Equals poss that becomes a let. Possible next step, stop filter. Possible next steps. So steps, where the step is not equal to you. You dot what is the it's a bit disruptive, but I'm gonna just what is the what's it called? U.body.body. I love that my my many, many if statements, my heuristic was not okay, but there's this will be so much cleaner though when it's done. I will agree with you there. Thank you. So this is remove net. I think that's what that does. So every item where that because all the body parts are is this. It's an x and y. Right? Yep. Yep. I I'm a little bit I think I think object, object comparison is a little bit hunky. So what I'm gonna do just to be on the safe side here is say, where s dot where s dot x is not equal to x and where it's not equal to y. So if both those things, no or no and hang on. This is this is important. I'm gonna do it the other way around. So where they are equal to x and they are equal to y, that means, hey, this item matches or wrap the whole thing in another bracket and we will negate it. Okay. That should be removing. Does that make sense? I'm so glad we have a video because that's super unreadable, but I get the logic makes sense. No. No. No. Not not unreadable. Unreadable. I mean, like, I feel like if somebody looked at this, they would be like, what is happening in this line? So, I mean, I mean, we're removing the yeah. Yeah. Right. Okay. Sure. Yeah. So Who needs to read this code except for us? Exactly. No. This makes sense. Okay. Yeah. I think that works. So we removed the neck. So that's removing that's saying all of our possible neck positions. Now we wanna basically figure out all of the every other snake's possible next steps. And if there's any matching item oh, there's a there's a silly, silly little thing going on here, which is we're gonna push in. I'm gonna just call the variable c to mean coordinates and that and this is where it all starts falling apart in terms of, like, clarity. And I am gonna I am I I've decided I am gonna be more explicit here. No. I think it was I mean, I think it's I think it's very clean code before, but, yeah, I think that this makes a little bit more sense. Yeah. So we have the cohorts. And the reason this matters, It's because we don't just want to store the coordinates. We also wanna store the actual reference to which direction it is. So as well as the quotes, we are gonna say direction left, and we can get rid of that. We can get rid of that. So direction left, direction right, direction down and direction up. Right? So now we just have to change this bit here because it's not s dot x anymore. It's s dot quartz x and that's dot quartz y. But it will when it removes it, will physically the directions will no longer and then at the end, we're gonna just return the those directions. So I think that that's an important thing. So we can actually ultimately at the end change is move safe and know what values we are we are removing. Yeah. Because before, there's no how do we know which one's which other than the order we initially push them in? Mhmm. Not a nice. The next thing we want to do is go around every snake, and we wanna basically do this same game here where we go left, right, up, down, push it into an array, cross reference them. If any of them are the same, we know the direction in which they match. Oh, that That's funny. Off reactions gone. Are you familiar with these? I am, but you're in Arc. Right? Is that where it actually is? Or is it within Riverside? No. It's it's macOS. Oh, it's in Mac. Really? No way. Yeah. But I don't Well, I'm not I'm on Windows. Windows is like, no. We don't we don't think these are things that we need. That is so funny. So now we now we wanna do the same thing for this snake. And this is this is the important thing is that for every snake, we are literally gonna do this exact same logic, except we're not gonna remove the neck. We're just gonna say, oh, are we gonna remove the neck? No. No. We'll just remove the head. No. No. No. No. Because if we you know, because if we're colliding into the neck, we're colliding like that would have been handed by the dome. Yep. Yeah. Exactly. Yeah. So it's just the head. Exactly. Exactly. So we just care about this logic. So possible next steps. And I am just gonna just shrink this down slightly because it'll be contextually clear what's going on here. So it's no longer my head. It's no longer my head. It's head. Head. Okay. And so that's so that's that. We're doing that for every single snake. And now this is the important thing we are going to compare. Yeah. We are going to compare. Let's just have a think about this. We actually don't care about the directions this time. The directions are irrelevant. I think, I think we'll leave them in for the sake of having the same data structure. So we know exactly what we're doing, but this bit's irrelevant. We just yeah. It's it's irrelevant. So this n is going to go before it's just one big array of every snake. We don't need to have it on a per per snake basis. So this is us populating and with every viable direction that could ever be in. Actually, I've had a change of heart. We are we are gonna Sure. That down. And then we're just gonna be comparing our end versus our possible next steps. Hence, look, we're just gonna be You absolutely you absolutely got it. I like it. Okay. This is cleaner than I thought. I was definitely you were, I get where your head is at with removing some of this stuff now. I love it. It took it took you getting to the end of this for me to be like, yeah. I I this makes sense. Good. Good. Good. Thank you very much. Thank you, Ro. Smart code. Very much. So now what we're gonna do is compare every single value in n. So we're so what we're gonna do now is and yeah. Yeah. Perfect. So we'll we'll loop now. So it's a for let n of, can't do n. Yeah. If you just change n to to next moves or something like that or or yeah. Yeah. There you go. Sure. Oh, I see. So for so next, I'd rather that's fine. For Yep. So I can use the shorter version inside the list. I'm about to use it, I think, a reasonable amount. So for every single value in there, is it one of those? It's all we care about. Let's have a think let's have a quick think about how we're gonna achieve that. Okay. So for every single one, we're gonna say, does next possible Does value in one array appear in another? Hey. There we go. Nice little vanilla JavaScript there. Absolutely. Include some and include. Some text element against the test function that return. Yeah. It's great. Cool. I don't think this is, oh, but it's that's no. It's that same thing again with objects. So I think the object nature of it, like, object comparisons are are specific. Yeah. It's a find and a size I think this is actually flipped. What are the responses? Did they say it actually works? I think so. That's a bit of a it's a bit of a big big example. Got it. Got it. Lovely. That's the answer. So I'm gonna just I'm gonna just pop it here and comment it out so we just have a little reference at the point where we're writing it. So this is an array. Let's consider this as our possible next steps. Yeah. So we wanna say, for, matches r.sum. It's not called r, is it? It's called next possible steps. Possible next steps. Possible next steps. Possible. I'll fix that in a moment. So sorry. The sum method of an array test whether at least one element in the array passes the test implemented. Okay. So next possible did I make a typo? Yep. Possible next steps, not next possible steps. Just Thank you. It's what I'm here for Possible next steps. And it immediately changes color to be like, yeah, you can spell now. Thanks. Possible next steps dot sum item. We'll do that again, and it's item dotcoords dotcoords. Dotxmatchn dotx. Dotxanditem.coords.y. For n of next. Is this is this how is this really I I think I I think there's some redundancy in here, actually. Yeah. What? Yeah. This is all we're this is this is trying to, like but we're already in a loop. We're already in a loop. So all we wanna know was, I've got it. Matching collision. Collision. Is that how you spell it? Collision Yep. Equals possible I got it. I got it. I got it. I got it. Next steps dot find and because we just wanna find does does one match. Right? And what we wanna know is step in there, is there a value where the cohorts dot x are the same as n.xandstep.cowards.y equals m.y. If this returns a value It works. Then that yeah. Then that collision it's gonna be a little bit of a long winded one to test because also we're gonna have to go we're gonna have to go back through the logs. This one's gonna actually be really painful to test because in theory, if it works, you know, but, so what this will return is a possible next step. And so what we will then do is if this this will have the value of possible next step in it. Mhmm. If it matches, so what we will then do is say if collision, because it will be 4 to undefined, like, some faulty value if if there's nothing returned in there, then possible just get myself a few characters because I think I'm gonna go quite far to the right here. Possible next steps equals possible next steps dot filter, and we wanna remove this item. And it's this. It's this logic right here that we already wrote, but slightly different. So we wanna say we're s.coawards.x, where collision by collision.cohorts.x. Oops. This one here, where it is the same as collision collision. Am I spelling it right? I I swear I swear I swear I That's right. No. You're good. You're good. I'm literally just like, you know, when words start to look wrong. Yep. No. But it's catching it. It's catching it, turning it purple if you're right. And this is the same as collision dotcoorg.y. Okay. I think I think this is it. Then oh, no. There's one more step. So now possible net, possible next steps is a shortened array which has just items which are viable. Yep. Just items which are viable. Let's just have a think because we we don't wanna What is that actually gonna look like, though? Do we know right now? It it will be an array of objects that look like this. Is it just gonna be a same case? Yeah. Yeah. But just a shortened a shortened list. Yeah. Now what we actually wanna do now I think about it is we kind of want the others, which I've just realized we want we want the other items. We want the ones that are being removed. So Oh, to So removed from his move. Yes. Yes. Yes. Yes. So let make false. This is we're starting to get a little hunky now in terms of, like, code quality, but, like, it's fine. So if collision we don't wanna screw around with possible next steps. We don't care about that. All we're gonna do is add collision dot direction to make force, and we're not even gonna do that. We are gonna just straight up say is move safe dot left, and the value of left will be in collision dot the equals false. And that's the direct we are making the the value that we came in with. Yeah. We're setting it to false because we're gonna collide. And I'm not sure if this is valid, syntax. I will find out. We will find out. I might I might just save ourselves some effort here. Commission dot the okay. Alright. Sorry for bringing oh, don't don't play this game. I, I'm sorry. I felt like that wasn't an overly, like, collaborative exercise, and I'm sorry. That was it was wonderfully collab I don't know what you're talking about. See, my favorite collaborative experiences are the ones where I can nod along and say yes, And I can I can help pick out when you've misspelled something? That's, I feel like I've I've contributed in my own YouTube. I don't know don't know what that little error is at times. Anyway It's weird. Let's and this one is gonna be a little bit of a hard one to to test. So we're gonna just have to watch watch this carefully. The snake's going up the whole time. Okay. So there's a bug somewhere. There's a bug somewhere, but we will be able to See debug it. Oh, it all died here. Un un there's a problem in the setup of the globals. There's a comma. Change in here. Comma. Comma. Those commas. It's always the commas. Grammar's out to you. I'm loving I'm loving now that we don't have to touch the code editor at all. Yeah. Agreed. Okay. See. So where K. Avoid head to head. Fine. Unexpected token line 8. Great. Okay. 8. There is an extra bracket here and an extra bracket. No. No. No. The one at the end is the one at the end is correct. There's an extra bracket here too. Great. Let's see if that does it. Yeah. I I literally cannot believe we're okay. I was gonna say we're getting it to work. We're getting things are happening. We're debugging, and that's the important thing. Alright. Snakes is not defined. Okay. Not a problem. What's the I mean, this is good. Oh, snakes. Fine. It's all really small, like, little errors, quite well defined, quite quick to fix, allegedly. Alright. Alright. Alright. I need everyone to know at the time of recording, it is 11:30 at night. Snakes dot shift is not a function or its return valuable value is not iterable. Right. That's that's fair. And that is here, snake dot shift. So what we're gonna do is just it really doesn't matter. Like, snake star shift, and I I'm assuming it that's how it like, it needs to happen on its own line first. Kevin, if this is what you programming at 11:30 at night does, I don't wanna see you programming when you're fully rested and awake. Well, here's here's the joke. I'm I'm never fully rested. I mean, children. Children. Yeah. Fair enough. Well, it's going it's going up, but I also didn't set that up correctly. But let's let's keep having a look at the logs. S is not iterable. Okay. I think I've misunderstood how shift works. 1st element. Oh, it returns the first element. I don't want that. I I want to return them. Right. Right. Right. It returns just the element. It pops out of the top, but I want everything else. Oh, everything but. Yeah. So what's the option of the shift? It is to do the head, avoid head to head. So it is to do the work. So it's to do the shift snake stop shift, and then I think it might actually be to put snakes back in there. Yep. But I'm not sure if snakes is re I'm not sure if that will work. I think it will. Okay. I think it's not doing that anymore. This is obviously not the test, the, we need to But we're not we're we've got no actual errors in the code that we've well, that we I use we very liberally. The code that has been produced in that final card is working and it's definitely a little bit slower now. So I think that we're definitely getting a, there's a lot more compute going into this, which totally makes sense. Yes. Okay. We're we're still going. Woah. That was a okay. Okay. It did end up giving up. Why? Oh, because there was no viable choice. Yep. So that's Which is yeah. Wow. Hey. We wanna move fast oh, sorry. What do you mean? I was gonna say if we wanna move faster for the head to heads, put multiple snakes in more than just one. Okay. I I think we I think we got a snake. I think we did too. I think it's working. I'll stick 2 hungry bots in that There we go. Cough. That should do it. Should have hit start game first, so it did its job. Okay. Head to heads are obviously gonna be hard to to start. Yeah. But we can kind of see we can kind of see here when it ends it ended. Okay. So now we can watch the whole thing. Yep. So he's not what's he turn why is he turning? Was there a safe move there? There was a safe move. How do I go back? Pause back. No. There wasn't. Nope. There wasn't. It got itself into a corner. Fine. I'm confident I mean, I'm not confident enough. I do that were there any head to head opportunities? And I didn't see one, did you? Nope. No. But I think I think we're not getting any errors at that final stage, and I think that's a good sign that the logic in there makes sense. You yeah. Yeah. But it might not be doing what we want. So what other few do you think 11 by 11 is still a good size, or maybe I should make it small? Make it small, and then we can see faster. And, yeah, give that a try. Yeah. Yeah. There we go. Yeah. Run that and see what happens. Oh, it's it it went on for a reasonable length of time. K. So there looks like No. Our snake didn't didn't need to didn't have a head to head moment. Well, I mean, it avoided a potential head to head moment there, but But it's I'm happy I'm happy in no. Yeah. Because we'll never know, will we? Yeah. We'll never know. We'll know if we play enough games over a long enough period of time, but I think the code is there. And we would know it doesn't work if there is a head to head, but they don't happen often enough. Hey. We leveled up our snake. That's solid. So not only move it to a different platform where it's running, same logic, and then adding that extra step and super visual. Super visual. I'm very I'm very, very satisfied. I'm very satisfied by it that working. Awesome. I think that brings us to time. I mean, we we have to be at time at this time. You gotta go to sleep. I've got yeah. My kids will be up in 5 minutes. So, awesome. Thank you for for for for doing this again. Yeah. Thanks for joining us, everybody. I feel like I'm glad that you were driving this time because had I been driving, this would have not gone as smoothly in any way, shape, or form. So I feel like this was gonna be be silly. But I I am excited to eventually drive when we, again, in episode 3 or 4 when we start to implement some other technology. So do we know what we're doing on our next episode yet, or is it all In our next episode, we're gonna stay in Directus, and we're not gonna be leveling up our snake. But given that Directus is backed by a database, we're gonna start actually storing data about games and then seeing what we might be able to learn with Directus Insights. I love it. I love it. That's gonna be an awesome next episode. So, we've got a snake. You've seen how it works. That's all of the steps for the starter snake that are worked out in there. It's actually just a functional JavaScript snake. You could pull all of that logic out. Well, most of that logic out and just put it into a JavaScript Express server and just go to town. But, but we've got it working in here. And so now let's do a little bit more. Let's see how powerful you can make Directus with Battlesync data. I'm very excited. Yeah. This is awesome. So until next time, this has been ready, set, battles, stake. We're getting better. We're getting better. Some some would say. Some would say. Till next time, folks. Bye, buddy.",[190,191],"79065ff8-a276-4134-a90c-04775dccb561","82d75a59-34de-4a81-8d98-59f44f95b638",[],{"reps":194},[195,251],{"name":196,"sdr":8,"link":197,"countries":198,"states":200},"John Daniels","https://meet.directus.io/meetings/john2144/john-contact-form-meeting",[199],"United States",[201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250],"Michigan","Indiana","Ohio","West Virginia","Kentucky","Virginia","Tennessee","North Carolina","South Carolina","Georgia","Florida","Alabama","Mississippi","New York","MI","IN","OH","WV","KY","VA","TN","NC","SC","GA","FL","AL","MS","NY","Connecticut","CT","Delaware","DE","Maine","ME","Maryland","MD","Massachusetts","MA","New Hampshire","NH","New Jersey","NJ","Pennsylvania","PA","Rhode Island","RI","Vermont","VT","Washington DC","DC",{"name":252,"link":253,"countries":254},"Michelle Riber","https://meetings.hubspot.com/mriber",[255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,232,443,444],"Albania","ALB","Algeria","DZA","Andorra","AND","Angola","AGO","Austria","AUT","Belgium","BEL","Benin","BEN","Bosnia and Herzegovina","BIH","Botswana","BWA","Bulgaria","BGR","Burkina Faso","BFA","Burundi","BDI","Cameroon","CMR","Cape Verde","CPV","Central African Republic","CAF","Chad","TCD","Comoros","COM","Côte d'Ivoire","CIV","Croatia","HRV","Czech Republic","CZE","Democratic Republic of Congo","COD","Denmark","DNK","Djibouti","DJI","Egypt","EGY","Equatorial Guinea","GNQ","Eritrea","ERI","Estonia","EST","Eswatini","SWZ","Ethiopia","ETH","Finland","FIN","France","FRA","Gabon","GAB","Gambia","GMB","Ghana","GHA","Greece","GRC","Guinea","GIN","Guinea-Bissau","GNB","Hungary","HUN","Iceland","ISL","Ireland","IRL","Italy","ITA","Kenya","KEN","Latvia","LVA","Lesotho","LSO","Liberia","LBR","Libya","LBY","Liechtenstein","LIE","Lithuania","LTU","Luxembourg","LUX","Madagascar","MDG","Malawi","MWI","Mali","MLI","Malta","MLT","Mauritania","MRT","Mauritius","MUS","Moldova","MDA","Monaco","MCO","Montenegro","MNE","Morocco","MAR","Mozambique","MOZ","Namibia","NAM","Niger","NER","Nigeria","NGA","North Macedonia","MKD","Norway","NOR","Poland","POL","Portugal","PRT","Republic of Congo","COG","Romania","ROU","Rwanda","RWA","San Marino","SMR","São Tomé and Príncipe","STP","Senegal","SEN","Serbia","SRB","Seychelles","SYC","Sierra Leone","SLE","Slovakia","SVK","Slovenia","SVN","Somalia","SOM","South Africa","ZAF","South Sudan","SSD","Spain","ESP","Sudan","SDN","Sweden","SWE","Tanzania","TZA","Togo","TGO","Tunisia","TUN","Uganda","UGA","United Kingdom","GBR","Vatican City","VAT","Zambia","ZMB","Zimbabwe","ZWE","UK","Germany","Netherlands","Switzerland","CH","NL",1773850423007]