def _shorten_pieces(self, pieces): if not pieces: return [] str_pieces = [] first = last = pieces[0] for current in pieces[1:]: if isinstance(last, Combo): str_pieces.append(str(last)) first = last = current elif isinstance(current, Combo): str_pieces.append(self._get_format(first, last)) first = last = current elif ( current.is_pair and Rank.difference(last.first, current.first) == 1 ) or ( last.first == current.first and Rank.difference(last.second, current.second) == 1 ): last = current else: str_pieces.append(self._get_format(first, last)) first = last = current # write out any remaining pieces str_pieces.append(self._get_format(first, last)) return str_pieces
def _get_format(self, first, last): if first == last: return str(first) elif ( first.is_pair and first.first.val == "A" or Rank.difference(first.first, first.second) == 1 ): return f"{last}+" elif last.second.val == "2": return f"{first}-" else: return f"{first}-{last}"
def Flush_Collection(self): Flush_dict = self.Flush() Flush_Collection_tail = { 'suit_c': [], 'suit_d': [], 'suit_h': [], 'suit_s': [] } for c in ['c', 'd', 'h', 's']: color_num = self.color_dict['suit_' + c] if (color_num >= 5): item_sum = 1 for item in range(1, color_num): if (Rank.difference(Flush_dict['suit_' + c][item], Flush_dict['suit_' + c][item - 1])) == 1: item_sum += 1 else: item_sum = 0 if (item_sum >= 5): Flush_Collection_tail['suit_' + c].append( Flush_dict['suit_' + c][item]) return Flush_Collection_tail
def judge_right(res_one, res_two, res_three, shape_1, shape_2, shape_3): if (shape_1 == str(2) or shape_1 == str(3)): return False if (shape_3 == str(0)): for i in range(5): for j in range(5): if (i != j and res_three[i].rank == res_three[j].rank): return False if (shape_2 == str(0)): for i in range(5): for j in range(5): if (i != j and res_two[i].rank == res_two[j].rank): return False if (shape_1 == str(0)): for i in range(3): for j in range(3): if (i != j and res_one[i].rank == res_one[j].rank): return False if (shape_3 == str(1)): pair_num = 0 for i in res_three: for j in res_three: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 2): return False if (shape_2 == str(1)): pair_num = 0 for i in res_two: for j in res_two: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 2): return False if (shape_1 == str(1)): pair_num = 0 for i in res_one: for j in res_one: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 2): return False if (shape_3 == str(2) or shape_3 == str(3)): pair_num = 0 for i in res_three: for j in res_three: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 4): return False pair_one = '' pair_two = '' for i in res_three: for j in res_three: if (pair_one == '' and i != j and i.rank == j.rank): pair_one = i.rank elif (pair_one != '' and i != j and i.rank == j.rank and i.rank != pair_one): pair_two = i.rank if (shape_3 == str(2) and Rank.difference(pair_one, pair_two) == 1): return False if (shape_2 == str(2) or shape_2 == str(3)): pair_num = 0 for i in res_two: for j in res_two: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 4): return False pair_one = '' pair_two = '' for i in res_two: for j in res_two: if (pair_one == '' and i != j and i.rank == j.rank): pair_one = i.rank elif (pair_one != '' and i != j and i.rank == j.rank and i.rank != pair_one): pair_two = i.rank if (shape_2 == str(2) and Rank.difference(pair_one, pair_two) == 1): return False if (shape_3 == str(4)): pair_num = 0 for i in res_three: for j in res_three: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 6): return False if (shape_2 == str(4)): pair_num = 0 for i in res_two: for j in res_two: if (i != j and i.rank == j.rank): pair_num += 1 if (pair_num != 6): return False if (shape_1 == str(4)): if (res_one[0].rank != res_one[1].rank or res_one[1].rank != res_one[2].rank or res_one[1].rank != res_one[0].rank): return False flag_reward = Compare_up(3, res_three, res_two, shape_3, shape_2) if (flag_reward < 0): return False flag_reward = Compare_gap(res_two, res_one, shape_2, shape_1) if (flag_reward < 0): return False return True
def rank_difference(self): """The difference between the first and second rank of the Combo.""" # self.first >= self.second return Rank.difference(self.first.rank, self.second.rank)