V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
hard2reg
V2EX  ›  Python

使用第三方 API 写了个 LOL 演员识别器

  •  
  •   hard2reg · 2016-05-25 10:50:18 +08:00 · 3499 次点击
    这是一个创建于 2894 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # -*- coding:utf-8 -*-
    
    import daiwan
    import time
    
    class Actor(object):
    
        def __init__(self, name, area):
            self.ranks = []
            self.name = name
            self.area_id = areas[area]
            tmp = daiwan.getUserArea(self.name)
            for x in tmp['data']:
                if x['area_id'] == self.area_id:
                    # 1 钻石 6 大师 0 王者
                    if x['tier'] in (1, 6, 0):
                        self.qquin = x['qquin']
                    else:
                        print('\n 测试版本只允许分析钻石以上段位!')
                        input()
                        exit()
                    return
            print('\n 玩家 ID 不存在!')
            input()
            exit()
    
    areas = {}
    judgements = ['挂机局', '浪输局', '甩锅局']
    
    def init():
    
        daiwan.init('API 账号', 'API 密码')
        daiwan.getToken()
        tmp = daiwan.getArea()
        for x in tmp:
            areas[x['name']] = int(x['id'])
    
    def isActor(name, area):
        jd = 0
        person = Actor(name, area)
        print('\n 分析中 0%', end='\r')
        p = 1
        while True:
            tmp = daiwan.getCombatList(person.qquin, person.area_id, p)
            for x in tmp:
                if x['game_type'] == '4' and x['game_mode'] == '4':
                    person.ranks.append(x)
            if len(person.ranks) >= 10:
                break
            else:
                p += 1
        players = {}
        b = 0
        i = 0
        all = len(person.ranks)
        for combat in person.ranks:
            i += 1
            tmp = daiwan.getGameDetail(person.qquin, person.area_id, combat['game_id'])
            time.sleep(0.5)
            for player in tmp['data'][0]['battle']['gamer_records']:
                if combat['result'] == '胜利' and player['winclass'] == 'active' and player['qquin'] != person.qquin:
                    if player['name'] not in players:
                        players[player['name']] = 1
                    else:
                         players[player['name']] += 1
                elif combat['result'] == '失败' and player['winclass'] == 'active':
                    if player['name'] not in players:
                        players[player['name']] = 1
                    else:
                        players[player['name']] += 1
            if combat['result'] == '失败' and combat['judgement'] in judgements:
                b += 1
            percent = (i / all) * 100
            print('分析中 %d%%' % percent, end='\r')
        a = max(players.values())
        rate = (a * 0.02 + b * 0.01) * 100
        print('%s 是演员的可能性为 %d%%' % (person.name, rate))
    
    init()
    print(
        '''
        =======================================================
        
                            LOL 演员识别器
                
                本程序采用作者自创的非科学算法,纯属娱乐!
                
        =======================================================
        '''
    )
    name = input('请输入玩家 ID :')
    area = input('请输入玩家所在大区:')
    isActor(name, area)
    input()
    

    识别算法是自己瞎编的。。。新手,感觉自己的代码有点乱。。

    11 条回复    2016-05-26 10:20:05 +08:00
    yanchao7511461
        1
    yanchao7511461  
       2016-05-25 12:20:34 +08:00
    识别模型很关键
    lunaticus7
        2
    lunaticus7  
       2016-05-25 12:39:34 +08:00
    少侠是学 java 出身吧^_^
    cjyang1128
        3
    cjyang1128  
       2016-05-25 12:40:47 +08:00
    哪过第三方 API
    hard2reg
        4
    hard2reg  
    OP
       2016-05-25 13:04:22 +08:00
    @cjyang1128 百度 “带玩游戏平台”。不能多说了,有推广嫌疑。。。
    hard2reg
        5
    hard2reg  
    OP
       2016-05-25 13:04:31 +08:00
    @lunaticus7 何以见得
    gkiwi
        6
    gkiwi  
       2016-05-25 14:27:55 +08:00
    青铜的怎么办!
    hard2reg
        7
    hard2reg  
    OP
       2016-05-25 14:31:08 +08:00
    @gkiwi 因为钻石以上的人少,所以会“比较准”。
    changwei
        8
    changwei  
       2016-05-25 18:43:31 +08:00
    腾讯 TGP 啊,某玩游戏盒子啊不知道他们是什么算法检测的
    cjyang1128
        9
    cjyang1128  
       2016-05-25 22:20:47 +08:00
    alittletrain
        10
    alittletrain  
       2016-05-26 08:35:41 +08:00
    @hard2reg 请教哪个平台的 api ?
    hard2reg
        11
    hard2reg  
    OP
       2016-05-26 10:20:05 +08:00
    @alittletrain 见 4L ,我已经说了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2861 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:18 · PVG 15:18 · LAX 00:18 · JFK 03:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.