def try_exposed_chow(self, tile: Tile, owner) -> bool: arr = Rule.convert_tiles_to_arr(self.concealed) outer = tile.key # 胡吃一气 combins = MjMath.get_chow_combins_from_arr(arr=arr, outer=outer) if not combins: return False combin = choice(combins) inners = Rule.convert_arr_to_tiles(combin) self.exposed_chow(inners=inners, tile=tile, owner=owner) return True
def test_decide_discard_by_left_meld_and_eye(): mj_set = MjSet() ai = PlayerAiAdv("bot02") for _ in range(3): ai.draw(mj_set) mj_set.shuffle() for _ in range(11): ai.draw(mj_set) ai.sort_concealed() print("ai.concealed_str =", ai.concealed_str) result = ai.decide_discard_by_left_meld_and_eye() for x in result: print(x, Rule.convert_tiles_to_str(Rule.convert_arr_to_tiles(result[x])))
def decide_discard_by_value(self, wall=None, players_count: int = 4, deep: int = 2): left = Rule.convert_tiles_to_arr(wall) arr = Rule.convert_tiles_to_arr(self.concealed) arr.sort() if deep == 1: # (arr) pass keys = list(set(arr)) candidates = dict() self.sort_concealed() # ("self.concealed_str =", self.concealed_str) # ("self.concealed =", Rule.convert_tiles_to_arr(self.concealed)) for key in keys: test = arr[:] test.remove(key) mj_value = MjMath.value_arr(test, left=left, players_count=players_count, deep=deep) value = MjMath.convert_mj_value_to_int(mj_value) # (value) if key not in candidates: candidates[key] = value else: raise LookupError(f"duplicate key: {key}") max_chance = 0 # find max_chance for key in candidates: if candidates[key] == 0: # don't care about candidate who have no chance continue if max_chance < candidates[key]: max_chance = candidates[key] if not max_chance: return None # find candidate who have the min chance temp = [] for key in candidates: if candidates[key] == max_chance: temp.append(key) if not temp: return None tiles = Rule.convert_arr_to_tiles(temp) return tiles
def decide_discard_by_left_meld_and_eye(self): arr = Rule.convert_tiles_to_arr(self.concealed) arr.sort() keys = list(set(arr)) candidates = dict() for key in keys: test = arr[:] test.remove(key) result = MjMath.count_of_melds_and_eys(test) count = result[0] if result[1]: # has eye count += 1 if count not in candidates: candidates[count] = [] candidates[count].append(key) if not candidates: return None if len(candidates) == 1: return None len_arr = [key for key in candidates] max_len = max(len_arr) return Rule.convert_arr_to_tiles(candidates[max_len])
def sort_concealed(self): arr = Rule.convert_tiles_to_arr(self._concealed) arr.sort() self._concealed = Rule.convert_arr_to_tiles(arr)