# Sikuli IDE Browser Robot for MusicWars

##### Background:

Somehow before me was the task: "I want to pump a character, but because of work there is not enough time." Immediately decided: "I'm an engineer, now we will solve the problem."
Music Wars is a new browser-based MMORPG where you have to fight for your musical preferences in a tough fight. Vivid graphics, a non-standard combat system will attract not only notorious music lovers, but also all fans of computer games.

After studying the MusicWars toy, it turned out that it, like many browser games, is made on Flash, which does not give full manipulation. There is a solution, use scripts focused on GUI programming. I decided to use sikuli thanks to the article "More about Sikuli in Test Automation" from Gulsom .

The advantage of this writing is visual objects without any programming tricks. Anyone who knows more or less notions about programming can cope with such writing. All writing with debugging took a couple of ches!

The logic itself is to search for the enemy from 2 windows. I choose a lower level and a lower force and attack if there is none, then we go out and reload the opponents and so on in a circle.

I used Region for more speed finding elements since the game occupied only half the screen.

The logic of the choice of the enemy
``````def left_open_doi(): #смотрим слева
region_left = Region(561,414,386,387)
if region_left.exists("aIE.png"): #если уровень меньше
if region_left.exists("HAI1ACIh2g.png"):
region_left.hover("Cmna.png")
if region_left.exists("1404561848539.png"):
right_open_boi()
else:
region_left.click("HAI1ACIh2g.png")
if Region(177,250,779,551).exists("1404562400404.png"):
Region(177,250,779,551).click("1404562484299.png")
sleep(0.23)
new_okno_boi()
else:
if Region(161,175,795,633).exists("Heqocrarouuo.png"):
Region(161,175,795,633).click("1404562484299.png")
else_none_boi()
else:
if Region(163,171,797,636).exists("HEAOCTBTOHH0.png"):
sleep(100)
new_okno_boi()
else:
sleep(30)
close_boi()
else:
right_open_boi()
else:
right_open_boi()
def right_open_boi():
region_right = Region(175,418,388,381)
if region_right.exists("aIE-1.png"):
if region_right.exists("HAI1ACIh2g.png"):
region_right.hover("Cmna.png")
if Region(447,499,96,22).exists("1404561848539.png"):
new_okno_boi()
else:
region_right.click("HAI1ACIh2g.png")
if Region(177,250,779,551).exists("1404562400404.png"):
Region(177,250,779,551).click("1404562484299.png")
sleep(0.23)
new_okno_boi()
else:
if Region(161,175,795,633).exists("Heqocrarouuo.png"):
Region(161,175,795,633).click("1404562484299.png")
else_none_boi()
else:
if Region(163,171,797,636).exists("HEAOCTBTOHH0.png"):
sleep(100)
new_okno_boi()
else:
sleep(30)
close_boi()
else:
new_okno_boi()
else:
new_okno_boi()
start()
``````

Closures after an attack
``````def close_boi(): #закрываем окно после боя
if Region(240,250,652,320).exists("QBuxcn.png"):
Region(240,250,652,320).click("QBuxcn.png")
new_okno_boi()
else:
click(Location(555,484))
Region(237,253,652,311).click("1404559699899.png")
if Region(183,266,767,547).exists("Floanpanrmen.png"):
Region(183,266,767,547).click("1404562484299.png")
Region(240,250,652,320).click("QBuxcn.png")
new_okno_boi()
else:
sleep(0)
Region(183,266,767,547).click("QBuxcn.png")
sleep(10)
new_okno_boi() #после закрытия подготавливаем к новым боям
``````

Window change if there are no suitable opponents
``````def new_okno_boi():
Region(411,279,155,100).click("1404557642674.png")
if Region(177,306,378,486).exists("BUKBAJI.png"):
Region(195,412,201,102).click("BUKBAJI.png")
sleep(0.10)
Region(736,627,220,179).hover("1404582245445.png")
sleep(2)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
if Region(181,253,142,41).exists("BVITBA.png"):
left_open_doi()
else:
sleep(0.10)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
Region(175,306,770,489).click("1404547957758.png")
left_open_doi()
else:
if Region(216,326,149,128).exists("DBOPbI.png"):
Region(188,310,190,151).click("DBOPbI-1.png")
Region(736,627,220,179).hover("1404582245445.png")
sleep(2)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
if Region(181,253,142,41).exists("BVITBA.png"):
left_open_doi()
else:
sleep(0.10)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
Region(175,306,770,489).click("1404547957758.png")
left_open_doi()
else:
if Region(376,313,125,121).exists("KOCTEFI.png"):
Region(373,313,127,108).click("KOCTEFI-1.png")
Region(736,627,220,179).hover("1404582245445.png")
sleep(2)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
if Region(181,253,142,41).exists("BVITBA.png"):
left_open_doi()
else:
sleep(0.10)
Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20))
Region(175,306,770,489).click("1404547957758.png")
left_open_doi()
``````