MIT Battlecode Reflections: A First-Time Finalist’s Takeaways | by David Teather | Nov, 2024


Key Takeaways from a First-Time Contestant

Picture created by the creator, utilizing Battlecode’s Engine

I used to be dragged into Battlecode 2024 by one among our teammates. I had by no means heard of Battlecode earlier than, however I used to be excited to strive it out. I had lots of enjoyable and I’m glad I did it, and we ended up qualifying for the finals and inserting thirteenth total. So I figured I’d write a weblog publish in regards to the expertise from the attitude of a primary time participant.

This was cross-posted from my blog, so if you happen to’re test extra on the market.

Battlecode is a contest the place you write code to regulate a workforce of robots which have to perform some activity. You possibly can learn extra about it here.

This 12 months the sport was a duck based mostly seize the flag recreation the place our aim was to seize all 3 of the flags from the opponent. The sport is performed on a grid and every workforce has a base the place they spawn geese. Geese can transfer across the map, construct traps, and assault different geese. The sport is performed in rounds, and every around the geese are given a set quantity of bytecode to execute their actions.

Right here’s a fast snippet of what the sport seems to be like

Instance match within the Battlecode’s Engine, created by the creator

There’s loads occurring in that gif so let’s break it down somewhat bit.

Every duck has a number of actions to assist assault or defend flags that it might probably carry out every flip/spherical (proven on the backside of the gif above). Every motion has a selected cooldown so you’ll be able to’t simply spam the identical motion time and again.

  • Transfer to a brand new tile
  • Construct traps: water, bombs, stuns, dig a water pit, and fill a water pit
  • Choose up flag
  • Assault an enemy duck
  • Heal
  • Respawn
    – When a duck dies, it might probably respawn at one of many workforce’s spawn factors after ~20 rounds

There’s additionally a forex known as crumbs that you may get from two methods: a number of spawn on the map every spherical which you’ll be able to decide up, and also you additionally get some for killing enemy geese of their territory.

Actions that construct traps require crumbs, which requires you to be strategic about how you utilize your crumbs.

Because the similar code will get deployed to all of the geese, you need to write code that may deal with lots of completely different conditions. Possibly you need some geese to give attention to defending and constructing round base, possibly you need some designated to exit and seize flags, and possibly you need some to be aggressive and assault the enemy geese.

A number of issues that make it troublesome:

  • There’s a restricted dimension shared array that every duck can learn and write
    – That is the one approach to talk info between your geese in regards to the state of the sport
    – This implies you need to be strategic about what info you retailer within the array and the way you utilize it, and when you’ve got all of your geese performing the identical motion based mostly on the identical info you need to watch out as a result of in any other case they’ll cluster up doing the identical factor so you need to watch out about the way you distribute the work
  • Every duck is given 25K bytecode to execute per flip
    – Which means every flip every duck will get to execute a sure variety of actions, calculations, and reminiscence reads and writes.
    – If you need tremendous good pathfinding (which we didn’t have) you need to watch out about how you utilize your bytecode in intensive calculations like this in any other case you’ll run out of bytecode and your geese will simply sit there and do nothing
    – Fortunately we didn’t have to fret about this an excessive amount of since 25K is kind of massive and apparently in earlier years its been a lot smaller

I additionally really feel prefer it’s actually laborious to inform in case your new bot is best than the earlier model, like normally it’s higher in some conditions and worse in others. In contrast to most software program I’m used to engaged on it’s straightforward to inform if what you’ve made is best than earlier than since if you happen to added a brand new function it’s higher than earlier than.

For this I’d say like no less than half of the options I attempted to develop didn’t work tremendous nicely and simply ended up scrapping the modifications. There’s so many branches for lifeless options that simply didn’t work out.

Okay so now that we’ve got a fundamental understanding of the sport, let’s speak in regards to the precise competitors.

Leaderboard

The leaderboard is among the most vital elements of the competition. It’s a semi-live leaderboard that reveals the rankings of all of the groups within the contest. Each 4 hours there could be ranked video games performed towards your relative neighbors on the leaderboard and if you happen to win you acquire extra factors and if you happen to lose you lose factors.

