Exemple #1
0
def act(result, my=0):
    dis = gu.fetch_posx()[my] - gu.fetch_posx()[1 - my]
    if dis > 0.45:
        result = 39
    elif dis < -0.45:
        result = 42
    for i in range(8):
        oldkeystate[i] = keystate[i]
    print("", result, my)
    first_d = result // 9
    for i in range(4, 8):
        keystate[i] = first_d == i - 3
    next_d = (result % 9) // 3
    for i in range(2, 4):
        keystate[i] = next_d == i - 1
    last_d = result % 3
    for i in range(0, 2):
        keystate[i] = last_d == i + 1
    if ((first_d == 0 and last_d != 1) or (first_d == 4 and next_d == 0)):
        if gu.fetch_posx()[1 - my] - gu.fetch_posx()[my] > 0:
            oldkeystate[2] = False
            keystate[2] = True
            oldkeystate[3] = True
            keystate[3] = False
        else:
            oldkeystate[2] = True
            keystate[2] = False
            oldkeystate[3] = False
            keystate[3] = True
        if ((gu.fetch_operation()[1 - my] & 2 > 0)
                and gu.fetch_posy()[1 - my] < 0.01):
            oldkeystate[1] = False
            keystate[1] = True
            oldkeystate[0] = True
            keystate[0] = False
    # gu.write_operation(result, my)
    for i in range(8):
        if (not oldkeystate[i]) and keystate[i]:
            gu.PressKey(keysetting[my][i])
        if (not keystate[i]) and oldkeystate[i]:
            gu.ReleaseKey(keysetting[my][i])
Exemple #2
0
 def step(self, action):
     import game_utils as gu
     self.act(action)
     time.sleep(0.012)
     gu.update_base()
     pos1x, pos2x = gu.fetch_posx()
     pos1y, pos2y = gu.fetch_posy()
     char1, char2 = gu.fetch_char()
     key1, key2 = gu.fetch_operation()
     hp1, hp2 = gu.fetch_hp()
     wid, wcn = gu.fetch_weather()
     print([
         pos1x, pos2y, pos2x, pos2y, char1, char2,
         self.key_to_category(key1),
         self.key_to_category(key2), hp1, hp2, wid
     ])
     return [
         pos1x, pos2y, pos2x, pos2y, char1, char2,
         self.key_to_category(key1),
         self.key_to_category(key2), hp1, hp2, wid
     ], 0.0, False, {}
