Skip to content

Commit

Permalink
adjusting check_if_in_battle(), adjusting _2v2_fight_loop and _1v1_fi…
Browse files Browse the repository at this point in the history
…ght_loop() to not play the same card index in a row. making deck randomization faster
  • Loading branch information
matthewmiglio committed Dec 26, 2023
1 parent e5fca51 commit dc595b0
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 759 deletions.
72 changes: 65 additions & 7 deletions src/pyclashbot/bot/deck_randomization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
check_if_on_clash_main_menu,
get_to_card_page_from_clash_main,
)
from pyclashbot.detection.image_rec import pixel_is_equal
from pyclashbot.memu.client import click
from pyclashbot.utils.logger import Logger

Expand Down Expand Up @@ -52,21 +53,17 @@ def randomize_deck(vm_index: int, logger: Logger) -> bool:
# click on deck 2
logger.change_status("Deleting deck 2...")
click(vm_index, 109, 123)
time.sleep(2)

# click on deck options
click(vm_index, 354, 480)
time.sleep(2)

# click delete deck
print("Clicking delete")
click(vm_index, 291, 305)
time.sleep(2)

# click OK
print("Clicking OK")
click(vm_index, 283, 387)
time.sleep(2)

# click empty card 1 slot
logger.change_status("Randomizing deck 2...")
Expand All @@ -77,7 +74,7 @@ def randomize_deck(vm_index: int, logger: Logger) -> bool:
# click randomize button
print("Clicking randomize button")
click(vm_index, 262, 396)
time.sleep(4)
wait_for_filled_deck(vm_index)

# click OK
print("Clicking OK to randomize")
Expand All @@ -90,7 +87,7 @@ def randomize_deck(vm_index: int, logger: Logger) -> bool:
# get to clash main
logger.change_status("Returning to clash main")
click(vm_index, 248, 603)
time.sleep(3)
time.sleep(2)

# if not on clash main, return false
if check_if_on_clash_main_menu(vm_index) is False:
Expand All @@ -103,5 +100,66 @@ def randomize_deck(vm_index: int, logger: Logger) -> bool:
return True


import numpy
from pyclashbot.memu.client import screenshot


def wait_for_filled_deck(vm_index):
timeout = 20 # s
start_time = time.time()
while time.time() - start_time < timeout:
if check_for_filled_deck(vm_index):
return True
return False


def check_for_filled_deck(vm_index):
iar = numpy.asarray(screenshot(vm_index))
pixels = [
iar[144][168],
iar[308][247],
iar[279][344],
]

colors = [
[127, 47, 6],
[163, 87, 9],
[149, 70, 6],
]

for i, p in enumerate(pixels):
# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False
return True


def check_for_selected_deck_2(vm_index):
iar = numpy.asarray(screenshot(vm_index))
pixels = [
iar[119][102],
iar[111][111],
iar[120][123],
iar[13][401],
]

colors = [
[93, 211, 249],
[94, 209, 250],
[96, 208, 252],
[21, 169, 45],
]

for i, p in enumerate(pixels):
# print(p)
if not pixel_is_equal(colors[i], p, tol=10):
return False
return True


if __name__ == "__main__":
pass
start_time = time.time()
randomize_deck(12, Logger(None))
print(time.time() - start_time)

# print(check_for_selected_deck_2(12))
Loading

0 comments on commit dc595b0

Please sign in to comment.