Moreover, you’ll be able to manually queue your personal ranked video games towards different groups so long as they permit it. That is vital as a result of you’ll be able to’t simply queue video games towards the identical workforce time and again to farm factors.

Nonetheless, you may also queue unranked video games towards any workforce which is vital for testing your bot towards different groups to see if the modifications you made are literally higher than earlier than towards actual opponents.

Sprints

Sprints are a separate a part of the competition the place the organizers run a bracket of video games and livestream the outcomes. Sprints are performed throughout all groups whether or not they’re in your division or not. The sprints are a enjoyable approach to see how your bot is doing towards different groups and it’s additionally a great way to see how the opposite groups are doing.

The seeding of your workforce within the sprints is predicated in your leaderboard rating, so if you happen to’re doing nicely within the leaderboard you’ll be seeded larger within the sprints.

Tournaments

Tournaments are additionally livestreamed and are performed throughout the groups in your divison in the identical approach because the sprints. The seeding of your workforce within the tournaments is predicated in your leaderboard rating, so if you happen to’re doing nicely within the leaderboard you’ll be seeded larger within the tournaments.

In our 12 months the highest 12 US faculty groups and the highest 4 worldwide groups certified for the finals. As well as there’s different divisions like highschool and new to battlecode groups which have their very own match.

Okay now that we all know extra about what battlecode is and the way the competition is structured, let’s speak about our robotic and a few of the methods we used. This part goes to be somewhat bit blurry as a result of I’m scripting this ~2 months after the competition and I don’t keep in mind all the things we did.

Our Methods

We had a number of completely different methods and variations of our bot throughout the match that we tried out particularly as the sport received tweaked for steadiness and we realized extra in regards to the recreation.

  • Setup Part
    – For the primary 200 out of the 250 rounds of setup we simply had all of our geese transfer round randomly to attempt to discover as a lot of it as we might
    – After that we had our geese transfer to the middle of the map and construct traps subsequent to the wall dividing the 2 sides of the map
  • Base Protection
    – We had designated geese that will keep always guarding our flags and constructing traps round our base and particularly proper on the flag itself which we positioned down bombs and stun traps proper on the flag in order that if the enemy tried to choose it up they might get surprised and we might assault them.
    – We additionally determined to make a water moat checkboard grid sample round our flags in order that the enemy geese would both should spend crumbs attempting to fill the water or undergo on the diagonals which made certain that the enemy geese couldnt fully swarm our base without delay and it made them funnel by a number of paths which made it simpler for our geese to defend.
    – If a duck was guarding the flag and it noticed an enemy duck close by it will set a world variable within the shared array that will name different geese to come back assist defend the flag. We additionally made certain that if these protection factors have been known as that we would favor geese to spawn close by to assist defend the flag.
    – However we needed to be cautious about this as a result of if we known as too many geese to defend the flag then we wouldn’t have sufficient geese to exit and seize the enemy flags.
  • Flag Passing
    – We observed that always our bots would get caught surrounding the duck with the flag and stopping it from actually transferring wherever so we carried out a flag passing technique the place it will move the flag to a different duck nearer to the place the flag wanted to be captured
    – We added this beautiful late within the match and it labored fairly nicely.
  • Flag Return
    – When a duck was returning the flag we had logic to assign close by geese to escort the duck returning the flag to ensure that it might get again to our base safely
    – It additionally focused to return to the bottom that was closest to the place the flag service was
  • Pathfinding
    – We took code from a earlier 12 months’s bot for doing BugNav pathfinding however of their 12 months the bytecode restrict was a lot smaller so we had much more bytecode that we might’ve been utilizing to do smarter pathfinding however didn’t transfer to one thing higher.
    – Our pathfinding was so dangerous that within the sprints we’d typically get caught attempting to return the flag and sometimes misplaced video games due to it and the casters would make enjoyable of us for it 😭 however it was humorous so I didn’t thoughts
  • Higher Distribution of Specializations
    – One factor I didn’t point out was that when a duck does an motion sufficient instances it’ll specialise in that motion and get extra environment friendly at it. This specialization additionally limits it’s peak effectivity in different actions so we must always’ve in all probability been extra cautious about this since for lots of the match most of our geese have been specialised in therapeutic and we didn’t actually need that many geese specialised in therapeutic because it made us worse at combating.
    – I did make this somewhat bit extra nicely balanced between healers and fighters on the finish however I feel that is one thing we must always’ve carried out in a extra calculated approach to attempt to maximize probably the most out of our geese
  • Caught Flag Duck
    – We simply didn’t write any code to deal with the case the place a duck picks up the enemy flag and will get caught someplace like on an island surrounded by water and have been simply too lazy to repair it and it didn’t occur typically sufficient for us to care about it an excessive amount of.
  • Duck Standoff
    – Generally our geese would simply sit there and do nothing and never transfer as a result of each teams of geese calculated that they have been at an obstacle and that they shouldn’t be aggressive which was annoying and we didn’t actually have a great way to deal with this.
  • Shifting Flags
    – We tried to maneuver the flags across the map in setup which helps you to change the placement the place your flags are however we didn’t make investments sufficient time into this for it to be tremendous efficient.
    – Different groups have been capable of transfer their flags across the map in simpler methods. Particularly after they have been scoring spots of the map based mostly on issues just like the # of partitions across the flag and the gap away from pleasant spawns and enemy spawns.
    – That is positively a function that we must always’ve spent extra time on because it was fairly efficient for different groups

