# CheckReadyHand.py ###### tags: `UnitTest_FileProcess` ``` #array = [230, 231, 240, 252, 263, 312, 323, 333, 372, 380] #arr1 = [120, 133, 141, 221, 222, 261, 270] #arr2 = [220, 232, 241, 281, 283, 341, 351, 353, 370, 373, 393] #arr3 = [143, 223, 243, 271, 282, 331, 340, 343, 352, 360, 361, 362, 383] #tile_to_test = 280 def hu_test(tile_arr, test_tile): def del_rep(): cnt = 0 rep = [0] to_del = [] for tile in arr_cpy: #print(f"{arr_cpy}\nrep test: {tile}v{rep[0]} {int(tile/10) != int(rep[0]/10)}") if int(tile/10) != int(rep[0]/10): cnt = 0 rep = [0] rep[0] = tile else: cnt += 1 rep.append(tile) if cnt == 2: to_del.extend(rep) cnt = 0 rep = [0] #print(f"rep: {rep}\nto_del {to_del}") for t in to_del: arr_cpy.remove(t) def del_num(): cnt = 0 num = [0] numflag = True while numflag: numflag = False for tile in arr_cpy: if int(tile/10) == int(num[cnt]/10): continue elif int(tile/10) != int(num[cnt]/10) +1: cnt = 0 num = [0] num[0] = tile else: cnt += 1 num.append(tile) if cnt == 2: for t in num: arr_cpy.remove(t) cnt = 0 num = [0] numflag = True #print(f"num: {num}") arr = tile_arr.copy() arr.append(test_tile) arr.sort() #print('arr =', arr) eye_idx = -1 eye = [0] while 1: eye = [0] eye_flag = False eye_idx += 1 for new_eye in arr[eye_idx:]: if int(new_eye/10) != int(eye[0]/10): eye[0] = new_eye else: eye_flag = True eye.append(new_eye) break eye_idx += 1 #print(eye) if eye_flag == False: return False #若無牌眼 則不可能胡 arr_cpy = arr.copy() arr_cpy.remove(eye[0]) arr_cpy.remove(eye[1]) #print(arr_cpy) # 抓刻子 del_rep() #print(f"\nrepped{arr_cpy}") # 抓順子 del_num() #print(f"nummed{arr_cpy}\n") if len(arr_cpy) != 0: arr_cpy = arr.copy() arr_cpy.remove(eye[0]) arr_cpy.remove(eye[1]) #print(arr_cpy) # 抓順子 del_num() #print(f"nummed{arr_cpy}") # 抓刻子 del_rep() #print(f"repped{arr_cpy}\n") if len(arr_cpy) == 0: return True #print(hu_test(array, tile_to_test)) #print(hu_test(arr1, tile_to_test)) #print(hu_test(arr2, tile_to_test)) #print(hu_test(arr3, tile_to_test)) ''' for i in range(11, 48): if i%10 == 0: continue x = i*10 +1 if hu_test(array, x): print(i) '''