민서네집

[Python][PyCon 2016] 가위바위보 소스 본문

Python

[Python][PyCon 2016] 가위바위보 소스

브라이언7 2016. 8. 14. 19:41

코딩배틀 가위바위보 in 파이콘 2016 APAC


http://tech.kakao.com/pycon2016apac/


https://www.facebook.com/seokjoon.yun.9/posts/1115414945195627


https://www.facebook.com/seokjoon.yun.9/posts/1115845348485920


윤석준 님 소스


import random
from collections import defaultdict

def get_index(probabilities):
    max = sum(probabilities)
    
    acc = 0
    rand = random.random() * max
    for idx, percent in enumerate(probabilities):
        acc += percent
        if rand < acc:
            return idx
    return len(probabilities)

GBB = ['gawi', 'bawi', 'bo']

def show_me_the_hand(records):
    
    index = 0
    
    if len(records) == 0:
        index = get_index([1,1,1])
    else:
        enemyChoice = defaultdict(int)
        #enemyScore = defaultdict(int)
        
        for hand, score in records:
            enemyChoice[hand] += 1
            #enemyScore[hand] += 1
            
        reference = [enemyChoice['bo'], enemyChoice['gawi'],enemyChoice['bawi'] ]
        index = get_index(reference)
        
    return GBB[index]

if __name__ == '__main__':
    records = []
    print(show_me_the_hand(records))
    print(show_me_the_hand([('gawi',1), ('bo',1)]))
    


player.py
Comments