def setRonHand(self,ronPai,i): """ (int,int) int -> [[(int,int)]] i: which form does the ronPai fit return breakdown of Ron hand """ b = breakdown(self.hand,self.getOpenHand()) target_form = b[i][:] # 孤张 for mianzi in target_form: if len(mianzi) == 1: mianzi.append(ronPai) self.ronHand = target_form return # is_seq if len(mianzi) == 2 and has_seq2(mianzi): mianzi.append(ronPai) mianzi.sort() self.ronHand = target_form return else: continue # both are pairs for mianzi in target_form: if len(mianzi) == 2 and has_pair(mianzi): if mianzi[0][0] == ronPai[0]: mianzi.append(ronPai) self.ronHand = target_form return
def checkWait(self): """ [[Int]] return a list of list of tenpai """ b = breakdown(self.hand,self.getOpenHand()) ten = [[] for i in range(len(b))] seq2_count = 0 # find all ten for i, possibility in enumerate(b): for form in possibility: if len(form) == 2: if has_seq2(form): seq2_count += 1 a = Pai.previous(form[0]) if a is not None: ten[i].append(a) b = Pai.next(form[1]) if b is not None: ten[i].append(b) if has_pair(form) and seq2_count == 0: ten[i].append(Pai.same(form[0])) if len(form) == 1: ten[i].append(Pai.same(form[0])) return ten