Ejemplo n.º 1
0
 def next_state(self, owner):
     # 地主在翻倍后还有一次明牌机会
     if owner.table.conf.has_show and owner.table.dealer_seat == owner.seat and owner.show_card != 2:
         owner.machine.trigger(ShowCardDealerState())
         return
     owner.machine.trigger(WaitState())
     owner.table.machine.cur_state.execute(owner.table, "skip_step")
Ejemplo n.º 2
0
 def next_state(self, owner):
     if owner.table.conf.has_double:
         owner.machine.trigger(DoubleState())
         owner.table.machine.cur_state.execute(owner.table, "skip_double")
     else:
         owner.machine.trigger(WaitState())
         owner.table.machine.cur_state.execute(owner.table, "skip_step")
Ejemplo n.º 3
0
    def enter(self, owner):
        super(DiscardExposedKongKGState, self).enter(owner)

        for card in owner.action_ref_cards:
            owner.cards_in_hand.remove(card)

        active_card = owner.action_op_card
        action_cards = [active_card] * 4
        owner.cards_kong_exposed.extend(action_cards)
        owner.cards_group.extend(action_cards)
        owner.add_gang_num(1, 0, 0, 0)
        trigger_seat = owner.table.active_seat
        trigger_player = owner.table.seat_dict[trigger_seat]
        calculate_final_score(trigger_player, owner,
                              owner.get_fang_gang_score())
        trigger_player.add_gang_num(0, 0, 0, 1)
        trigger_player.cards_discard.remove(active_card)
        trigger_player.machine.trigger(WaitState())
        owner.table.active_seat = owner.seat

        proto = game_pb2.ActionCSResponse()
        for card in owner.action_ref_cards:
            cards = proto.ref_card.add()
            cards.card = card
        proto.active_card.card = active_card
        proto.trigger_seat = trigger_seat
        proto.active_type = PLAYER_ACTION_TYPE_KONG_EXPOSED_KG
        proto.player = owner.uuid
        for player in owner.table.player_dict.values():
            send(ACTION_CS, proto, player.session)
        owner.table.logger.info("player {0} kong {1}".format(
            owner.seat, active_card))
        owner.table.discard_seat = -1
Ejemplo n.º 4
0
    def enter(self, owner):
        super(ChowState, self).enter(owner)

        for card in owner.action_ref_cards:
            owner.cards_in_hand.remove(card)
        active_card = owner.table.active_card
        action_cards = owner.action_ref_cards
        action_cards.append(active_card)
        owner.cards_chow.extend(action_cards)
        owner.cards_group.extend(action_cards)

        trigger_seat = owner.table.active_seat
        trigger_player = owner.table.seat_dict[trigger_seat]
        trigger_player.cards_discard.remove(active_card)
        trigger_player.machine.trigger(WaitState())
        owner.table.active_seat = owner.seat

        proto = game_pb2.ActionResponse()
        for card in owner.action_ref_cards:
            cards = proto.card.add()
            cards.card = card
        proto.active_card.card = active_card
        proto.trigger_seat = trigger_seat
        proto.active_type = PLAYER_ACTION_TYPE_CHOW
        proto.player = owner.uuid
        # for player in owner.table.player_dict.values():
        #     send(ACTION, proto, player.session)
        owner.table.reset_proto(ACTION)
        for player in owner.table.player_dict.values():
            player.proto.p = copy(proto)
            if player.uuid == owner.uuid:
                PlayerRulesManager().condition(owner, PLAYER_RULE_CHOW)
            player.proto.send()
        owner.table.logger.info("player {0} chow {1}".format(
            owner.seat, active_card))
        # 吃完后检测杠
        owner.table.discard_seat = -1
        # owner.table.check_bao_change()
        owner.dumps()