You’ll find our code here

I simply thought this is able to be enjoyable to incorporate however to qualify for the finals we needed to win this match and we have been fairly excited after we did. Right here’s a video of us winning the match

Us profitable the qualifying recreation on livestream. Video by the creator

This part is extra devoted to our expertise in Boston for the finals, which was fairly superb however if you wish to skip this phase and go to reflection part beneath that’s cool too.

The Expertise

The finals have been held at MIT in Boston, and all of us received flown on the market for the occasion and it was my first time in reminiscence being in Boston and town was actually fairly. We additionally ended up staying within the MIT dorms which was thrilling due to the opposite individuals we met there by being within the dorms. Though, if I have been to do it once more I might’ve in all probability stayed in a resort as a result of the dorms are nicely ya know faculty dorms and will’ve been cleaner and I might’ve had a cushty mattress.

We additionally all have been invited to a dinner earlier than the finals the place we received to satisfy the opposite groups and the organizers. It was attention-grabbing to see the place everybody was from as well as we received some very nice meals from them for the dinner.

The Outcomes

The finals was hosted of their auditorium and was fairly enjoyable to observe even when we went 0–2, however we did place thirteenth total and it was already an enormous accomplishment to make it this far.

Additionally they ran a estimathon the place we needed to guess a variety on some query and I ended up profitable a duck from accurately estimating the variety of MIT dorm residents that provided to host groups for the finals. Right here’s a video of me catching the duck:

Video from the Battlecode Finalist Livestream

Enjoyable truth is that I put a pocket book beneath my jacket once I earlier than I went strolling up there so the video seems to be kinda foolish due to how I’m strolling 😭

I’m positively not an skilled on Battlecode, however I do have a number of key takeaways from the expertise and issues I’d enhance on if I have been to do it once more.

Make investments Time in Writing Organized and Clear Code

Regardless that that it initially would possibly appear to be a reasonably easy recreation even in a 12 months the place our recreation was comparatively easy in comparison with different years it’s criticial to take a position lots of time in writing organized and clear code.

We didn’t do code evaluations, and didn’t refactor our code as a lot as we must always’ve and it ended up biting us all through the remainder of the match as we needed to repair bugs and simply attempt to perceive what our code was doing. That is one thing that I might counsel everybody invests extra time in particularly firstly to arrange a great basis and construction on your venture so to construct on it and make modifications extra simply.

A part of the rationale we didn’t do it’s because we felt we have been rushed to get options out for the sprints to see how we have been doing towards everybody else and needed our video games to be proven on the stream.

