Пример #1
0
def heqie_tester():
    """发牌器, 测试何切函数
    """
    paishan = mahjong.init_paishan() #init
    raw_hand = ''.join(paishan[-13:]) #发手牌
    del paishan [-13:]
    hand = mahjong.hand_processer(raw_hand, raw_hand=True)

    for card in hand:
        mahjong.used_card(card) # 计算剩余牌量

    while paishan: 
        print('剩余牌量:', len(paishan))
        new_card = paishan.pop() # 出一张牌
        mahjong.used_card(new_card) # 计算剩余牌量
        print('hand: ', end = '')
        hand.sort(key=mahjong.sort_hand)
        mahjong.print_hand(hand)
        print('new card', new_card)
        hand = hand + [mahjong.Card(new_card)]
        discard_card, xiangtingshu = heqie(hand, output_notes=True)
        print('discard card:', discard_card)
        print('xiangtingshu:', xiangtingshu)
        print()
        if discard_card:
            for card in hand:
                if mahjong.is_samecard(card, discard_card):
                    hand.remove(card)
                    break
        else:
            print('和牌')
            return True
    else:
        print('牌山没牌了.')
Пример #2
0
def heqie_tester():
    """发牌器, 测试何切函数
    """
    paishan = mahjong.init_paishan() #init
    raw_hand = ''.join(paishan[-13:]) #发手牌
    del paishan [-13:]
    hand = mahjong.hand_processer(raw_hand, raw_hand=True)

    for card in hand:
        mahjong.used_card(card) # 计算剩余牌量

    while paishan: 
        print('剩余牌量:', len(paishan))
        new_card = paishan.pop() # 出一张牌
        mahjong.used_card(new_card) # 计算剩余牌量
        print('hand: ', end = '')
        hand.sort(key=mahjong.sort_hand)
        mahjong.print_hand(hand)
        print('new card', new_card)
        hand = hand + [mahjong.Card(new_card)]
        discard_card, xiangtingshu = heqie(hand, output_notes=True)
        print('discard card:', discard_card)
        print('xiangtingshu:', xiangtingshu)
        print()
        if discard_card:
            for card in hand:
                if mahjong.is_samecard(card, discard_card):
                    hand.remove(card)
                    break
        else:
            print('和牌')
            return True
    else:
        print('牌山没牌了.')
Пример #3
0
def ai():
    """ai using 国标v1.30
    读取手牌-(读取新摸牌-切牌)
    """
    raw_hand = autogui.get_hand()
    hand = mahjong.hand_processer(raw_hand, raw_hand=True)

    for card in hand:
        mahjong.used_card(card) # 计算剩余牌量

    while True: 
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)

        new_card = autogui.get_card() # 出一张牌
        mahjong.used_card(new_card) # 计算剩余牌量
        print('hand: ', end = '')
        hand.sort(key=mahjong.sort_hand)
        mahjong.print_hand(hand)
        print('new card', new_card)
        hand_plus = hand + [mahjong.Card(new_card)]
        discard_card, xiangtingshu = heqie(hand_plus, output_notes=True)
        print('discard card:', discard_card)
        print('xiangtingshu:', xiangtingshu)
        if discard_card:
            for card in hand:
                if mahjong.is_samecard(card, discard_card):
                    print('切第n张:', hand.index(card))
                    autogui.qiepai(hand.index(card))
                    hand_plus.remove(card)
                    hand = hand_plus
                    break
            else:
                autogui.qiepai(13)
        else:
            print('和牌')
            return True
    else:
        print('牌山没牌了.')
Пример #4
0
def ai():
    """ai using 国标v1.30
    读取手牌-(读取新摸牌-切牌)
    """
    raw_hand = autogui.get_hand()
    hand = mahjong.hand_processer(raw_hand, raw_hand=True)

    for card in hand:
        mahjong.used_card(card)  # 计算剩余牌量

    while True:
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)
        autogui.pass_mingpai()
        time.sleep(1)

        new_card = autogui.get_card()  # 出一张牌
        mahjong.used_card(new_card)  # 计算剩余牌量
        print('hand: ', end='')
        hand.sort(key=mahjong.sort_hand)
        mahjong.print_hand(hand)
        print('new card', new_card)
        hand_plus = hand + [mahjong.Card(new_card)]
        discard_card, xiangtingshu = heqie(hand_plus, output_notes=True)
        print('discard card:', discard_card)
        print('xiangtingshu:', xiangtingshu)
        if discard_card:
            for card in hand:
                if mahjong.is_samecard(card, discard_card):
                    print('切第n张:', hand.index(card))
                    autogui.qiepai(hand.index(card))
                    hand_plus.remove(card)
                    hand = hand_plus
                    break
            else:
                autogui.qiepai(13)
        else:
            print('和牌')
            return True
    else:
        print('牌山没牌了.')