Yesterday, I’ve wrote a piece on how I’ve tried to automate my TKO account with various extension, tools and even code. Today, I’ll explain how I went from the basic foundation laid out by the sushi go round bot tutorial to build my TKO bot. Everything here can be use to build your own bot for your game.

Reasons I love futurama - Ascent of bot (with the spring being Bender's invention)

“Sushi go round” bot basic

From the tutorial I’ve referenced in my last post, I explained how the author used python to make is bot and what inspired me from his post to make mine.

Note what will follow requires a basic understanding of programming. If you want more info on that let me know or check out the free python beginner book: Dive Into Python

[Dive Into Python]

The basic principle of the bot in the tutorial is to get the image on the screen and analyze them, from there the bot react from what he analyzed.

This is the most important thing I’ve got from that tutorial. Using the python imaging library & numpy to get the image and use what he (the bot) captured on the screen to make a decisions.

Other point to get started is to use paint.net (or another image program with ruler) to get positioning in the image of the item that needed to be analysed. PyWin is another important librairy to take care of the reaction of the bot by providing him some way to interact with the screen with the mouse pointer and some keyboard input.

The first step to create your bot

Your first step to create your bot is getting a screen grab of the game to know what is the boundary of your game are. Once you got the screen grab with the game on it, you open the image in an editor like Paint.net and check the position of where the game start on the screen (in pixel from the upper left corner of the screen ) to where the section of the screen you game end (the lower right corner). With these coordinate, you will be able to concentrate only on the section of your game and if it move you just have to get them again it’s shouldn’t impact your coordinate in game since they will be relative.

Second step: entering the game and/or decide your starting state.

Once you got where your game is in the screen, you need to have a starting state for your bot. It can be the start screen of the game and have a little routine to get in it like sushi go round or start from a state you are often in like in the resource screen of your main city. You’ll probably need to have a routine to go back there so you can easily make your bot shift between task. That kind of backtracking is useful in complex game like Tko but unnecessary for game simple has sushi go round.

Third step: Creating the first task for your bot.

In sushi go round the tutorial show how to find what sushi are being ordered by the customer and prepare them from the ingredient. For Tko there is more option, there so much that can be done, you can make your bot build your city, maybe just collect your daily reward, perhaps upgrade armor or just find those damn 15 farm field on the map. I’ve started by making a task to upgrade weapon, armor and speed (valor camp). These three task have a similar layout and since the same image is used for each upgrade everything needed to be coded only once. The three building can be found at the same place too,  through the menu next to your ruler portraits even if you don’t put them in the same place in every city.

From here you should be able to do almost anything you want. If you’re having a hard time, go revisit the basic that can be found in the sushi go round example and check out some good python free course or book. The next part will be more in deep of the problem I’ve encountered. I’ll show you I went a little further in the bot, by including keyboard input, by using a configuration in a file depending on the user I’m running the bot with or how to save the value you found like where are the 15f.

If you want to files let me know in the comment, l’ll send them to you.

After the merge of 2014, my server has lost and my main was brutally destroyed, I basically dropped from the game with a RIP message 2009-2014.

dong zhuo city

When I saw the sea of attacking coming at my other cities I decided, ‘No’ I can’t give up without a fight. I save most of my cities and kill around 30 lobbyist, thousand of demo. I was offered to join a sub league or be annihilated. I thought about it and chose the league.

Evil Laugh

After a few months in, I’ve decided to put my account to good use and learn a bit. I’ve decided to see how I could make my account automated at least reduce the amount of work to do. I’ve thought about doing it for other game too, but I usually get bored before doing it.

Finding the tech

1-Grease monkey

I’ve talked about the three kingdom online grease monkey script in the past  but the script wasn’t working anymore and was not maintain. I’ve try to understand what going on and modify it but it’s end up not doing what I wanted.

2-Autofill extension for firefox

I’ve found that great extension in firefox called autofill where you can save a form and it’s value. You can recall the value when you want. I used it for the market place but could have been used for the deployment screen too.

Here a quick video how I’ve used it:

3-Selenium IDE Extension

Selenium record what you’re doing and then try to reproduce it exactly. I’ve played a bit with that one but the way TKO was set up sometime event or call where missing or not needed, making selenium not going to the next screen and then it’s tried to do what it was supposed to do in the next screen but in the current screen. What the mess, I’ve drop it after a few try, but could probably work with some tweaking.

4-Autohokey

AutoHotkey (AHK) is a free, open-source macro-creation and automation software for Windows that allows users to automate repetitive tasks.

This one seem to be use a lot for bot, basically you write a simple script and inside tell it where to click. It has some power, I’ve used it to do the governor work. See it in action for one loop, but the real script was running it 10 time in a loop to max the potential popularity each day.

You can download it here and if you want my autohotkey file let me know.

5-Python

After a bit of research I’ve found a tutorial of a guy using a python script to play sushi go round. Click on sushi to get the article.

This is when my bot was born, I’ve used the principles in the tutorial and applied it to TKO instead.

 

Disclaimer: there are other thing I could check, like using fiddler to get the request and try to spoof them, use a mix of a python proxy to do that with a combination of the bot I ended doing. It’s not the most efficient way but looking at what happening on the screen and reacting to it is the best way to avoid being flag has a bot, because in the end the bot is doing the same thing you’ll be doing.

I’ve you used a bot or some tool to help you play let me know I’ll love to hear what you’ve done.