Exemple #3
0
def act(result, my=0):
    dis = abs(gu.fetch_posx()[my] - gu.fetch_posx()[1 - my])
    if dis < 0.24 and result // 9 == 3:
        result = 18 + (result % 9)
    if dis < 0.12 and (result // 9 == 2 or result // 9 == 3):
        result = 9 + (result % 9)
    for i in range(8):
        oldkeystate[i] = keystate[i]
    first_d = result // 9
    for i in range(4, 8):
        keystate[i] = first_d == i - 3
    next_d = (result % 9) // 3
    for i in range(2, 4):
        keystate[i] = next_d == i - 1
    last_d = result % 3
    for i in range(0, 2):
        keystate[i] = last_d == i + 1
    print(first_d, next_d, last_d)
    if ((first_d == 0 and last_d != 1) or (first_d == 4 and next_d == 0)):
        if gu.fetch_posx()[1 - my] - gu.fetch_posx()[my] > 0:
            oldkeystate[2] = False
            keystate[2] = True
            oldkeystate[3] = True
            keystate[3] = False
        else:
            oldkeystate[2] = True
            keystate[2] = False
            oldkeystate[3] = False
            keystate[3] = True
        if ((gu.fetch_operation()[1 - my] & 2 > 0)
                and gu.fetch_posy()[1 - my] < 0.01):
            oldkeystate[1] = False
            keystate[1] = True
            oldkeystate[0] = True
            keystate[0] = False
    for i in range(8):
        if (not oldkeystate[i]) and keystate[i]:
            gu.PressKey(keysetting[i])
        if (not keystate[i]) and oldkeystate[i]:
            gu.ReleaseKey(keysetting[i])
Exemple #4
0
 def act(self, result):
     import game_utils as gu
     my = self.my
     for i in range(8):
         oldkeystate[i] = keystate[i]
     print("", result, my)
     first_d = result // 9
     for i in range(4, 8):
         keystate[i] = first_d == i - 3
     next_d = (result % 9) // 3
     for i in range(2, 4):
         keystate[i] = next_d == i - 1
     last_d = result % 3
     for i in range(0, 2):
         keystate[i] = last_d == i + 1
     if ((first_d == 0 and last_d != 1) or (first_d == 4 and next_d == 0)):
         if gu.fetch_posx()[1 - my] - gu.fetch_posx()[my] > 0:
             oldkeystate[2] = False
             keystate[2] = True
             oldkeystate[3] = True
             keystate[3] = False
         else:
             oldkeystate[2] = True
             keystate[2] = False
             oldkeystate[3] = False
             keystate[3] = True
         if ((gu.fetch_operation()[1 - my] & 2 > 0)
                 and gu.fetch_posy()[1 - my] < 0.01):
             oldkeystate[1] = False
             keystate[1] = True
             oldkeystate[0] = True
             keystate[0] = False
     for i in range(8):
         if (not oldkeystate[i]) and keystate[i]:
             gu.PressKey(keysetting[my][i])
         if (not keystate[i]) and oldkeystate[i]:
             gu.ReleaseKey(keysetting[my][i])
Exemple #5
0
 def step(self, action):
     gu.press_key([dxk.DIK_Z])
     gu.update_base()
     act(action, self.current_act)
     while len(self.p1_keys) <= 128:
         time.sleep(0.05)
         char_data = gu.fetch_char()
         px = gu.fetch_posx()
         py = gu.fetch_posy()
         self.p1_keys.append(gu.fetch_operation()[0])
         self.p2_keys.append(gu.fetch_operation()[1])
         self.p1_positions.append(
             np.array(
                 [px[0], py[0], px[1], py[1], px[1] - px[0],
                  py[1] - py[0]]))
         self.p2_positions.append(
             np.array(
                 [px[1], py[1], px[0], py[0], px[0] - px[1],
                  py[0] - py[1]]))
         self.p1_char_acts.append(
             np.array([
                 char_data[0],
                 gu.fetch_action()[0], char_data[1],
                 gu.fetch_action()[1]
             ]))
         self.p2_char_acts.append(
             np.array([
                 char_data[1],
                 gu.fetch_action()[1], char_data[0],
                 gu.fetch_action()[0]
             ]))
     while len(self.p1_keys) > 128:
         self.p1_keys = self.p1_keys[-128:]
     while len(self.p2_keys) > 128:
         self.p2_keys = self.p2_keys[-128:]
     while len(self.p1_positions) > 128:
         self.p1_positions = self.p1_positions[-128:]
     while len(self.p2_positions) > 128:
         self.p2_positions = self.p2_positions[-128:]
     while len(self.p1_char_acts) > 128:
         self.p1_char_acts = self.p1_char_acts[-128:]
     while len(self.p2_char_acts) > 128:
         self.p2_char_acts = self.p2_char_acts[-128:]
     reward = 0
     maybe_rwd = -(self.old_dhp - (gu.fetch_hp()[0] - gu.fetch_hp()[1]))
     if self.old_dhp - (gu.fetch_hp()[0] - gu.fetch_hp()[1]) > 100:
         reward = maybe_rwd / 200.0
     elif self.old_dhp - (gu.fetch_hp()[0] - gu.fetch_hp()[1]) < -100:
         reward = maybe_rwd / 200.0
     if gu.fetch_hp()[0] > gu.fetch_hp()[1]:
         reward = 0.01
     elif gu.fetch_hp()[0] < gu.fetch_hp()[1]:
         reward = -0.01
     if gu.fetch_hp()[0] == 0 and gu.fetch_hp()[1] > 0:
         reward = -5000.0
     elif gu.fetch_hp()[0] > 0 and gu.fetch_hp()[1] == 0:
         reward = 5000.0
     if self.current_act == 1:
         reward = -reward
     self.old_dhp = (gu.fetch_hp()[0] - gu.fetch_hp()[1])
     state = None
     if self.current_act == 1:
         self.current_act = 0
         state = np.concatenate(
             (np.array(self.p2_char_acts), np.array(self.p2_positions),
              encode_keylist(self.p1_keys), encode_keylist(self.p2_keys)),
             axis=-1)
     elif self.current_act == 0:
         self.current_act = 1
         state = np.concatenate(
             (np.array(self.p1_char_acts), np.array(self.p1_positions),
              encode_keylist(self.p2_keys), encode_keylist(self.p1_keys)),
             axis=-1)
     # gu.press_key([dxk.DIK_ESCAPE])
     return state, reward, abs(reward) > 999, {}
Exemple #6
0
def play(my=0):
    en = 1 - my
    gu.update_proc()
    m.load_weights("D:/FXTZ.uu.dat")
    print("Wait For Battle Detection...")
    if (gu.fetch_status() not in [0x05, 0x0d, 0x0e, 0x09]):
        while (gu.fetch_status() not in [0x03, 0x08]):
            gu.press_key([dxk.DIK_Z])
            time.sleep(1)
        gu.update_base()
        while gu.fetch_char()[0] != 7:
            gu.press_key([dxk.DIK_LEFT])
            time.sleep(0.15)
        gu.press_key([dxk.DIK_Z])
        time.sleep(1)
        gu.press_key([dxk.DIK_Z])
        time.sleep(1)
    while (gu.fetch_status() not in [0x05, 0x0d, 0x0e, 0x09]):
        time.sleep(0.3)
        gu.press_key([dxk.DIK_Z])
    print("Battle Detected!")
    gu.update_base()
    char_act = []
    pos = []
    en_key = []
    my_key = []
    keys = [[], []]
    poses = []
    char_acts = []
    oldhp = [10000, 10000]
    while gu.fetch_hp()[0] > 0 and gu.fetch_hp()[1] > 0:
        '''if (oldhp[en] < gu.fetch_hp()[en]
                and gu.fetch_posy()[en] < 0.05
                and abs(gu.fetch_posx()[en] - 0.5) > 0.42):
            oldhp[0], oldhp[1] = gu.fetch_hp()
            gu.combo_1()
            continue'''
        oldhp[0], oldhp[1] = gu.fetch_hp()
        char_data = gu.fetch_char()
        px = gu.fetch_posx()
        py = gu.fetch_posy()
        if abs(px[en] - px[my]) > 0.4:
            if px[en] < px[my]:
                act(39, my)
            else:
                act(42, my)
            keys[0].append(gu.fetch_operation()[0])
            keys[1].append(gu.fetch_operation()[1])
            poses.append(
                np.array([
                    px[my], py[my], px[en], py[en], px[en] - px[my],
                    py[en] - py[my]
                ]))
            char_acts.append(
                np.array([
                    char_data[my],
                    gu.fetch_action()[my] / 100.0, char_data[en],
                    gu.fetch_action()[en] / 100.0
                ]))
            time.sleep(0.033)
            continue
        time_begin = time.time()
        keys[0].append(gu.fetch_operation()[my])
        keys[1].append(gu.fetch_operation()[en])
        poses.append(
            np.array([
                px[my], py[my], px[en], py[en], px[en] - px[my],
                py[en] - py[my]
            ]))
        char_acts.append(
            np.array([char_data[en],
                      gu.fetch_action()[en] / 100.0]))
        while len(keys[0]) > 30:
            keys[0] = keys[0][-30:]
        while len(keys[1]) > 30:
            keys[1] = keys[1][-30:]
        while len(poses) > 30:
            poses = poses[-30:]
        while len(char_acts) > 30:
            char_acts = char_acts[-30:]
        if len(keys[1]) < 30:
            continue
        char_act.append(char_acts[-1])
        pos.append(poses[-1])
        my_key.append(mv2.encode_keylist(keys[0], merge=1))
        en_key.append(mv2.encode_keylist(keys[1], merge=1))
        Y = m.predict([np.array(char_act), np.array(pos)], batch_size=1)[0]
        char_act = []
        pos = []
        en_key = []
        my_key = []
        category = np.argmax(Y)
        '''category1 = np.random.choice([x for x in range(5)], p=Y[0][0])
        category2 = np.random.choice([x for x in range(3)], p=Y[1][0])
        category3 = np.random.choice([x for x in range(3)], p=Y[2][0])
        category = category1 * 9 + category2 * 3 + category3'''
        category = np.random.choice([x for x in range(45)], p=Y)
        if time_begin + 0.032 > time.time():
            time.sleep(time_begin + 0.033 - time.time())
        act(category, my)
Exemple #7
0
def replay_to_data(cancel_on_title_met=False):
    print("Wait For Battle Detection...")
    time_begin = time.time()
    while (gu.fetch_status() not in [0x05, 0x0e] or gu.fetch_wincnt()[0] > 256
           or gu.fetch_wincnt()[1] > 256):
        if gu.fetch_status() == 0x02 and cancel_on_title_met:
            th123.terminate()
            return
        if not psth123.is_running():
            return
        if time.time() > time_begin + 30.0:
            return
        time.sleep(0.5)
    print("Battle Detected!")
    gu.update_base()
    hp1, hp2 = 10000, 10000
    data = []
    f = open(OUTPUT_PATH + "/" + str(int(time.time() * 1000)) + ".txt", "w+")
    f.write("P1: ")
    f.write(str(gu.fetch_char()[0]))
    f.write(", ")
    f.write("P2: ")
    f.write(str(gu.fetch_char()[1]))
    f.write("\n")
    while (psth123.is_running() and hp1 > 0 and hp2 > 0
           and gu.fetch_status() in [0x05, 0x0e]):
        hp1, hp2 = gu.fetch_hp()
        key1, key2 = gu.fetch_operation()
        pos1x, pos2x = gu.fetch_posx()
        pos1y, pos2y = gu.fetch_posy()
        act1, act2 = gu.fetch_action()
        data.append(hp1)
        data.append(round(pos1x, 4))
        data.append(round(pos1y, 4))
        data.append(key1)
        data.append(act1)
        data.append(hp2)
        data.append(round(pos2x, 4))
        data.append(round(pos2y, 4))
        data.append(key2)
        data.append(act2)
        time.sleep(1.0 / 30.0)
    if hp1 <= 0 and hp2 > 0:
        f.write("P2 Won.")
    elif hp2 <= 0 and hp1 > 0:
        f.write("P1 Won.")
    elif hp2 <= 0 and hp1 <= 0:
        f.write("Tie.")
    else:
        f.write("Interrupted Battle.")
    f.write("\n# P1 HP P1 Pos X P1 Pos Y P1 Key P1 Act; P2 etc.\n")
    if len(data) == 0:
        f.close()
        return
    for x in range(0, len(data), 10):
        for i in range(x, x + 5):
            f.write(str(data[i]))
            if i != x + 4:
                f.write(" ")
        f.write("; ")
        for i in range(x + 5, x + 10):
            f.write(str(data[i]))
            if i != x + 9:
                f.write(" ")
        f.write("\n")
    f.close()
    if gu.fetch_wincnt()[0] < 2 and gu.fetch_wincnt()[1] < 2:
        while hp1 <= 0 or hp2 <= 0:
            time.sleep(0.5)
            hp1, hp2 = gu.fetch_hp()
            if (gu.fetch_status() not in [0x05, 0x0e]
                    or not psth123.is_running()):
                return
        replay_to_data(cancel_on_title_met)