improved speed & fixed some issues#20
improved speed & fixed some issues#20weeeeedy wants to merge 1 commit intovap0r01:masterfrom weeeeedy:enhancement
Conversation
| 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 |
There was a problem hiding this comment.
calculate distance between matches to prevent multiple matches on same coin
| 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) |
There was a problem hiding this comment.
creates another thread to check if "gain_power" button is visible
| if os.path.exists("imgs"): | ||
| shutil.rmtree('imgs') |
There was a problem hiding this comment.
prevent "Program was not correctly closed last time"
| for thread in threads: | ||
| result = thread.join() | ||
| if len(result) > 0: | ||
| matches.append(result) |
There was a problem hiding this comment.
append each found match to a list
| 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) |
There was a problem hiding this comment.
creates one thread per template to improve the speed of matching
| 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 |
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
method for thread with return value (return value will be the matches of CoinFlip)
|
whe i install requirements.txt i have some error |
|
can u remove the goto_games.png click when its computing |


Implementation of multithreading to improve speed of CoinFlip and 2048.