自用组帧工具
栏目:互联网时间:2014-09-06 22:45:15
#coding:utf-8
BUTTON = 'button' # 庄稼?????
L_BLIND = 'little_blind' # 小盲注
B_BLIND = 'big_blind' # 小盲注
SEAT = 'seat'
HOLD = 'hold' # 手牌
ASK = 'ask' # ?????
FIRST= 'first' # 第一次发三张牌 ?????
TURN = 'turn' # 转牌
RIVER= 'river' # 河牌
ACT = 'act'
# ????
HEI = 'hei'
HONG = 'hong'
MEI = 'mei'
FANG = 'fang'
LITTLE_BLIND_MONEY = 500
START_MONEY = 8000
START_BET = 2000
input_info = [
(SEAT, 2, 0), # 共2人,我是第0位,0位表示庄稼
(HOLD, [(HEI, 'A'), (HEI, 'K')]),
(ACT, [0,]), # -1=放弃, 0=让(或跟), n=加n注
(FIRST, [(HEI, 'Q'), (HEI, 'J'), (HEI, '10')]),
(ACT, [0, 1]),
(TURN, [(HONG, '2'), ]),
(ACT, [0, 1]),
(RIVER, [(FANG, '3'), ]),
(ACT, [0, 1]),
]
def analyse_SEAT(one_info):
person_cnt = one_info[1]
my_seat = one_info[2]
core = ''
for i in range(person_cnt):
if my_seat == i:
pid = 3001
else:
pid = 9001+i
if i == 0:
extra_info = BUTTON
elif i == 1:
extra_info = L_BLIND
elif i == 2:
extra_info = B_BLIND
else:
extra_info = ''
this_line = '{0} {1}: {2} {3}
'.format(extra_info, pid, START_BET, START_MONEY) # ??????
core += this_line
return SEAT+'/
'+ core +'/'+SEAT + '
'
def analyse_HOLD(one_info):
'''
hold
HEI 10
MEI 9
hold
'''
body_info = one_info[1]
return '''{0}
{1} {2}
{3} {4}
{0} '''.format(HOLD,
body_info[0][0], body_info[0][1],
body_info[1][0], body_info[1][1],
)
def analyse_FIRST(one_info):
body_info = one_info[1]
return '''{0}
{1} {2}
{3} {4}
{5} {6}
{0} '''.format(FIRST,
body_info[0][0], body_info[0][1],
body_info[1][0], body_info[1][1],
body_info[2][0], body_info[2][1],
)
def analyse_TURN(one_info):
body_info = one_info[1]
return '''{0}
{1} {2}
{0} '''.format(TURN,
body_info[0][0], body_info[0][1],
)
def analyse_RIVER(one_info):
body_info = one_info[1]
return '''{0}
{1} {2}
{0} '''.format(RIVER,
body_info[0][0], body_info[0][1],
)
# ?????
def get_pid(i):
return 9001 + i
def analyse_ACT(one_info):
'''
ASK
9001: 0 8000 500 call
total: xxxx
ASK
'''
core = ''
for i,itm in enumerate(one_info[1]):
if 0 == itm:
extra_info = 'check'
pay = LITTLE_BLIND_MONEY # ????
elif -1 == itm: # ???? 有人弃牌会引发组装错误
extra_info = 'fold'
pay = 0
else:
extra_info = 'raise'
pay = LITTLE_BLIND_MONEY*itm
pid = get_pid(i)
cur_bet = 500 # ???? 需要动态获取
cur_money = 8000
this_line = '{0}: {1} {2} {3} {4}
'.format(
pid, cur_bet, cur_money, pay, extra_info)
core += this_line
total_pot = 1000 # ?????
rtn = '''
{0}
{1}total: {2}
{0}
'''.format(ASK, core, total_pot) # ????????
return rtn
def analyse_one(one_info):
type = one_info[0]
if type == SEAT:
rtn = analyse_SEAT(one_info)
elif type == HOLD:
rtn = analyse_HOLD(one_info)
elif type == FIRST:
rtn = analyse_FIRST(one_info)
elif type == TURN:
rtn = analyse_TURN(one_info)
elif type == RIVER:
rtn = analyse_RIVER(one_info)
elif type == ACT:
rtn = analyse_ACT(one_info)
else:
print 'type error'
return rtn
def analyse(all_info):
rtn = ''
for itm in all_info:
rtn += analyse_one(itm)
return rtn
print analyse(input_info)
------分隔线----------------------------
------分隔线----------------------------