def test_seq(): decomposer = FollowDecomposer() combo = Combo() combo.cards = [4, 5, 6, 7, 8] print(decomposer.get_good_follows(np.array([5, 5, 6, 7, 8, 9]), combo)) print(decomposer.get_good_follows(np.array([CARD_G1, CARD_G0]), combo))
def test_long_seq(): combo = Combo() decomposer = FollowDecomposer() combo.cards_view = 'Q' print( decomposer.get_good_follows( np.array([1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 8, 9, 10, 11, 12]), combo))
def test_four_takes(): decomposer = PlayDecomposer() follow_decomposer = FollowDecomposer() combo = Combo() combo.cards_view = '4 4 4 4 7 8' play_hand = decomposer.get_good_plays(combo.cards) print(play_hand) print( follow_decomposer.get_good_follows(np.array([9, 9, 9, 9, 8, 10]), combo))
def test_trio(): decomposer = PlayDecomposer() combo = Combo() combo.cards_view = '3 4 4 5 6 6 6 7 7 7 8 8 9 9 10 10 J Q B G' print(decomposer.get_good_plays(combo.cards)) print(decomposer.get_good_plays(np.array([4, 4, 4, 5, 6, 6, 7, 7]))) print( decomposer.get_good_plays( np.array([1, 1, 2, 3, 4, 5, 6, 9, 9, 9, 10, 10, 10, 11, 11, 11])))
def test_card2(): decomposer = FollowDecomposer() combo = Combo() combo.cards_view = '5 6 7 8 9' print(decomposer.get_good_follows(np.array([CARD_2]), combo)) combo.cards_view = '8 8 8 9 9' print(decomposer.get_good_follows(np.array([CARD_2]), combo)) print(decomposer.get_good_follows(np.array([CARD_2, CARD_2]), combo)) print( decomposer.get_good_follows(np.array([CARD_2, CARD_2, CARD_2]), combo))
def _update_main_lists_and_find_max(self, a: np.ndarray, q: int, max_q: int) -> None: """在action有效的情况下加入到主列表,并更新最大值""" main_kind = self._last_combo.main_kind seq_len = self._last_combo.seq_len value = self._last_combo.value combo = Combo() combo.cards = a # 筛选符合规则的主牌 if combo.value > value and combo.main_kind == main_kind and combo.seq_len == seq_len: self._main_lists[self._delta_q(max_q, q)].append(a) # 仅对比主牌大小,不关心是否带了牌 if combo.value > self._max_combo.value: self._max_combo = deepcopy(combo)
def test_get_good_plays(): decomposer = PlayDecomposer() combo = Combo() combo.cards_view = '3 3 4 5 5 6 7 7 7 8 9 10 J Q K K A 2 g G' print(decomposer.get_good_plays(combo.cards)) test_data = [ [5, 6, 7, 7, 8, 8, 9, 10], [1, 1, 1, 1, 5, 5, 6, 6, 7, 7, 7, 9, 9, 10, 10, 11, 11, 14, 15], [3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 9, 10, 11], [1, 2, 3, 3, 5, 6, 7, 7, 7, 8, 8, 9, 10, 11, 11, 11, 12, 13, 14, 15] ] for i in test_data: cards = np.array(i) print(decomposer.get_good_plays(cards))
def test_trio_with_one(): combo = Combo() combo.cards = [3, 7, 7, 7] decomposer = FollowDecomposer() print(decomposer.get_good_follows(np.array([8, 8, 8, 9, 10]), combo)) print(decomposer.get_good_follows(np.array([8, 8, 9, 10]), combo)) print(decomposer.get_good_follows(np.array([8, 8, 8, 8, 9, 10]), combo)) combo.cards = [3, 3, 7, 7, 7] print( decomposer.get_good_follows(np.array([8, 8, 8, CARD_2, CARD_2]), combo)) print(decomposer.get_good_follows(np.array([8, 8, 8, CARD_2]), combo)) print( decomposer.get_good_follows( np.array([1, 1, 2, 3, 4, 5, 6, 9, 9, 9, 10, 10, 10, 11, 11, 11]), combo))
def test_bomb(): follow_provider = FollowProvider(1) follow_provider.add_landlord_id(2) combo = Combo() combo.cards = [1] res = follow_provider.provide(0, 5, 5, np.array([3, 3, 3, 3, 4, 4, 4, 4, 14, 15]), combo) print(res) play_provider = PlayProvider(1) play_provider.add_landlord_id(2) res = play_provider.provide(np.array([3, 3, 3, 3, 4, 4, 4, 4, 14, 15]), 10, 10) print(res) res = play_provider.provide(np.array([4, 4, 4, 4, 14, 15]), 10, 10) print(res) res = play_provider.provide(np.array([3, 3, 4]), 10, 10) print(res)
def test_sorted_follow(): follow_provider = FollowProvider(1) follow_provider.add_landlord_id(1) combo = Combo() combo.cards_view = '3 4 4 6 6 7 8 8 8 10 Q Q K K A 2 2' combo1 = Combo() combo1.cards_view = '3 3' result = follow_provider.provide(0, 18, 17, combo.cards, combo1) print(result) combo.cards = [6, 6, 7, 7, 9, 9, 9, 9, 8, 8, 8, 8] result = follow_provider.provide(0, 18, 17, combo.cards, combo1) print(result) combo.cards_view = '3 3 7 7 7' combo1.cards_view = '2 2 8 8 8 4 4' result = follow_provider.provide(0, 18, 17, combo1.cards, combo) print(result)
def test_takes(): play_decomposer = PlayDecomposer() follow_decomposer = FollowDecomposer() test_cards = [([1, 1, 4, 4, 4, 5, 5, 5, 6], [6, 6, 3, 3, 3, 4, 4, 4])] print( play_decomposer.get_good_plays( np.array([2, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 12]))) combo = Combo() for i in test_cards: combo.cards = i[1] cards = np.array(i[0]) print(play_decomposer.get_good_plays(cards)) print(follow_decomposer.get_good_follows(cards, combo)) print( play_decomposer.get_good_plays( np.array([5, 7, 8, 9, 10, 10, 10, 11, 11, 11, 12, 12]))) print( play_decomposer.get_good_plays( np.array([3, 3, 5, 7, 8, 9, 10, 10, 10, 11, 11, 11, 12, 12])))
def test_follow(): follow_provider = FollowProvider(1) follow_provider.add_landlord_id(1) combo = Combo() combo.cards = [3, 3] result = follow_provider.provide(2, 10, 10, np.array([7, 7, 12, 12, 12]), combo) print(result) combo.cards = [9, 9] result = follow_provider.provide(2, 10, 10, np.array([7, 7, 12, 12, 12]), combo) print(result) combo.cards = [4] result = follow_provider.provide(2, 10, 10, np.array([7, 8, 12, 12, 12]), combo) print(result) combo.cards = [9] result = follow_provider.provide(2, 10, 10, np.array([7, 8, 12, 12, 12]), combo) print(result) combo.cards = [13] result = follow_provider.provide(2, 10, 10, np.array([7, 8, 12, 12, 12]), combo) print(result)
def get_good_follows(self, state: np.ndarray, last_combo: Combo) \ -> Tuple[List[np.ndarray], int, List[np.ndarray], np.ndarray]: """ 尽量给出较好的跟牌行动。 @param state: 当前手牌。 @param last_combo: 上一次出牌 @return: 四元组:炸弹, 最好的组合 - 最好的跟牌(数字越大越不应该这样拆牌), 好的出牌的数组, 最大的出牌 """ if last_combo.is_rocket(): return [], 0, [], np.array([], dtype=int) self._process_card(state) self._init(last_combo) min_delta_q, self._output = self._thieve_valid_actions() self._add_bomb(card_to_di(self._lt2_cards)[0][4]) self._max_combo.cards = self._max_main_takes return self._bomb_list, min_delta_q, self._output, ( self._max_main_takes if self._max_combo > last_combo else np.array([], dtype=int))
def test_good_single(): combo = Combo() combo.cards = [3] decomposer = FollowDecomposer() print( decomposer.get_good_follows( np.array([4, 5, 6, 6, CARD_2, CARD_2, CARD_G0, CARD_G1]), combo)) combo.cards = [3, 4, 5, 6, 7] print( decomposer.get_good_follows(np.array([5, 6, 7, 8, 9, 10, 11, 12]), combo)) combo.cards = [8] print( decomposer.get_good_follows(np.array([5, 7, CARD_G0, CARD_G1]), combo)) combo.cards_view = '2' print(decomposer.get_good_follows(np.array([CARD_2]), combo)) combo.cards_view = 'A A' print( decomposer.get_good_follows(np.array([CARD_2, CARD_2, CARD_2]), combo))
def test_combo_type(): combo = Combo() combo.cards = [CARD_A, CARD_A, CARD_A, CARD_2, CARD_G0] assert not combo.is_valid()