def main():
    last_time = time.time()
    for i in list(range(5))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False
    while (True):

        if not paused:
            # 800x600 windowed mode
            screen = np.array(ImageGrab.grab(bbox=(0, 30, 1280, 745)))
            # print('loop took {} seconds'.format(time.time()-last_time))
            last_time = time.time()
            # screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
            screen = cv2.resize(screen, (224, 224))
            action_probs = model.predict([screen.reshape(1, 224, 224, 3)])[0]
            # To prevent very low probs from taking over
            # and going into infinite loop
            # print(max(action_probs))
            if max(action_probs) > 0.3:

                moves = list(np.around(action_probs))
                # print(moves)

                if moves == [1, 0, 0, 0, 0, 0]:
                    print('left')
                    left()
                elif moves == [0, 1, 0, 0, 0, 0]:
                    print('front')
                    front()
                elif moves == [0, 0, 1, 0, 0, 0]:
                    print('right')
                    right()
                elif moves == [0, 0, 0, 1, 0, 0]:
                    print('back')
                    back()
                elif moves == [0, 0, 0, 0, 1, 0]:
                    print('attack')
                    attack()
                elif moves == [0, 0, 0, 0, 0, 1]:
                    print('superattack')
                    superattack()

        keys = key_check()

        # p pauses game and can get annoying.
        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                ReleaseKey(S)
                time.sleep(1)
    def _isDone(self):
        isDone = self.ScreenProcessor.isDone()
        if isDone:
            # print('Restarting game after timestep: {}'.format(self.time_step))
            # Reset the game
            w.find_window_wildcard(
                "雷电模拟器")  # Note: The android simulator of your choice
            w.set_foreground()
            PressKey(B)
            time.sleep(0.3)
            ReleaseKey(B)
            time.sleep(3)
            PressKey(B)
            time.sleep(0.3)
            ReleaseKey(B)
            time.sleep(5)  # Wait for game to begin
            for i in range(30):
                PressKey(B)
                time.sleep(0.1)
                ReleaseKey(B)

        return isDone
def superattack():
    PressKey(Q)
    time.sleep(0.05)
    ReleaseKey(Q)
def back():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
    PressKey(S)
def right():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(S)
    PressKey(D)
def left():
    ReleaseKey(W)
    ReleaseKey(D)
    ReleaseKey(S)
    PressKey(A)
def front():
    ReleaseKey(A)
    ReleaseKey(D)
    ReleaseKey(S)
    PressKey(W)
def releaseAllKeys():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
    ReleaseKey(S)
def attack():
    PressKey(E)
    time.sleep(0.05)
    ReleaseKey(E)