emiln / cljck

An OS-agnostic Clojure library for automating keyboard and mouse actions.
GNU General Public License v3.0
5 stars 0 forks source link

Locate upper-left corner of ClickerHeroes window #19

Closed emiln closed 8 years ago

emiln commented 9 years ago

It would be great to have the bot locate the upper left corner of the Clicker Heroes window. This would allow movement commands relative to the inside of the game frame. I imagine the commands [:relative-move-to 100 100] and [:absolute-move-to 100 100] to replace the current [:move-to 100 100].

emiln commented 9 years ago

What's preferable, come to think of it: pixel coordinates inside the window or a percentage of the width and height? The former avoids issues of precision, while the latter scales obviously to different resolutions. I would really like to have both properties. My 4k monitor allots twice the amount of pixels in both directions for the game window due to high-DPI scaling compared to a regular monitor, and ideally a script should work flawlessly on both.

All of the above pertains to relative coordinates of course.

emiln commented 9 years ago

I think it is preferable to work with pixels, so perhaps a sort of "normalized pixel" coordinate is tolerable to work with. You'll use coordinates as if the window was scaled normally, and the bot will know how to scale the coordinates to possibly bigger or smaller actual game windows. I can't think of a better way of doing it at this point.

emiln commented 8 years ago

After some deliberation and a chat with @PoliGamiOn, I'm actually leaning towards a percentage-based solution again.

emiln commented 8 years ago

Some thoughts on actually finding the game window's borders:

Take a screenshot and pick n random coordinates within it.

  1. Calculate the fitness of each coordinate. If the best coordinate has optimal fitness, assume we've found the point we're looking for and stop.
  2. Pick the n/3 best coordinates so far ranked by fitness + n/3 random coordinates + mutations of the n/3 best coordinates. Repeat 1.

An idea for fitness could be the following:

Sample both a horizontal and vertical line centered on the pixel and see how many pixels match the background color of the area around the game window. The contributes positively to fitness.

Sample the pixels below and to the right of the pixels. These should not match the background color above.

Assuming we find a pixel of optimal fitness, it should be the pixel next to the top left corner of the game window. From here it should be easy to trace the outline of the game window.

emiln commented 8 years ago

The approach described above almost works. When hitting the left side of the game window border, however, there is no increase in fitness by moving slightly up towards the upper left corner, so the generations don't gravitate towards the corner. They remain somewhere on the left border unless you're really lucky. Fitness should have added how many pixels down there's a game window to the immediate right of the coordinate, perhaps.

emiln commented 8 years ago

This is proving a fairly large task, which is something I by no means have the time for at the moment. I'm closing this for now due to lack of time.