예제 #1
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
    def check_hook(self):
        pos = self.pos
        key_dict = self.key_dict

        pic = cpic.pic()
        npc = []
        for i in range(1, 4):
            ptemp = cpic.pic(' ')
            ptemp.img = pic.getslice(
                slice=pos.get_rio(key_dict['np%d' % i], width=20))
            npc.append(ptemp)

        time.sleep(0.2)
        npp = cpic.pic()
        for i in range(1, 4):
            np = npp.getslice(slice=pos.get_rio(key_dict['np%d' %
                                                         i], width=20))
            cmp = npc[i - 1].compare(np)
            print(cmp)
            if cmp == 1.0:
                print("error hook state!!!")
                return self.check_hook()
            if cmp < 0.7:
                self.hook[i - 1] = 1
            else:
                self.hook[i - 1] = 0

        print("hook state:", self.hook)
        return 0
예제 #2
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def log_skill(self):
     if len(self.skill_img) > 1:
         return
     img = cpic.pic()
     st = self.key_dict['sk_st']
     pos = self.pos
     self.skill_img = []
     for i in range(st, st + 9):
         pic = cpic.pic(' ')
         pic.img = img.getslice(pos.get_rio(i, width=20))
         pic.save('pic/skill/%d.bmp' % i)
         self.skill_img.append(pic.img)
예제 #3
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
    def skill_cold_check(self):
        curp = cpic.pic()
        cursk = cpic.pic(' ')
        st = self.key_dict['sk_st']
        pos = self.pos
        if len(self.skill_img) < 9:
            return

        for i in range(st, st + 9):
            cursk.img = curp.getslice(pos.get_rio(i, width=20))
            # sim = cursk.compare(self.skill_img[i - st])
            # print("sk", i, ":", sim)
            if cursk.compare(self.skill_img[i - st]) < 0.95:
                self.skill_cdwn[i - st] = 0  # 不可使用
            else:
                self.skill_cdwn[i - st] = 1  # 可使用
예제 #4
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
    def log_face(self):
        img = cpic.pic()
        temp = cpic.pic(' ')
        st = self.key_dict['face_st']
        pos = self.pos
        self.skill_img = []
        ans = input()
        ans = ans.split(' ')
        mesh = {'0': 'b', '1': 'q', '2': 'a'}

        for i in range(st, st + 5):
            temp.img = img.getslice(pos.get_rio(i))
            tp = mesh[ans[i - st]]
            tp += str(time.time())[-6:]
            temp.save('pic/train_face/%s.bmp' % tp)
        print("face log!")
예제 #5
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def cardcolor(self):
     st = self.key_dict['card_st']
     pic = cpic.pic()
     pos = self.pos
     for i in range(st, st + 5):
         self.card[i - st] = self.clf.judge(
             pic.getslice(slice=pos.get_rio(i, width=70)))
     print('card color:', self.card)
예제 #6
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def cardface(self):
     st = self.key_dict['face_st']
     pos = self.pos
     pic = cpic.pic()
     ids = {'b': 0, 'q': 1, 'a': 2}
     for i in range(st, st + 5):
         self.face[i - st] = ids[self.clf_face.judge(
             pic.getslice(slice=pos.get_rio(i)))]
     print('card actor:', self.face)
예제 #7
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
    def detect(self, fn, w=50, thr=0.9, dtype='judg'):
        pos = self.pos
        fname = fn + '.bmp'
        idp = self.key_dict[fn]
        try:
            thr = self.thr[fn]
        except KeyError:
            pass
        pic_cmp = cpic.pic(fname)
        pic = cpic.pic(' ')
        pic.img = self.curpic.getslice(slice=pos.get_rio(idp, w))
        how = pic_cmp.compare(pic)

        if dtype == 'how':
            return how
        elif how < thr:
            return False
        else:
            print('detect-:', fn, ' !')
            return True