Sprints Aren’t The whole lot

This brings us into the subsequent level that sprints aren’t all the things and don’t matter an excessive amount of. You positively ought to give attention to the primary occasion itself and never getting too caught up in making your bot excellent for the sprints.

As well as, if you happen to don’t find yourself making it that far within the sprints it’s not the tip of the world. We by no means received our video games proven on the dash stream and certaintly didn’t win them. At the least our 12 months it felt just like the bracket we have been in (US faculty) was comparatively small and if you happen to don’t find yourself making it tremendous far within the dash it’s not over on your workforce and you may nonetheless qualify for the finals.

Scrimmage a Lot

As I discussed earlier, it’s tremendous troublesome to inform in case your new bot is best than the earlier model since you’ll be able to solely domestically take a look at your bot towards different variants of code that you’ve and in lots of instances it’s not tremendous useful to check towards your earlier variations of your bot as a result of in the event that they’re too similiar they’ll typically draw loads otherwise you’ll see that the change you made is best in some conditions and worse in others.

Because of this it’s vital to scrimmage lots of different groups to see in case your modifications are literally higher than earlier than towards actual opponents that you simply’ll possible face in ranked video games and the tournaments.

It didn’t cross my thoughts till the tip of the match when one other workforce shared that they did this, however I feel it’s a extremely good thought to make a script to mechanically queue video games towards different groups and with some form of analysis to see in case your modifications are literally higher than earlier than. One script is linked here

Even if you happen to don’t have a script to mechanically do that, it’s nonetheless vital to manually queue video games towards different groups to see in case your modifications are literally higher than earlier than with the modifications you made. We didn’t and we nonetheless queued 818 complete unranked scrimmaged which is the eighth most of any workforce. And seventh most complete scrimmages with 1,294 in complete.

Watch Your Video games

One of many downsides to an automatic script to queue video games is that you simply in all probability wouldn’t be watching your video games as typically. It’s tremendous helpful to observe the video games that you simply’re taking part in to see what conditions your bot is doing nicely in and what conditions it’s doing poorly in.

This provides you lots of details about what you’ll be able to probably do to enhance your bot and your methods.

Watch the Different Groups

It’s additionally equally vital to observe the opposite groups video games (particularly if they’ve auto scrimmages off) to see what methods they’re utilizing and the way their bot is doing.

When you see a workforce that’s doing a lot better than you otherwise you see some attention-grabbing methods that they’re utilizing, don’t be afraid to steal and increase their methods to suit your bot probably even higher than how they’re utilizing it.

Use Group Sources

The Battlecode group is tremendous useful and there’s lots of assets on the market that can assist you get began and enhance your bot. There’s lots of groups which have shared their code and techniques from earlier years and it’s an effective way to get began and see what different groups are doing.

As well as there’s lots of code from earlier years that additionally works yearly and is an effective way to get began and see what different groups are doing. For instance: shared array communication, pathfinding, and so forth. All of those are issues that yow will discover in earlier years code and use in your bot.

Recommendation to New Members

It may be overwhelming to get began with Battlecode as a result of there’s lots of issues to find out about: the sport specs, the competition construction, methods, limitations on the sport, the way to talk between your geese, working video games domestically, and so forth.

To not point out that it may be troublesome to start out writing code as a result of you need to get used to what strategies exist and what actions you’ll be able to carry out and what info you’ll be able to and can’t entry and will be troublesome to work with. I positively extremely counsel that you simply use an IDE with plenty of autocomplete so you’ll be able to preview all out there strategies. It feels loads like working with a library like Pandas the place there’s lots of strategies and you need to get used to what’s out there and form of appears like one other language totally.

It positively annoyed me initially as a result of I simply needed so as to add some fundamental options however as a mixture of: our venture not being tremendous organized, me not being aware of the sport, or the way to write code for it, it was fairly annoying to get began. Nevertheless it’s price it to push by and get began as a result of it’s lots of enjoyable and also you’ll study loads.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *