Help to make a bot

Asked by maestroarte

Good morning guys ^^'
I want to create a bot for a game
This bot have to:
-Wait for the monster in the map (there is only one monster) and when the monster appeare, the bot have to click on this monster, and click to the ready button
but, some other players can attack the monster first =/ So, the monster dissapear for x seconds...
this is the begin of the code

click(monster)

if not Region(-13,-13,12,12).exists(gun ,10):
          click(monster )
(the gun appeare only if my character lauche an attack, so, if the gun doesn't appear after the click on the monster, it mean that an other player click on the monster)

but the rest of the code is to difficult for me =/
Can someone help-me? (sorry for my very bad english =/)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

What game?

Without having some idea of the playground and the dynamics, there is no chance for efficient help.

--- comments on Region(-13,-13,12,12).exists(gun ,10)

- Region(-13,-13,12,12)
is outside the screen. if you mean "left above" of something else, you need a reference to the base region.

- exists(gun ,10)
this waits 10 seconds for the gun to appear. During this time, your script will just do nothing.

while not exists(gun,0): # comes back directly after the search
     # do something else
     wait(1)

allows you to check something else and may be act on during the time, the gun is not there.

This is some kind of "poor man's subprocessing". If you really want to be able to react on the most important things happening, you have to implement different specialized bots, that run in parallel as subprocesses and talk to each other.

Revision history for this message
maestroarte (martin-dupuis41) said :
#2

Okay, i will try to be more accurate:
This game is dofus
I want a bot for make the same dunjeon
(a dunjeon is:
first you give the key at one png, second, you have to beat one group of monsters to come to the next room, and there are ten room)

I solve the problem that i told you at the beginin: (we suppose that i am in the first room, with a monster name monster A)
code:

if not exists(monsterA): // if the monster isn't yet in the room
          while not exists(monsterA):
                          wait( monsterA,20) //we wait for it :)
                          break
click(monsterA) //monster A appear! :) let's go fight
if not exists(readybutton): //if the ready button is not present, it mind that an other player attack the monster A before me
          while not exists(buttonready):
                          wait(monsterA,20) //the repop of the monsterA is 20 second
                          click(monsterA)
                          break
click(buttonblockcombat) // the other player can't join the combat
click(buttonready) // begin the fight!!

but, i think that i arrive to the must problem ever!!
i explain! (it's very very difficult)
the monster A is not static!! he moves!! So, if i told to the program to click on monsterA, some times, the program doesn't recognize him, because the monster has moven!! Oo
And, monsters in this game can change orientation!!they can be in front of you, the can be back of you, the change orientation! =/
SO, i think that a screen can't find where is exactly the monster =/

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Ok, understood.

I already had a look at dofus for another guy earlier this year. I think I still have a registration. (Sorry, but I am not a gamer :-(

As you described: it is rather challenging to track, what is happening on the playground.

I will have a look at it and come back tomorrow sometimes during the day, to tell you wether and how I can help you.

BTW: It would help to know, what your programming skills/experiences are.

Revision history for this message
maestroarte (martin-dupuis41) said :
#4

Okay thanks Rai :) (if you want, i explain you how play at dofus ^^')
I have only 16 years, ^^' and with the school i don't have many time for programming, but, i program with TI Basic for one year (on TI 82 Stats.fr and TI Nspire Cx Cas), the Ti Basic works with:
If condition
....
End (i don't know where is the "end" in Sikuli, i think that "break" is like "end" but it works only with "while" =/)
In TI Basic you have also:
AND
OR
ELSE
GOTO -> LBL (i don't find these function in Sikuli, perheaps they don't exist)
These function are like the functions in Sikuli, so i don't have many problems to program with sikuly
I discover Sikuli on Sunday, and i love it :) but now, i don't know if, as you say Rai, if Sikuli can know what is happening on the playground

Why i want a sikuli bot? Because i am on Mac, an the famous language Autoit, for create bots, is only for windows =/
What i propose:
Sikuli can find, i think, what elements moves in the map but:
- There are monsters but, also, players who moves in the map

Sikuli can find elements who deseappear of the map but:
The monster dessapear when there are in a combat (for x seconds, the "repop" time)
The players who disconnect dissapear of the map
The player who enter in the combat dessapear of the map (they enter in the fight)

(same thing for the elements who appear on the map)

it's very difficult....i know, but, is-it impossible? :p

thanks you rai for your help! :)
(and sorry for my english =/)

Revision history for this message
Best RaiMan (raimund-hocke) said :
#5

Ok, I had a look at the game and especially at the possibility to make a bot for the combat situations.
And I remember the situation earlier this year: it was the combat with gobblies.

conclusion again:
No, it is not possible
- you have to decide and select a weapon/spell (some are not available, exhausted in that turn or do not have any effect for the target)
- you have to check, wether the target can be reached with the selected weapon
- you have to decide wether it makes sense to move and then do it
- you have to track the time of the turn and realize, when a turn ends and a new one starts
- you have to track the target (did it move? at least at the end of the turn it moves)
- It gets even more complicated, if you have a group of targets (which of them should be attacked first)
- ... and some more aspects

Even if you use the grid in Sikuli, to restrict the regions to process, all the checks you have to make before and after an action will take some time (e.g. as an average a search in a small region of 100x100 costs about 0.2 seconds: If you have to check, wether the target has moved, this will cost you 2 to 5 seconds).

To get an acceptable performance, you have to invest massively into multitasking, which results in complex programming.

So again I have to say: If you are a trained player, you will be able to do the combat in the same time as it would be with a Sikuli script (in which you invested a huge amount of time before and it will never be perfect) and you can only sit in front and do nothing else during the time the script runs. So what is the benefit?

I herewith close my activities on this subject.

Revision history for this message
maestroarte (martin-dupuis41) said :
#6

Okay =p
But, Dofus is a stupid game :p
I know how monsters (of the dungeon that i told you) moves
I need only that Sikuli click on the monster, after, the spells and other is not a problem at all!
I create a sort of algorithm for all the combat that i have to do in this dungeon! (click on that speel and on that region of the map ect... ^^")

Can you think that Sikuli can find a monster (who moves on the map)?

Revision history for this message
RaiMan (raimund-hocke) said :
#7

Yes, dofus might be a stupid game, but looking at it from the graphics standpoint, it is rather complex: each moveable figure has at least 4 different shapes (one for each direction). And figures might overlap, which is very hard to discover with a script.

So I think, it is very hard and time consuming, to follow/find a figure, that is moving (but may be possible).

Again, I doubt, that the effort you have to invest into a really supporting script will ever pay back.

But you are always welcome, to come back if you have any specific Sikuli questions on the road. And I will always be willing to have a look into one of your scripts - just send me your zipped .sikuli using the mail at https://launchpad.net/~raimund-hocke.

Revision history for this message
maestroarte (martin-dupuis41) said :
#8

Hello Rai, i have a question
I decide to make a dofus farmer bot, it is less difficult!
I finish my code :) but...i have a lot of problem with indentation =/
Can you explain me how use indentation whith "while" please =)
And, can you explain me when we have to use "pass" and "break", is it the same thing?
Thanks!

Revision history for this message
RaiMan (raimund-hocke) said :
#9

Hi Martin,

I used this question to finally write an indentation faq 1800

To understand break and continue, have a look at faq 1437

when you have your farmer bot running, I would be interested to have a look at it. If you agree, send the stuff as zip file to my mail at https://launchpad.net/~raimund-hocke.

all the best

Revision history for this message
maestroarte (martin-dupuis41) said :
#10

Rai! I find the good indentation for while! :) thanks
But, the program farm only one box of corn, cause i am afraid to be in wrong if I continue...
If I join you the program A (the first program who farm only one corn) and the program B (the pictures of the other box of corn to farm), can you, please, because you are an expert and you make no mistakes ^^', continue my initial code, and insert in the program A, the program B without indentation error? ^^' (i'll tell you where you have to put it^^')
And, I have also and other question for you ^^' This is my program!:

click(A) // A is the Dofus Icon on my desktop
while not exists(B): // B is a green message that told that you can't farm corn because you are full
                 if exists(C): // C is one bow of the corn in a map (we call the map Z)
                 click(C)
                 sleep(13) // we wait the time that the farmer fam the box ^^'
else:
              if exists(B): // If the message appear, my avatar have to go in the bank
                 click(D) //He follow the road that i told him to do ^^'
                 wait( ,20)
                 click(E)
                 wait( ,20)
                 click(F)
                 wait( ,20)
                 click(G )
                 wait( ,20)
                 click(H)
                 wait( ,20)
                 click(I)
                 wait( ,20)
                 click(J)
                 wait( ,20)
                 click(K)
                 wait( ,20)
                 click(L)
                 wait( ,20)
                 click(M)
                 wait( ,20)
                 click(N)
                 wait( ,20)
                 click(O)
                 wait( ,20)
                 click(P)
                 wait( ,20)
                 click(Q)
                 wait( ,20)
                 click(R)
                 wait( ,20)
                 click(S)
                 wait( ,20)
                 click(T)
                 wait( ,20)
                 click(U)
                 wait( ,20)
                 click(V) // My avatar arrive in the bank
                 dragDrop( , ) // He take the corn, and he put it in the bank
                 click( ) // Now he return at map Z
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( )
                 wait( ,20)
                 click( ) // He is in map Z
                 find(X) // X is the tchatbox
                 click(X)
                 type("c'est long" + Key.ENTER) //My avatar have to talk alone 6 times , for make diseappear the green initial message
                 sleep(3)
                 type("c'est long" + Key.ENTER)
                 sleep(3)
                 type("c'est long" + Key.ENTER)
                 sleep(3)
                 type("c'est long" + Key.ENTER)
                 sleep(3)
                 type("c'est long" + Key.ENTER)
                 sleep(3)
                 type("c'est long" + Key.ENTER)
                 sleep(3)

Now my question: After that my avatar talk alone, he have to restart the programm (he have to restart to farm corn)
Does I have to rewrite the same code behind this code? Or there is some function in Sikuli who can do this sort of thing?
Now, i telle you where, if you accept, you have to put the other box of corn
we suppose that we have 10 boxes of corn who are name 1-2-3-4-5-6-7-8-9-10, I have to put this things just like this:

click(A)
while not exists(B):
                 if exists(C):
                 click(C)
                 sleep(13)
                 if exists(1):
                 click(1)
                 sleep(13)
                 if exists(2):
                 click(2)
                 sleep(13) // and so on, and so on (i will send you the patterns 1 at 10, do you accept to help me? ^^')

Thanks a lot! :)

Revision history for this message
RaiMan (raimund-hocke) said :
#11

Uuups, many lines of code, that hide the logic behind it.

as far as I understand, this is the basic structure:

while True:
     next_box = something_to_do()
     if not next_box: break # this will end the loop
     if message_you_are_full():
           go_to_bank_and_come_back()
     farm_next_box(next_box)

to make this clean, compact and manageable we use functions:
(which is called modular programming)

(these functions have to be put at the beginning of the script before the while)

def something_to_do():
    pass
    # return the next box to work on
    # your C and 1 ... 10
    # else return None, which ends the whole process

def message_you_are_full():
    pass
    # check for message
    # return True if there
    # False otherwise

def go_to_bank_and_come_back():
    pass
    # the long way to bank and back

def farm_next_box(net_box):
    pass
    # farm on next_box