예제 #8
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def out_skill(self, actor, sknum):
     if actor > 0:
         actor -= 1
         sknum -= 1
         skid = 3 * actor + sknum
         if self.skill_cdwn[skid] == 0:
             print("skill", skid, "is colding..")
             return
         self.pos.click(skid)
         time.sleep(1)
         self.curpic = cpic.pic()
         self.detect_and_wait('attack')
     else:
         st = self.key_dict['master_sk']
         self.pos.click(st)
         time.sleep(0.7)
         self.pos.click(st + sknum)
         time.sleep(1)
         self.curpic = cpic.pic()
         self.detect_and_wait('attack')
예제 #9
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def detect_and_wait(self, fn, thr=0.9, w=50, jud=False):
     ct = 0
     while self.detect(fn, w, thr, dtype='judg') == jud and ct < 68:
         time.sleep(1)
         self.curpic = cpic.pic()
         if ct >= 5 and ct % 5 == 0:
             pass  # self.click('enm_blank')
         if ct == 66:
             os.system('shutdown -s -t 30')
             # pygame.mixer.init()
             # pygame.mixer.music.load('reminder.mp3')
             # pygame.mixer.music.play()
             input()
             pygame.mixer.music.stop()
         ct += 1
예제 #10
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def check_turn(self):
     # 回合数检查
     print("checking...")
     p1 = self.scene1
     p2 = self.scene2
     p3 = self.scene3
     score = np.array([0., 0., 0.])
     for i in range(3):
         p = cpic.pic(
             slice=self.pos.get_rio(self.key_dict['scene'], width=20))
         score += np.array([p.compare(p1), p.compare(p2), p.compare(p3)])
         time.sleep(0.2)
     turn = np.argmax(score) + 1
     if 0 <= turn - self.turn <= 1:
         self.turn = turn
         print("new turn:", self.turn)
     else:
         print("wrong turn:", turn)
     # 宝具检查:
     self.check_hook()
     print("checking done")
예제 #11
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def get_new_pic(self):
     time.sleep(1)
     self.curpic = cpic.pic()
예제 #12
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
 def detect_and_wait_with_click(self, fn, dst, thr=0.9, w=50, jud=False):
     ct = 5
     while self.detect(fn, w, thr, dtype='judg') == jud and ct:
         self.click(dst)
         self.curpic = cpic.pic()
         ct -= 1
예제 #13
0
파일: test.py 프로젝트: dljgs1/FGObattleAI
    # mfcDC创建可兼容的DC
    saveDC = mfcDC.CreateCompatibleDC()
    # 创建bigmap准备保存图片
    saveBitMap = win32ui.CreateBitmap()
    # 获取监控器信息
    MoniterDev = win32api.EnumDisplayMonitors(None, None)
    w = MoniterDev[0][2][2]
    h = MoniterDev[0][2][3]
    # print w,h   #图片大小
    # 为bitmap开辟空间
    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    # 高度saveDC,将截图保存到saveBitmap中
    saveDC.SelectObject(saveBitMap)
    # 截取从左上角(0,0)长宽为(w,h)的图片
    saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
    saveBitMap.SaveBitmapFile(saveDC, filename)


import time
from Wind import cpic

st = time.time()

p = cpic.pic()
ed = time.time()
print("1:", time.time() - st)

wind_capture(u'劲风版01')