Ejemplo n.º 5
0
    def enter(self, owner):
        super(PongState, self).enter(owner)
        #print 'enter pong state,', owner.action_ref_cards
        for card in owner.action_ref_cards:
            owner.cards_in_hand.remove(card)
        active_card = owner.table.active_card
        action_cards = [active_card] * 3
        owner.cards_pong.extend(action_cards)
        owner.cards_group.extend(action_cards)
        if active_card in owner.miss_pong_cards:
            owner.miss_pong_cards.remove(active_card)
        trigger_seat = owner.table.active_seat
        trigger_player = owner.table.seat_dict[trigger_seat]
        trigger_player.cards_discard.remove(active_card)
        trigger_player.machine.trigger(WaitState())
        owner.table.active_seat = owner.seat

        proto = game_pb2.ActionResponse()
        for card in owner.action_ref_cards:
            cards = proto.card.add()
            cards.card = card
        proto.active_card.card = active_card
        proto.trigger_seat = trigger_seat
        proto.active_type = PLAYER_ACTION_TYPE_PONG
        proto.player = owner.uuid
        # for player in owner.table.player_dict.values():
        #     send(ACTION, proto, player.session)
        owner.table.reset_proto(ACTION)
        for player in owner.table.player_dict.values():
            player.proto.p = copy(proto)
            if player.uuid == owner.uuid:
                PlayerRulesManager().condition(owner, PLAYER_RULE_PONG)
            player.proto.send()
        owner.table.logger.info("player {0} pong {1}".format(
            owner.seat, active_card))
        owner.table.discard_seat = -1
        #owner.table.reset_proto(ACTION)
        owner.dumps()
Ejemplo n.º 6
0
    def enter(self, owner):
        super(SettleForCardState, self).enter(owner)
        # 将所有玩家至于结算状态
        for player in owner.player_dict.values():
            player.machine.trigger(WaitState())

        # 广播胡牌数据
        proto = game_pb2.SendScoreResponse()

        for seat in sorted(owner.seat_dict.keys()):
            i = owner.seat_dict[seat]
            p = proto.player_data.add()
            p.player = i.uuid
            # 胡牌的人需要特殊处理
            if i.has_win > 0:
                p.win_card = i.win_card
                # 添加回放
                owner.replay["procedure"].append({"hu_card": [i.seat, i.win_card]})
            else:
                p.win_card = 0

            p.win_type = i.win_type
            p.hu_score = i.cards_score + i.gang_score

        for i in owner.player_dict.values():
                send(SEND_SCORE, proto, i.session)

        # 清空本次胡牌数据
        for player in owner.player_dict.values():
            player.cards_score = 0
            player.has_win = 0
            player.win_card = 0
        owner.win_seat_prompt = []
        owner.win_seat_action = []
        from state.table_state.step import StepState
        owner.machine.trigger(StepState())
Ejemplo n.º 7
0
    def enter(self, owner):
        super(DiscardExposedKongState, self).enter(owner)
        for card in owner.action_ref_cards:
            owner.cards_in_hand.remove(card)

        active_card = owner.table.active_card
        action_cards = [active_card] * 4
        owner.cards_kong_exposed.extend(action_cards)
        owner.cards_group.extend(action_cards)

        trigger_seat = owner.table.active_seat
        trigger_player = owner.table.seat_dict[trigger_seat]
        trigger_player.cards_discard.remove(active_card)
        trigger_player.machine.trigger(WaitState())
        owner.table.active_seat = owner.seat
        trigger_player.add_gang_num(0, 0, 0, 1)
        owner.add_gang_num(1, 0, 0, 0)

        proto = game_pb2.ActionResponse()
        for card in owner.action_ref_cards:
            cards = proto.card.add()
            cards.card = card
        proto.active_card.card = active_card
        proto.trigger_seat = trigger_seat
        proto.active_type = PLAYER_ACTION_TYPE_KONG_EXPOSED
        proto.player = owner.uuid
        for player in owner.table.player_dict.values():
            send(ACTION, proto, player.session)
        owner.last_gang_card = active_card
        owner.table.logger.info("player {0} kong {1}".format(
            owner.seat, active_card))
        owner.table.discard_seat = -1
        from rules.player_rules.manager import PlayerRulesManager
        from rules.define import PLAYER_RULE_TING_KONG
        owner.table.reset_proto(PROMPT)
        PlayerRulesManager().condition(owner, PLAYER_RULE_TING_KONG)
Ejemplo n.º 8
0
 def next_state(self, owner):
     # owner.machine.trigger(ShowCardState())
     # owner.table.machine.cur_state.execute(owner.table, "skip_show_card")
     # 2018.5.9改明牌之后出牌
     owner.machine.trigger(WaitState())
     owner.table.machine.cur_state.execute(owner.table, "skip_step")
Ejemplo n.º 9
0
from state.table_state.step import StepState as TableStepState
from state.table_state.wait import WaitState as TableWaitState
from state.table_state.dealer_choose import DealerChooseState as TableDealerChooseState
from web.request import WebRequest

