def enter(self, owner): super(DrawConcealedKongState, self).enter(owner) #print "cards_kong_concealed", owner.action_ref_cards, owner.cards_in_hand for card in owner.action_ref_cards: owner.cards_in_hand.remove(card) owner.cards_kong_concealed.extend(owner.action_ref_cards) owner.cards_group.extend(owner.action_ref_cards) 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_type = PLAYER_ACTION_TYPE_KONG_CONCEALED proto.player = owner.uuid proto.trigger_seat = owner.seat proto.active_card.card = 0 for player in owner.table.player_dict.values(): send(ACTION, proto, player.session) owner.table.logger.info("player {0} kong {1}".format(owner.seat, owner.action_ref_cards)) # 修改杠上开花 owner.last_gang_card = owner.table.active_card owner.add_gang_num(0, 0, 1, 0) owner.table.discard_seat = -1 # owner.table.check_bao_change() 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)
def enter(self, owner): super(DrawExposedKongState, self).enter(owner) active_card = owner.action_ref_cards[0] owner.draw_kong_exposed_card = active_card #print "cards_draw_kong_exposed", owner.action_ref_cards, owner.cards_in_hand owner.cards_in_hand.remove(active_card) owner.cards_kong_exposed.extend([active_card] * 4) owner.cards_pong.remove(active_card) owner.cards_pong.remove(active_card) owner.cards_pong.remove(active_card) owner.add_gang_num(0, 1, 0, 0) insert_index = owner.cards_group.index(active_card) owner.cards_group.insert(insert_index, active_card) owner.table.active_seat = owner.seat owner.table.last_oper_seat = owner.seat owner.table.active_card = active_card proto = game_pb2.ActionResponse() for card in owner.action_ref_cards: cards = proto.card.add() cards.card = card proto.active_type = PLAYER_ACTION_TYPE_KONG_PONG proto.player = owner.uuid proto.trigger_seat = owner.seat proto.active_card.card = 0 owner.table.discard_seat = owner.seat owner.table.logger.info("player {0} kong {1}".format( owner.seat, active_card)) #owner.table.reset_proto(ACTION) # 修改杠上开花 owner.last_gang_card = owner.table.active_card if owner.table.conf.is_qg(): owner.table.reset_proto(ACTION) owner.table.clear_prompt() owner.table.clear_actions() for player in owner.table.player_dict.values(): player.proto.p = copy(proto) if player.uuid != owner.uuid: player.machine.cur_state.execute(player, "other_kong") player.proto.send() if owner.table.player_prompts: #print "when pong kong ", owner.table.player_prompts owner.machine.trigger(PauseState()) return else: owner.table.reset_proto(ACTION) for player in owner.table.player_dict.values(): player.proto.p = copy(proto) player.proto.send() # for player in owner.table.player_dict.values(): # player.proto.p = copy(proto) # player.proto.send() 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)
def load(self): if not self.p or not self.c: return if self.c == DRAW: proto = game_pb2.DrawResponse() elif self.c == DISCARD: proto = game_pb2.DiscardResponse() elif self.c == ACTION: proto = game_pb2.ActionResponse() elif self.c == DEAL: proto = game_pb2.DealResponse() elif self.c == HAIDI: proto = game_pb2.QH_HaiDiResponse() else: proto = game_pb2.PromptResponse() self.p = proto.ParseFromString(str(self.p))
def load(self): if not self.p or not self.c: return if self.c == DRAW: proto = game_pb2.DrawResponse() elif self.c == POKER_DISCARD: proto = game_pb2.PokerDiscardResponse() elif self.c == ACTION: proto = game_pb2.ActionResponse() elif self.c == DEAL: proto = game_pb2.PokerDealResponse() elif self.c == ROB_DEALER or ROB_DEALER_HAPPY: proto = game_pb2.RobLandLordReponse() elif self.c == NOTIFY_DISCARD: proto = game_pb2.PokerDiscardNotifyResponse() elif self.c == POKER_DOUBLE: proto = game_pb2.PokerDoubleResponse() else: proto = game_pb2.PromptResponse() self.p = proto.ParseFromString(str(self.p))
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()
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()
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)
def enter(self, owner): super(QGWinState, self).enter(owner) # 广播玩家胡牌 proto = game_pb2.ActionResponse() proto.player = owner.uuid owner.win_total_cnt += 1 active_card = owner.action_op_card proto.trigger_seat = owner.table.active_seat trigger_player = owner.table.seat_dict[owner.table.active_seat] trigger_player.win_type = PLAYER_WIN_PAO # 如果触发玩家上一个状态是自摸明杠则需要从他的手牌中删除此牌, 不重复删除 if active_card in trigger_player.cards_kong_exposed: trigger_player.cards_pong.extend([active_card] * 3) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.kong_pong_cnt -= 1 trigger_player.cards_group.remove(active_card) proto.active_type = PLAYER_ACTION_TYPE_WIN_DISCARD owner.win_type = PLAYER_WIN_TYPE_DISCARD owner.win_card = active_card owner.win_discard_cnt += 1 owner.table.winner_list.append(owner.seat) owner.table.loser_list = [trigger_player.seat] owner.cards_win = owner.cards_in_hand owner.cards_win.append(active_card) owner.cards_win.sort() _, flags = owner.cards_ready_hand[owner.win_card] #print 'player seat:', owner.seat, ', uuid:', owner.uuid, 'win flags:', flags flags.append('QGH') owner.win_flags.extend(flags) if "JIAHU" in owner.win_flags and not owner.isJia: owner.win_flags.remove("JIAHU") # 需要将胡的牌单独拿出来 owner.cards_win.remove(owner.win_card) proto.active_card.card = owner.win_card for card in owner.cards_win: cards = proto.card.add() cards.card = card owner.dumps() if owner.isJia: if owner.table.conf.bian_hu_jia() and "BIANHU" in owner.win_flags: owner.win_flags.remove("BIANHU") owner.win_flags.append("JIAHU") base_score = WIN_DISCARD if owner.table.dealer_seat == owner.seat: base_score = base_score * 2 if len(trigger_player.cards_group) == 0: #门清 base_score = base_score * 2 if owner.isJia: base_score = base_score * 2 if trigger_player.seat == owner.table.dealer_seat: base_score = base_score * 2 if owner.table.conf.is_fan_hu( 'PIAOHU') and 'PIAOHU' in owner.win_flags: base_score *= 4 base_score *= 2 #抢杠 if owner.table.conf.pao_score_self(): calculate_final_score(trigger_player, owner, base_score) if owner.table.conf.pao_score_pay_all(): b_score = 0 for k, v in owner.table.seat_dict.items(): if k == owner.seat: continue b_score += self.calc_score(v, owner) calculate_final_score(trigger_player, owner, b_score) if owner.table.conf.pao_score_all_pay(): for k, v in owner.table.seat_dict.items(): if k == owner.seat: continue if k == trigger_player.seat: calculate_final_score(trigger_player, owner, base_score) else: pay_score = self.calc_score(v, owner) calculate_final_score(v, owner, pay_score) trigger_player.dumps() for player in owner.table.player_dict.values(): send(ACTION, proto, player.session) if owner.table.dealer_seat != owner.seat: owner.table.dealer_seat = owner.table.seat_dict[ owner.table.dealer_seat].next_seat # 圈 if not owner.table.conf.is_round: owner.table.cur_round += 1 if (owner.table.cur_round % owner.table.chairs) == 1: owner.table.cur_circle += 1 #owner.table.dealer_seat = owner.seat owner.table.logger.info("player {0} win {1} type {2}".format( owner.seat, owner.win_card, owner.win_type)) owner.table.machine.trigger(EndState())
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())
def enter(self, owner): super(WinState, self).enter(owner) # 广播玩家胡牌 proto = game_pb2.ActionResponse() proto.player = owner.uuid owner.win_total_cnt += 1 if owner.table.active_seat == owner.seat: 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] # 需要将胡的牌进行效验整理 tfs = TFS() owner.cards_win = tfs.start(owner.cards_in_hand) if owner.table.conf.is_qxd() and try_compose_seven_pairs( owner.cards_in_hand): owner.cards_win = sorted(owner.cards_in_hand) for player in owner.table.player_dict.values(): if player.uuid == owner.uuid: owner.score += 6 owner.total += 6 else: player.score -= 2 player.total -= 2 owner.table.loser_list.append(player.seat) else: active_card = owner.action_op_card proto.trigger_seat = owner.table.active_seat trigger_player = owner.table.seat_dict[owner.table.active_seat] trigger_player.win_type = PLAYER_WIN_PAO # 如果触发玩家上一个状态是自摸明杠则需要从他的手牌中删除此牌, 不重复删除 if trigger_player.machine.last_state.name == "DrawExposedKongState" \ and active_card in trigger_player.cards_kong_exposed: trigger_player.kong_pong_cnt -= 1 trigger_player.cards_pong.extend([active_card] * 3) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_kong_exposed.remove(active_card) trigger_player.cards_group.remove(active_card) proto.active_type = PLAYER_ACTION_TYPE_WIN_DISCARD owner.win_type = PLAYER_WIN_TYPE_DISCARD owner.win_card = active_card owner.win_discard_cnt += 1 owner.table.winner_list.append(owner.seat) owner.table.loser_list = [trigger_player.seat] cards_win = owner.cards_in_hand cards_win.append(active_card) tfs = TFS() owner.cards_win = tfs.start(cards_win) if owner.table.conf.is_qxd() and try_compose_seven_pairs( cards_win): owner.cards_win = sorted(cards_win) trigger_player.score -= 1 trigger_player.total -= 1 owner.score += 1 owner.total += 1 trigger_player.dumps() # 需要将胡的牌单独拿出来 owner.cards_win.remove(owner.win_card) proto.active_card.card = owner.win_card for card in owner.cards_win: cards = proto.card.add() cards.card = card owner.dumps() for player in owner.table.player_dict.values(): send(ACTION, proto, player.session) owner.table.logger.info("player {0} win {1} type {2}".format( owner.seat, owner.win_card, owner.win_type))
def enter(self, owner): super(DiscardWinState, self).enter(owner) # 广播玩家胡牌 proto = game_pb2.ActionResponse() proto.player = owner.uuid owner.win_total_cnt += 1 active_card = owner.action_op_card proto.trigger_seat = owner.table.active_seat trigger_player = owner.table.seat_dict[owner.table.active_seat] trigger_player.win_type = PLAYER_WIN_PAO proto.active_type = PLAYER_ACTION_TYPE_WIN_DISCARD owner.win_type = PLAYER_WIN_TYPE_DISCARD owner.win_card = active_card owner.win_discard_cnt += 1 owner.table.winner_list.append(owner.seat) owner.table.loser_list = [trigger_player.seat] owner.cards_win = owner.cards_in_hand owner.cards_win.append(active_card) owner.cards_win.sort() _, flags = owner.cards_ready_hand[owner.win_card] trigger_player.dumps() owner.win_flags.extend(flags) if "JIAHU" in owner.win_flags and not owner.isJia: owner.win_flags.remove("JIAHU") #owner.table.dealer_seat = owner.seat # 需要将胡的牌单独拿出来 owner.cards_win.remove(owner.win_card) proto.active_card.card = owner.win_card for card in owner.cards_win: cards = proto.card.add() cards.card = card owner.dumps() #穷胡计分 base_score = WIN_DISCARD if trigger_player.gang_pao_card != 0 and owner.table.conf.is_fan_hu( 'GSDP'): owner.win_flags.append('GSDP') base_score = base_score * 2 if owner.table.dealer_seat == owner.seat: owner.win_flags.append('ZHHU') base_score = base_score * 2 if len(trigger_player.cards_group) == 0: #门清 base_score = base_score * 2 if owner.isJia: base_score = base_score * 2 if owner.table.conf.bian_hu_jia() and "BIANHU" in owner.win_flags: owner.win_flags.remove("BIANHU") if "JIAHU" not in owner.win_flags: owner.win_flags.append("JIAHU") # 删除普通胡显示边胡 if not owner.isJia and "BIANHU" in owner.win_flags: owner.win_flags.remove("BIANHU") if trigger_player.seat == owner.table.dealer_seat: base_score = base_score * 2 if owner.table.conf.is_fan_hu( 'PIAOHU') and "PIAOHU" in owner.win_flags: base_score = base_score * 4 # 不加下面这行会不会崩溃? all_close_door = False if owner.table.chairs > 2: all_close_door = True for k, v in owner.table.seat_dict.items(): if k != owner.seat and v.is_open_door(): all_close_door = False if all_close_door: owner.win_flags.append('SJMQ') base_score = base_score * 2 #if len(owner.cards_ready_hand) == 1 and #base_score += (owner.kong_exposed_cnt + owner.kong_pong_cnt) * SCORE_BASE# + owner.kong_concealed_cnt * 2 * SCORE_BASE if owner.table.conf.pao_score_self(): calculate_final_score(trigger_player, owner, base_score) if owner.table.conf.pao_score_pay_all(): b_score = 0 for k, v in owner.table.seat_dict.items(): if k == owner.seat: continue b_score += self.calc_score(v, owner, all_close_door) calculate_final_score(trigger_player, owner, b_score) if owner.table.conf.pao_score_all_pay(): for k, v in owner.table.seat_dict.items(): if k == owner.seat: continue pay_score = self.calc_score(v, owner, all_close_door) calculate_final_score(v, owner, pay_score) trigger_player.dumps() for player in owner.table.player_dict.values(): send(ACTION, proto, player.session) if owner.table.dealer_seat != owner.seat: owner.table.dealer_seat = owner.table.seat_dict[ owner.table.dealer_seat].next_seat # 圈 if not owner.table.conf.is_round: owner.table.cur_round += 1 if (owner.table.cur_round % owner.table.chairs) == 1: owner.table.cur_circle += 1 owner.table.logger.info("player {0} win {1} type {2}".format( owner.seat, owner.win_card, owner.win_type)) owner.table.machine.trigger(EndState())