From 60b8c1d7905de1ede60bbb3f99b88a590099f927 Mon Sep 17 00:00:00 2001 From: Brian Seymour Date: Sun, 27 Sep 2020 02:52:29 -0500 Subject: [PATCH] new ep --- 118/basketball.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 118/basketball.py diff --git a/118/basketball.py b/118/basketball.py new file mode 100644 index 00000000..996a5622 --- /dev/null +++ b/118/basketball.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +from ppadb.client import Client +import time +import threading + +adb = Client(host='127.0.0.1', port=5037) +devices = adb.devices() + +if len(devices) == 0: + print('no device attached') + quit() + +device = devices[0] + +ready = False +min_x = 415 +shoot_x = None + +def monitor_hoop(): + global ready + global shoot_x + + input('') + + start = time.time() + + while True: + cycle = 6.25 + delta = time.time() - start + perc1 = (delta % cycle) / cycle + + dir = 'r' if perc1 < .5 else 'l' + + perc2 = perc1 + .24 + + if dir == 'l' and perc2 > 1: + perc2 = perc2 - 1 + + if perc2 > .5: + perc2 = .5 - (perc2 - .5) + + shoot_x = min_x + perc2 * 2 * 250 + ready = True + + print(shoot_x) + + time.sleep(.005) + + + +t1 = threading.Thread(target=monitor_hoop) +t1.daemon = True +t1.start() + +while True: + if not ready: + time.sleep(.5) + continue + + device.shell(f'input touchscreen swipe 540 1600 {int(shoot_x)} 820 300')