🏎️ When Bots Play Better: The One and Only Bot for KartWars.io

kmataru

Adrian Paul Nutiu

Posted on November 27, 2024

🏎️ When Bots Play Better: The One and Only Bot for KartWars.io

🚀 Intro

It was that day which found me wandering through multiplayer online browser games, just to stumble upon KartWars.io.

For those of you who don’t know, KartWars.io was a fast-paced multiplayer game where players controlled karts in an arena. The goal was simple: collect power-ups, outmaneuver your opponents, and survive for as long as possible while climbing the leaderboard.

I quickly got hooked, but as I played, an intriguing question popped into my mind:

What if I could create a bot to play this game for me?

Not because I didn’t enjoy the gameplay, but because the challenge of building something capable of navigating this chaotic digital battlefield seemed too fun to resist.


⚠️ Photosensitivity Warning

The following video involves fast-changing visuals that may trigger discomfort. Please proceed with caution.


GitHub logo kmataru / kartwars.io-bot

🚗 Intelligent self-control and fighting system of karts in the Kartwars.io multiplayer game.

 

Kartwars.io Bot Championship Edition

aka "Intelligent self-control and fighting system of karts in the Kartwars.io multiplayer game".

Welcome to the kartwars.io bot!

Table of Contents

Goals

  • No global pollution
  • Easy to use
  • Easy to create and embed any strategy and tactic
  • Clean and well structured source code

Features

  • Easy installable
  • Easy customizable
  • Unlock all skins
  • Multiple tactics
  • Strong documentation
  • Visual debugging
  • Real time customization through dat.GUI

Installation instructions

If you are on chrome, download the TamperMonkey extension.

On other browsers, use the GreaseMonkey extension.

Once installed, click on this, and choose Install.

Go to kartwars.io, and enjoy !

Hotkeys


















Key Result

Ctrl + B
Toggle Bot enabled/disabled
Mouse wheel Zoom in/out

Directory Contents

├── build                         # Compiled source code
├── doc                           # Generated documentation.
└── src                           # Source files.
    └── DracoolaArt.Bot.Kartwars  # Main VS project.
        ├── lib                   # Bot

🧐 Reverse Engineering the Game

The first step in creating my bot was understanding how KartWars.io worked under the hood. The game communicated with the server using WebSockets - a technology for real-time data exchange.

Using the browser's developer tools, I tapped into and monitored WebSocket traffic and identified key messages that revealed the kart's position, velocity, nearby power-ups, and other players' movements. It was like peeking behind the curtain of the game mechanics - a fascinating insight into how the arena operated.


🏎️ Teaching the Bot to Drive

Armed with this information, I wrote a basic JavaScript to control the kart’s movement. Initially, it was clumsy - the kart zigzagged, fell out of the arena, and failed spectacularly. 🥲

I called that "AI", but we all know what it actually means. 🤣

Secret Behind AI

As I refined the logic, the bot grew smarter. It prioritized moving toward power-ups and clusters of food, avoided enemies, and steered away from collisions just in time. Watching it make strategic moves was incredibly rewarding.


🎮 In-Game Power-Ups

Power-ups were the heart of KartWars.io, making the gameplay unpredictable and thrilling.

KartWars Power-Ups

Programming the bot to use these effectively added layers of strategy to the project.


🛠️ Debugging with Visual Cues

To better understand the bot’s decisions, I added visual overlays directly into the game. These overlays included lines for the bot’s current path, enemy trajectories, and avoidance zones. This real-time feedback made debugging much easier and helped fine-tune the bot’s logic.


🎛️ Adding a Control Panel

To dynamically adjust the bot’s behavior, I embedded a control panel using dat.GUI. This lightweight library allowed me to modify parameters like speed, aggression, and strategy thresholds on the fly. It also enabled toggling strategies without editing the code, speeding up experimentation.

Kartwars Bot Interface with dat.GUI


🧠 Used Techniques

Creating a bot capable of surviving and thriving in KartWars.io required several core techniques:

🛡️ Enemy Surrounding Detection

The bot analyzed enemy positions and trajectories to detect when it was surrounded.

It calculated escape routes and accelerated toward safety, steering clear of threats.

🛡️ Weapon-Based Enemy Avoidance

By identifying enemies equipped with specific power-ups, the bot created avoidance zones (polygons) around them. It avoided these zones unless it had a shield or a strong counterattack strategy.

🎯 Enemy Trajectory Prediction

The bot predicted enemy movements to dodge attacks or intercept projectiles.

For offense, it calculated precise interception paths to maximize missile hits.


⚔️ Dodge, Defend, Attack

Kartwars in Action

The bot’s ability to dodge, defend, and attack made it a formidable player. It activated shields under attack, fired missiles at vulnerable opponents, and evaded dangerous zones. With trajectory prediction and strategic power-up usage, it was able to outmaneuver human players frequently.


🤖 The Joy of Watching It Work

The most satisfying moment came when the bot began outperforming me. Watching it survive longer, climb the leaderboard, and execute strategies in real time was exhilarating. While it occasionally exhibited “bot-like” quirks, its ability to compete with real players made the effort worthwhile.


📚 Lessons Learned

Building this bot wasn’t just fun - it was an invaluable learning experience. From reverse-engineering WebSocket communications to implementing real-time decision-making, I gained skills in problem-solving, debugging, and AI logic.

Though KartWars.io is no longer available, the lessons I learned continue to shape my projects. Whether it’s a game or a complex system at work, the thrill of breaking down problems and building innovative solutions remains unmatched.


If you’ve ever tinkered with bots or automated something just for the fun of it, share your story—I’d love to hear about your experiences!

💖 💪 🙅 🚩
kmataru
Adrian Paul Nutiu

Posted on November 27, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related