print("2:", time.time() - ed)
예제 #14
0
파일: main.py 프로젝트: dljgs1/FGObattleAI
    def __init__(self, t=1):
        self.cur = 0
        self.turn = 1
        self.state = 0
        self.hook = [0, 0, 0]
        self.card = ['', '', '', '', '']
        self.face = ['', '', '', '', '']
        self.clf = SVM.SVM_clf()  # 卡色训练识别

        self.clf_face = SVM.SVM_clf()  # 脸谱训练识别
        if t:
            self.clf.train('pic/train')
            self.clf_face.train('pic/train_face')

        self.pos = cpos.pos()
        self.key_dict = {
            'fb': 48,
            'zhuzhan': 40,
            'start': 41,
            'attack': 15,
            'btres': 38,
            'swc_spd': 25,
            'next': 37,
            'scene': 54,
            'card_st': 49,
            'hook_st': 34,
            'np1': 10,
            'np2': 12,
            'np3': 14,
            'apple': 43,
            'apple_ok': 44,
            'retblank': 55,
            'master_sk': 16,
            'sk_st': 0,
            'face_st': 20,
            'manpo': 56,
            'flush': 57,
            'flush_ok': 58,
            'enm_blank': 28,
            'chouj': 59,
            'chongzhi': 60,
            'chongzhi_ok': 61,
            'chongzhi_done': 62
        }
        self.thr = {
            'next': 0.7,
            'attack': 0.3,
            'btres': 0.2,
            'swc_spd': 0.2,
            'manpo': 0.9
        }

        self.skill_img = []
        for i in range(0, 9):
            fname = 'skill/%d.bmp' % i
            pic = cpic.pic(fname)
            self.skill_img.append(pic)

        self.skill_cdwn = [1, 1, 1, 1, 1, 1, 1, 1, 1]

        self.scene1 = cpic.pic('scene1.bmp')
        self.scene2 = cpic.pic('scene2.bmp')
        self.scene3 = cpic.pic('scene3.bmp')

        self.count_time = time.time()

        self.curpic = None  # use for detect
예제 #15
0
from ML import SVM
from Wind import cpic
from Wind import cpos

import time

if __name__ == "__main__":
    clf = SVM.SVM_clf()
    pos = cpos.pos()
    st = 49
    picfile = 'pic/train'
    while 1:
        clf.train(picfile)
        pics = []
        pic_ = cpic.pic()
        for i in range(st, st + 5):
            pic = cpic.pic(' ')
            pic.img = pic_.getslice(pos.get_rio(i))
            print(clf.judge(pic))
            pics.append(pic)
        ctrl = input()
        ans = ctrl.split(' ')
        for i in range(5):
            pics[i].save(picfile + '/' + ans[i].strip() + '%s.bmp' %
                         (str(time.time())[-7:]))
예제 #16
0
pos = cpos.pos('scene/pos.txt')

while 1:
    cmd = input()
    cmds = cmd.split()
    ctr = cmds[0]
    i = int(cmds[1])
    w = 50
    if len(cmds) > 2:
        w = int(cmds[2])

    if ctr == 's':
        pic = None
        if i >= 0:
            pic = cpic.pic(slice=pos.get_rio(i, width=w))
        else:
            pic = cpic.pic()
        pic.show()
    elif ctr == 'c':
        pos.click(i)
    elif ctr == 'sc':
        f = open('clog.txt', 'a')
        f.write(i)
        f.write('\n')
        f.close()
    elif ctr == 'sp':  # save pic
        pic = None
        if int(i) >= 0:
            pic = cpic.pic(slice=pos.get_rio(i, width=w))
        else:
예제 #17
0
    def train(self,fname):
        global data, label
        self.clf = svm.SVC()
        reload(fname)
        self.clf.fit(data, label)

    def judge(self, img):
        global t_lab
        try:
            img = img.img
        except AttributeError:
            pass
        return t_lab[self.clf.predict([rgbfeature(img)])[0]]


if __name__ == "__main__":
    clf = SVM_clf()
    pos = cpos.pos(posfile='/scene/pos.txt')
    while 1:
        clf.train('/pic/train_face/')
        pics = []
        pics = cpic.pic()
        for i in range(20, 25):
            pic = pics.getslice(pos.get_rio(i))
            print(clf.judge(pic))

        ctrl = input()
        ans = ctrl.split()
        for i in range(5):
            pics[i].save('pic/train_face/' + ans[i] + '%s.bmp' % (str(time.time())[-6:]))