player_state = {
    "DealState": DealState(),
    "DiscardState": DiscardState(),
    "InitState": InitState(),
    "PauseState": PauseState(),
    "PromptState": PromptState(),
    "PromptDrawState": PromptDrawState(),
    "PromptDiscardState": PromptDiscardState(),
    "ReadyState": ReadyState(),
    "SettleState": SettleState(),
    "WaitState": WaitState(),
    'RobState': RobState(),
    'ShowCardState': ShowCardState(),
    'ShowCardDealerState': ShowCardDealerState(),
    'DoubleState': DoubleState(),
    'DealerChooseState': DealerChooseState()
}

table_state = {
    "DealState": TableDealState(),
    "EndState": TableEndState(),
    "InitState": TableInitState(),
    "ReadyState": TableReadyState(),
    "RestartState": TableRestartState(),
    "SettleForRoomState": TableSettleForRoomState(),
    "SettleForRoundState": TableSettleForRoundState(),
Ejemplo n.º 10
0
    def enter(self, owner):
        super(DrawWinState, self).enter(owner)
        # 广播玩家胡牌
        owner.table.liuju = False
        proto = game_pb2.ActionResponse()
        proto.player = owner.uuid
        owner.win_total_cnt += 1
        proto.trigger_seat = owner.seat
        proto.active_type = PLAYER_ACTION_TYPE_WIN_DRAW
        owner.win_type = PLAYER_WIN_TYPE_DRAW
        owner.win_draw_cnt += 1
        owner.win_card = owner.draw_card
        owner.table.winner_list = [owner.seat]
        # 需要将胡的牌进行效验整理
        flags1 = []
        owner.cards_win = sorted(owner.cards_in_hand)
        owner.cards_in_hand.remove(owner.draw_card)

        owner.has_win = 1
        if owner.table.conf.can_hu_on_ready() and owner.table.step == 0:
            owner.win_flags.append("TNHU")
            win_score = 32
            for p in owner.table.player_dict.values():
                if p.uuid == owner.uuid:
                    continue
                calculate_final_score(p, owner, win_score)
        else:
            flags1 = []
            point = 0
            if owner.win_card != 0 and owner.win_card in owner.cards_ready_hand:
                point, flags1 = owner.cards_ready_hand[owner.win_card]
                # 存储已经胡过得牌和牌组
                owner.has_win_cards[owner.draw_card] = owner.win_card_group[
                    owner.draw_card]
            # 算分
            if point:
                # 处理下吃干榨尽,不和自摸同时存在
                if len(owner.cards_in_hand) == 1:
                    if "BASE" in flags1:
                        point = 2
                    else:
                        point += 2
                # 倍数 = 连杠次数+流局倍数
                mul_liuju = 1 if owner.table.liuju_times > 0 else 0
                times = owner.kong_times + mul_liuju
                # 将番数相加*2^倍数
                owner.temp_total_score += point * (2**times)

        # 需要将胡的牌单独拿出来
        if owner.win_card in owner.cards_win:
            owner.cards_win.remove(owner.win_card)
            owner.has_win_cards_list.append(owner.win_card)
        proto.active_card.card = owner.win_card
        cards = proto.card.add()
        cards.card = 0
        # for card in owner.cards_win:
        # cards = proto.card.add()
        # cards.card = card
        # 胡牌不显示所有手牌
        # TODO
        # cards.card = 0
        owner.dumps()
        for player in owner.table.player_dict.values():
            send(ACTION, proto, player.session)
        owner.table.win_type = TABLE_WIN_TYPE_DISCARD_DRAW

        owner.table.logger.info("player {0} win {1} type {2} score {3}".format(
            owner.seat, owner.win_card, owner.win_type,
            owner.temp_total_score))
        owner.machine.trigger(WaitState())
Ejemplo n.º 11
0
 def next_state(self, owner):
     owner.machine.trigger(WaitState())
     owner.table.machine.cur_state.execute(owner.table, "skip_step")
Ejemplo n.º 12
0
 def next_state(self, owner):
     # 要先将自己切换为等待状态 否则流局这种情况在切换到SettleState后又切回来了
     owner.machine.trigger(WaitState())
     owner.table.machine.cur_state.execute(owner.table, "step")
Ejemplo n.º 13
0
 def next_state(self, owner):
     owner.proto.send()
     owner.ready_hand()  # 检测自己能碰和胡的牌
     owner.machine.trigger(WaitState())
     owner.table.machine.cur_state.execute(owner.table, "prompt_deal")
Ejemplo n.º 14
0
def discard(player, proto):
    from state.player_state.wait import WaitState

    if player.seat != player.table.active_seat:
        return
    type = proto.type
    cards = []
    for i in proto.cards:
        cards.append(i.card)
    # print set(cards)
    if set(cards) - set(player.cards_in_hand):
        # 出不存在的牌的时候同步手牌
        proto = game_pb2.PokerSynchroniseCardsResponse()
        for i in player.cards_in_hand:
            c = proto.card.add()
            c.card = i
        send(POKER_SYNCHRONISE_CARDS, proto, player.session)
        player.table.logger.warn(
            "player {0} discard {1} not exist in hand".format(
                player.seat, cards))
        return
    # 强制地主出牌如果走到这说明作弊了

    if player.table.step == 0 and not cards:
        proto = game_pb2.PokerDiscardResponse()
        proto.player = player.uuid
        proto.code = -2
        proto.rest_cards_count = len(player.cards_in_hand)
        player.table.reset_proto(POKER_DISCARD)
        player.proto.p = copy(proto)
        player.proto.send()
        player.table.logger.warn(
            "player {0} is landlord and does not discard".format(
                player.seat, cards))
        return

    if player.state == "PromptState":
        player.del_prompt()
        player.table.clear_prompt()
        player.machine.next_state()
        player.table.logger.fatal(
            "{0} client send discard event without pass".format(player.uuid))

    proto = game_pb2.PokerDiscardResponse()
    proto.player = player.uuid
    proto.code = 2
    if cards and type == 1:
        card_type = match_type(cards, game_id)
        if card_type:
            proto.card_type = card_type
            # 其余两家要不起之后可以出任意牌
            if player.table.last_discard_seat == player.seat:
                rcode = 1
            else:
                rcode = compare(player, cards, card_type=card_type)
            if rcode != 1:
                proto.code = rcode
                # proto.rest_cards_count = len(player.cards_in_hand) - len(cards)
                proto.rest_cards_count = len(player.cards_in_hand)
                player.table.reset_proto(POKER_DISCARD)
                player.proto.p = copy(proto)
                player.proto.send()
                return
        else:
            proto.code = -2
            proto.rest_cards_count = len(player.cards_in_hand)
            player.table.reset_proto(POKER_DISCARD)
            player.proto.p = copy(proto)
            player.proto.send()
            return

        player.table.last_discard_seat = player.seat
        player.table.active_card = cards
        player.table.active_seat = player.seat
        player.table.active_card_type = card_type
        if card_type in ['bomb', 'jackBomb']:
            player.bomb_cnt += 1
            player.table.boom_num += 1
            # 喜钱
            player.table.calculate_reward_points()

        for i in cards:
            player.cards_in_hand.remove(i)
            c = proto.cards.add()
            c.card = i
        proto.rest_cards_count = len(player.cards_in_hand)

    else:
        # 过滤重复点过
        if type == 2 and player.table.last_discard_seat == player.seat:
            proto.code = -2
            proto.rest_cards_count = len(player.cards_in_hand)
            player.table.reset_proto(POKER_DISCARD)
            player.proto.p = copy(proto)
            player.proto.send()
            return
        # 出牌列表为空
        if type == 1 and not cards:
            proto.code = -2
            proto.rest_cards_count = len(player.cards_in_hand)
            player.table.reset_proto(POKER_DISCARD)
            player.proto.p = copy(proto)
            player.proto.send()
            return

    player.table.replay["procedure"].append({"discard": [player.uuid, cards]})
    player.table.logger.info("player {0} discard {1}".format(
        player.seat, cards))
    if player.table.spy_card in cards and player.seat != player.table.dealer_seat and not player.table.baolu:
        player.table.notify_goutui()
    # player.table.last_oper_seat = player.seat
    player.table.discard_seat = player.seat
    player.last_cards_discard = cards[:]
    if cards:
        player.cards_discard.append(cards)
    player.table.step += 1

    player.table.reset_proto(POKER_DISCARD)
    for i in player.table.player_dict.values():
        # if i.uuid == player.uuid:
        #     continue
        i.proto.p = copy(proto)
        if i.machine.cur_state.name == 'PromptDiscardState':
            i.machine.trigger(WaitState())

        if i.uuid != player.uuid:
            i.machine.cur_state.execute(i, "other_discard")
        i.proto.send()

    if player.table.player_prompts:
        player.machine.trigger(PauseState())
    else:
        # player.machine.next_state()
        from rules.player_rules.manager import PlayerRulesManager
        PlayerRulesManager().condition(player, PLAYER_RULE_WIN)