清一色テンパイを調べるプログラム
作ってみた。シンプルに行こう行こうとしたら、結構キモイ。3時間ギリギリだったし。
# -*- coding:utf-8 -*- import sys mentul =['111', '222', '333', '444', '555', '666', '777', '888', '999', '123', '234', '345', '456', '567', '678', '789'] ans = [] #面子で分解して待ちをしらべる def tempai(string): lst = list(string) lst.sort() for mentu1 in mentul: lst1 = GetMentu(lst, mentu1) if lst1!= False:#面子1つ for mentu2 in mentul: lst2 = GetMentu(lst1, mentu2) if lst2!= False:#面子2つ for mentu3 in mentul: lst3 = GetMentu(lst2, mentu3) if lst3!= False:#面子3つ for mentu4 in mentul: lst4 = GetMentu(lst3, mentu4) if lst4!= False: l = [mentu1,mentu2,mentu3,mentu4]#面子4つ #単騎待ち l.sort() l.append(lst4[0]) if l not in ans: ans.append(l) l = [mentu1,mentu2,mentu3] l.sort() l1,l2 = GetAtama(lst3) if l1 == "syanpon": lcopy = l[:] lcopy.append(lst3[0]+lst3[1]) lcopy.append(lst3[2]+lst3[3])#シャンポン待ち if lcopy not in ans: ans.append(lcopy) l.append(lst3[2]+lst3[3]) l.append(lst3[0]+lst3[1])#シャンポン待ち if l not in ans: ans.append(l) elif l1!= False: l.append(l1[0]+l1[1]) l.append(l2[0]+l2[1])#ターツ待ち if l not in ans: ans.append(l) return ans #stringから面子を取得 def GetMentu(lst, mentu): lcopy = lst[:] for j in mentu: if j in lcopy: lcopy.remove(j) else: return False return lcopy #stringからアタマを取得 def GetAtama(lst): if lst[0] == lst[1]: if lst[2] == lst[3]: return "syanpon",None elif (int(lst[2]) +1) == int(lst[3]): return (lst[0], lst[1]), (lst[2],lst[3]) elif lst[2] == lst[3]: if (int(lst[0]) +1) == int(lst[1]): return (lst[2],lst[3]), (lst[0], lst[1]) return False, False #七対子のチェック def toitu7(string): single = 0 mati = None lst = list(string[:]) lst.sort() for i in lst: n = lst.count(i) if n == 1 : single += 1 mati = i if single > 1: return None else: return None lst.remove(mati) lst.append(mati) return lst def main(): hai = sys.argv[1] if len(hai) != 13: pass else: rslt = toitu7(hai) if rslt: print "(%s%s)(%s%s)(%s%s)(%s%s)(%s%s)(%s%s)[%s]" % tuple(rslt) ans = tempai(hai) for i in ans: print "(%s)(%s)(%s)(%s)[%s]" % tuple(i) if __name__ == "__main__": main()
ちゃんと動きはするようだ。
もちっと見た目かっこいいのにしよう。
カンチャンを見つけられなかった。だめじゃん。