DEV Community

Cover image for ๐ŸŽ๏ธ When Bots Play Better: My Journey of Creating a Bot for KartWars.io
Adrian Paul Nutiu
Adrian Paul Nutiu

Posted on

๐ŸŽ๏ธ When Bots Play Better: My Journey of Creating a 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.


๐Ÿง  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!

Top comments (0)