A really challenging problem!

Ask gaming related questions (AHK v1.1 and older)
User avatar
Epyxoid
Posts: 4
Joined: 12 Dec 2016, 11:20

A really challenging problem!

14 Jan 2017, 13:45

Hello everyone!

I've run into a really challenging problem which I cannot solve by myself. I want to solve a Cups and Balls game!! More specifically, I want to my script could solve it, but it's more complex than it looks like. This is how the game looks like: https://streamable.com/h9uid
I think the steps to solve this puzzle are:
  1. After click on 'Start', search for a pixel color of the diamond and determine which cup is above it
  2. Wait until the cup descends and covers the diamond
  3. Tracking that specific cup's movement until it stops moving and determine which position it is now (I don't even know if it's possible)
  4. Repeat once the previous step and wait until none of the cups are moving (or just do it these in one step)
  5. Click on the cup that hides the diamond!
I was looking for a similar problem in this forum previously, but the only one I've found is this: https://autohotkey.com/board/topic/5076 ... g-objects/ where the moving object has a specific color all the time, which isn't true in my case.

I hope someone can help me out in this one. Thank you!
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: A really challenging problem!

14 Jan 2017, 15:47

How fast does the cup and ball move on screen? I ask because commands like imageSearch use some time to search the whole screen, so you'll need to make a routine that limit the search area as much as possible. That I believe is the challenge here.

To get an idea about what I'm talking about - you can read this tread - also about making imageSearch as efficient as possible:
https://autohotkey.com/boards/viewtopic.php?f=6&t=26758
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: A really challenging problem!

15 Jan 2017, 07:15

This would be very very tricky using AHK, because once the cup goes over the ball, you have to track the motion of one object and there are 4 other identical objects.
You are going to need to examine every single frame basically, and AHK is just not geared to do that normally.
You may be able to get it done with my library CGDipSnapshot library, because this allows you to take multiple "Snapshots" of the screen. If this code is fast enough to be able to take a snapshot of every frame, you could potentially snapshot all the frames, then do the analysis after the animation has stopped.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: A really challenging problem!

18 Jan 2017, 01:22

If I was inclined to write this script, which I am not, then the approach I would take would be to not image search for the entire stump but find a little 10x10 pixel snippet of a part of the stump you want to track.
Then search for that target 10x10 image in a 100x100 area centered on the last known location.
Then in a loop continual search for the 10x10 image in a 100x100 area that is re-centered each time the 10x10 image is found.
You are searching a small area that should happen quickly and if you search it again before the object moves more than 40 pixels then you should find it. Then do the next search centered on that new target location.
Once you find it several times in the same location, then you know it has stopped moving.
You might have to play with the numbers but that is the basic theory.

You will run in to problems if the tracked object changes colors even slightly like from lighting or visual effects but this looks like a simple sprite graphic that might stay stable when moving.
More sophisticated tracking would allow for a certain amount of variation from one find to the next and take a new sample of what to look for next each time the object is found so the object could change appearance quite a bit as it moved across the screen as long as the change was gradual enough to fall within the variation allowance each search.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
Epyxoid
Posts: 4
Joined: 12 Dec 2016, 11:20

Re: A really challenging problem!

01 Feb 2017, 10:06

First of all, thank you very much the better and better advices, I really appreciate them, all of them!

But FanaticGuru, your comment is the far more helpful, thank you for you've analyzed my problem in detail. I've been waiting for that comment of yours I believe, because I was thinking of the same concept what you gave in your comment, but I didn't know if it's worth it to bother, because I wasn't sure if it's feasible. But if You, a more experienced programmer than I am, say it's worth a try, I will give it a try.
And don't you fear for me, I'm more than capable of programming this, or at least I think I can do it! :D I just didn't know how to "approach it", because I don't know AHK's performance limits in situations like that. But your comment have solved this too!

Thank you again, and have a nice day!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 52 guests