While you sleep the enemy is swinging! (c) folk wisdom
Everyone sooner or later wants to sleep. How to break away from the monitor, if you are all in battle? And then there are resources you can dig between fights. And the most annoying thing is that you lay out 120% but always, at any level, there is a person who is
behind you in terms of parameters, quality and quantity of clothes, equipment, and loyal to your pet. What to do? How to be? Write bot!
A bot (bot, abbr. From robot) is a special program that performs automatically and / or according to a predetermined schedule, any actions through the same interfaces as a regular user. That is what Wikipedia says. And this is about 20% of the iceberg, which can be called a real boat.
Consider the simplest option. Online game with automatic combat. It is also possible to search for resources between battles. In our arsenal there is a LAMP server and several bottles of beer.
In fact, we need to do a few simple steps. Enter the game and attack the enemy.
There are several implementation options. Consider one of them - CURL.
')
Let's start:
1) Login to the game.First, carefully study the form of entry. Usually there besides the login, password, checkbox “remember” there are some more hidden fields. For example, "action".
Next, run the script:
We sent our data to the game server. If everything went well, the server authorized us, returned the cookies we needed for further work and our script saved them to the file cookiefile.txt.
2) Choosing an opponentWalking through the locations of the game, we can parse the pages and choose whom to attack. You can get HTML pages as follows:
Using the file cookiefile.txt obtained from the previous example, we transmit the information about our bot to the server, and the server happily gives us a page with the choice of the enemy. On it, we select the ID (nickname, any other parameter necessary for an attack) of the enemy.
3) AttackHaving chosen the enemy, we carefully study the form for the attack. Select all hidden fields. Substitute the enemy ID in the script. We do everything as in the case of the choice of the enemy, only by substituting the values ​​necessary for the attack in the POST variables. Attack and win!
So, we have a primitive bot, which you can run on a schedule for the whole night and wake up a millionaire.
Some tips on creating "artificial intelligence":- Bot should be like a man. It should not be as accurate as a clock. Random to help you. Make different pauses between fights. Participate in the game atmosphere. Give gifts. Get resources. Go to locations.
- There may be several bots. They can log in under one account at different times and do different things.
- Carefully consider the algorithm of the movement of the bot on the game. The algorithm must provide for all possible situations, such as getting out of a battle, waiting for an event, gathering information, etc. For example, during a battle you can’t go to a mine in any way.
- Remember that the administrators of the game are also not badly baked, and everyone has known this for a long time. Watch from what IP and how often you enter the game. How a character behaves when it is controlled by you and the bot.
Good game!
Useful links:
PHP cURL:
http://php.net/manual/ru/book.curl.phpRegular expressions for parsing a page on
wikipedia