We’ve talked about how to automate your game in part 1 and how to build a bot with python in part 2. Now we are going to implement specific task I’ve wanted the bot to do and the difficulty I’ve encountered implementing them.

The principle and idea we talk about here can be apply to other games or even website or apps but the code itself is specific to Three kingdom online (RIP).

Problem #1: the bot don’t know if the game have focus or not.



Solution #1: take a specific section of the game that never change and validate that it’s always present.

Other possible solution: check the window in focus, check if there an external input.

My problem was that sometime I left the bot running and another site would popup or I wanted to close it but it’s keep clicking everywhere even if the game is not there. My solution was to check the logo in the top left corner and validate if it’s there each time we make a big step.


Problem #2: We need to input value from the keyboard

Example: Sending resources from your city to another city, plundering or sending troop to a location.

Solution: Use the pyWin and make keyboard input.

One of the first problem I had is that I wanted all my sub to send resources to my main or a city in development. But to do that you need to type the amount of resources to send (note that, there a way to add them via click) and enter the destination (must have an input if it’s not one of your city)

Problem #3: need different configuration between account


Example: build order, market destination, city found

Solution: load the configuration from a file.

Alternative: save and load value in a db (mysql, sqllite)

There are other issues I’ve encountered, a ui change, popup that not where it should be and other stuffs like that. But these were the mains that were really painful. Hopefully it will give you some ideas if you get the same problem.

This problem is quite recurrent and was going to be an issue if I had the time to build a bot that manage multiple account. Having a different build between account, city or having different destination depending on the city is great example. How I solve it it’s by creating a class that have the initial value and save in a file. When the bot run, it will loads that file and can modify it if needed,  this allow to remember where it was, when the last time he did a certain task. I’ve didn’t go that far but that the principle. Next video show how it use different setting.

You can’t really see it but in the previous video I’ve use the shelve, the 3 10000 for each resources come from the shelve. I’ve haven’t used them to their full potential, they could be use it to save what we send and what to send next time.

There are other issues I’ve encountered but these were the mains that were really painful. Hopefully it will give you some ideas if you get the same problem. Next article will be about all I’ve managed to do with the bot and what was missing.