๐ 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.
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. ๐คฃ
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.
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
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)