Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

improved speed & fixed some issues #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

improved speed & fixed some issues #20

wants to merge 1 commit into from

Conversation

weeeeedy
Copy link

Implementation of multithreading to improve speed of CoinFlip and 2048.

Comment on lines +23 to +33
def notInList(results, thresholdDist, newObject):
for result in results:
if isinstance(result[1], tuple):
tupleObject = result[1]
if math.hypot(newObject[0] - tupleObject[0], newObject[1] - tupleObject[1]) < thresholdDist:
return False
else:
if math.hypot(newObject[0] - result[0], newObject[1] - result[1]) < thresholdDist:
return False

return True
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculate distance between matches to prevent multiple matches on same coin

Comment on lines +205 to +211
try:
thread = ThreadWithReturnValue(target=check_image,
args=("rc_items/gain_power.png", True, self,))
thread.start()
except:
print("Unable to start thread for checking image")
end_game(self, fail=True)
Copy link
Author

@weeeeedy weeeeedy Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creates another thread to check if "gain_power" button is visible

Comment on lines +364 to +365
if os.path.exists("imgs"):
shutil.rmtree('imgs')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent "Program was not correctly closed last time"

Comment on lines +315 to +318
for thread in threads:
result = thread.join()
if len(result) > 0:
matches.append(result)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append each found match to a list

Comment on lines +303 to +313
for template in self.coin_images:
try:
thread = ThreadWithReturnValue(target=matchTemplate,
args=(screen, template[1], template[0],))
thread.start()
threads.append(thread)
# print("starting thread " + str(i) + " for matching " + template[0])
i += 1
except:
print("Couldn't start thread " + str(i) + " for matching " + template[0])
end_game(self, fail=True)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creates one thread per template to improve the speed of matching

Comment on lines +213 to +217
while self.game_status == "running":
for i in range(8):
keyboard.press_and_release(random.choice(self.available_moves))
time.sleep(0.125)
time.sleep(0.15)
keyboard.press_and_release("page up") # to prevent errors for the thread with check image
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks if game status is still "running" (is set to "ended" if thread found the "gain_power" button)
and then pressing random button 8 times before checking status again to improve the speed

Comment on lines +168 to +181
class ThreadWithReturnValue(Thread):
def __init__(self, group=None, target=None, name=None,
args=(), kwargs={}, Verbose=None):
Thread.__init__(self, group, target, name, args, kwargs)
self._return = None

def run(self):
if self._target is not None:
self._return = self._target(*self._args,
**self._kwargs)

def join(self, *args):
Thread.join(self, *args)
return self._return
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method for thread with return value (return value will be the matches of CoinFlip)

@weeeeedy weeeeedy mentioned this pull request Jan 10, 2021
@ValoWaking
Copy link

ValoWaking commented Jan 13, 2021

whe i install requirements.txt i have some error

@weeeeedy
Copy link
Author

whe i install requirements.txt i have some error

1

ignore it.. should work tho

@MARTENBTC
Copy link

whe i install requirements.txt i have some error
1

ignore it.. should work tho

image

when i ignore it

@MARTENBTC
Copy link

can u remove the goto_games.png click when its computing
i would like to make the recapcha, but that click skips it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants