示例#1
0
    def update_remain_bet_time(self):
        """
        更新当局游戏剩余时间
        :return:
        """
        self.remain_bet_time -= 1

        if self.remain_bet_time > 0:
            self.call_Later(Config().interval_one_round,
                            self.update_remain_bet_time)
            notice_cotent = json.dumps({
                "spade": RoundManager().cur_round_spade_num,
                "heart": RoundManager().cur_round_heart_num,
                "club": RoundManager().cur_round_club_num,
                "diamond": RoundManager().cur_round_diamond_num,
                "joker": RoundManager().cur_round_joker_num,
                "remain_bet_time": self.remain_bet_time
            })
            print "update_remain_bet_time notice_cotent=", notice_cotent
            if UserManager().get_classic_wx_session_list():
                # 向经典五星场内所有玩家推送信息
                send_all(UserManager().get_classic_wx_session_list(),
                         KEY_PUSH_CURRENT_BET_INFO, notice_cotent)
        else:
            self.call_Later(1, self.settle)
示例#2
0
    def start_bet(self):
        """
        游戏开始,可以押注
        :return:
        """
        if self.stop_time and self.stop_time <= time.time():
            self.is_stop = 1
            logger.debug(u"维护中,游戏暂停")
            send_all(UserManager().get_session_list(), KEY_PUSH_SYSTEM_NOTICE,
                     self.stop_content)
            self.call_Later(10, self.start_bet)
            return
        else:
            self.is_stop = 0
        print u"开始投注"
        self.is_can_bet = True
        self.remain_bet_time = Config().max_bet_time
        self.remain_show_time = Config().max_show_time
        self.call_Later(Config().interval_one_round,
                        self.update_remain_bet_time)

        RoundManager().new_round()
        self.notify_user_game_start()
示例#3
0
def enter(session_id):
    """
    进入经典五星
    :param session_id: 用户会话ID ("proxy,1")
    :return:
    """
    user = UserManager().get_user_by_sessionid(session_id)

    if user is None:
        return 0, {"info": "user is none"}
    user_id = UserManager().get_user_by_sessionid(session_id).user_id
    UserManager().add_session_to_classic_wx(
        session_id)  # 将用户会话加入经典五星会话列表便于全局推送
    cur_round_bet_info = {
        "own_bet":
        RoundManager().cur_user_bet_info.get(user_id, {}),
        "bet_static": [
            RoundManager().cur_round_spade_num,
            RoundManager().cur_round_heart_num,
            RoundManager().cur_round_club_num,
            RoundManager().cur_round_diamond_num,
            RoundManager().cur_round_joker_num
        ]
    }
    return 1, {
        "max_bet_num": Config().max_bet_num,
        "min_bet_num": Config().min_bet_num,
        "max_bet_time": Config().max_bet_time,
        "max_show_time": Config().max_show_time,
        "last_records": RoundManager().get_last_n_round_card_type(),
        "gold": user.gold,
        "bet_info": cur_round_bet_info,
        "remain_bet_time": AwardManager().get_remain_bet_time(),
        "remain_show_time": AwardManager().get_remain_show_time(),
        "is_can_bet": AwardManager().get_is_can_bet()
    }
示例#4
0
 def calculate_away_info(info, card_type):
     """
     根据每个人压住,计算开奖时的返回分数,包含开王时的特殊处理
     :param info: 个人押注信息
     :param card_type: 开奖花色
     :return: 个人中奖具体分数
     """
     bet_sum = 0  # 用于记录非王 压住总点数
     user_cur_award = info[CARD_DESC[card_type]] * Config().odds[card_type]
     if card_type == CARD_JOKER:
         bet_sum += info[CARD_DESC[0]]
         bet_sum += info[CARD_DESC[1]]
         bet_sum += info[CARD_DESC[2]]
         bet_sum += info[CARD_DESC[3]]
         user_cur_award += bet_sum
     return user_cur_award
示例#5
0
    def get_random_card(self):
        """
        返回   (花色,牌点数)
        """
        card_probabilitys = list(copy.deepcopy(Config().card_probability))
        cur_award_pool = RoundManager().cur_award_pool_gold

        # 普通牌中各花色占比
        common_card_weight_ratio = []
        # 黑红梅方(普通牌)总概率和
        common_probabilitys = card_probabilitys[0] + card_probabilitys[
            1] + card_probabilitys[2] + card_probabilitys[3]
        for i in range(0, 4):
            ratio = 1.0 * card_probabilitys[i] / common_probabilitys
            common_card_weight_ratio.append(ratio)

        if cur_award_pool > Config().add_base_min_gold:
            # 触发大小王概率增益
            if cur_award_pool < Config().add_base_max_gold:
                add_probability = 1.0 * (cur_award_pool - Config().add_base_min_gold) / Config().base_ratio \
                                  * Config().add_ratio
            else:
                add_probability = 1.0 * (Config().add_base_max_gold - Config().add_base_min_gold) / Config().base_ratio \
                                  * Config().add_ratio
            card_probabilitys[4] += add_probability
            for i in range(0, 4):
                card_probabilitys[
                    i] -= add_probability * common_card_weight_ratio[i]
        elif cur_award_pool < Config().deduce_base_max_gold:
            # 触发大小王概率减益
            if cur_award_pool > Config().deduce_base_min_gold:
                deduce_probability = 1.0 * (cur_award_pool - Config().deduce_base_min_gold) / Config().base_ratio \
                                     * Config().deduce_ratio
            else:
                deduce_probability = 1.0 * (
                    Config().deduce_base_max_gold - Config().deduce_base_min_gold) / Config().base_ratio \
                                     * Config().deduce_ratio
            card_probabilitys[4] -= deduce_probability
            for i in range(0, 4):
                card_probabilitys[
                    i] += deduce_probability * common_card_weight_ratio[i]
        # 将开奖概率装进单例中, 用于查询调用
        Config().card_probabilitys = card_probabilitys
        logger.info("random card probability : {0}".format(
            str(card_probabilitys)))

        random_card_type = weight_choice(card_probabilitys)
        if 4 == random_card_type:
            return random_card_type, random.randint(1, 2)
        else:
            return random_card_type, random.randint(1, 13)
示例#6
0
    def settle(self):
        """
        结算

        :return:
        """
        self.is_can_bet = False  # 调整押注状态为 False
        print u"开始结算"
        card_type, card_value = self.get_random_card()
        print u"随机卡牌:", card_type, card_value
        # 计算开不同花色时系统输赢情况
        print "RoundManager().cur_round_total =", RoundManager(
        ).cur_round_total
        print "RoundManager().cur_round_spade_num =", -RoundManager(
        ).cur_round_spade_num * Config().odds[0]
        print "RoundManager().cur_round_heart_num =", -RoundManager(
        ).cur_round_heart_num * Config().odds[0]
        print "RoundManager().cur_round_club_num =", -RoundManager(
        ).cur_round_club_num * Config().odds[0]
        print "RoundManager().cur_round_diamond_num =", -RoundManager(
        ).cur_round_diamond_num * Config().odds[0]
        print "RoundManager().cur_round_joker_num =", RoundManager(
        ).cur_round_joker_num * (1 - Config().odds[4])
        print "RoundManager().cur_round_consume_gold =", -RoundManager(
        ).cur_round_consume_gold
        # 计算出开每个点数时候庄家的输赢情况
        diff_card_award_change = [
            RoundManager().cur_round_total -
            RoundManager().cur_round_spade_num * Config().odds[0] -
            RoundManager().cur_round_consume_gold,
            RoundManager().cur_round_total -
            RoundManager().cur_round_heart_num * Config().odds[1] -
            RoundManager().cur_round_consume_gold,
            RoundManager().cur_round_total -
            RoundManager().cur_round_club_num * Config().odds[2] -
            RoundManager().cur_round_consume_gold,
            RoundManager().cur_round_total -
            RoundManager().cur_round_diamond_num * Config().odds[3] -
            RoundManager().cur_round_consume_gold,
            RoundManager().cur_round_joker_num * (1 - Config().odds[4]) -
            RoundManager().cur_round_consume_gold
        ]
        print "diff_card_award_change;", diff_card_award_change
        # 当前开出的花色, 输的点数+ 奖池现有金额, 为负数时 出发作弊开奖流程
        if 0 > RoundManager(
        ).cur_award_pool_gold + diff_card_award_change[card_type]:
            # 奖池不够扣,重新随机
            temp = []
            for i in range(0, 4):
                if diff_card_award_change[i] < 0:
                    temp.append(0)
                else:
                    temp.append(1)

            card_type = weight_choice(temp)
            card_value = random.randint(1, 13)
        print "card_type=", card_type, "card_value=", card_value
        # 增加作测试能开出指定花色
        is_debug = GlobalObject().json_config.get("debug", 0)
        if is_debug and self.test_next_color:
            card_type = self.test_next_color.pop()
            if card_type == 4:
                card_value = random.randint(1, 2)
            logger.info("debug test next color is :{0}".format(card_type))
        # 测试功能完毕************
        show_card = CardManager().cal_card(card_type, card_value)
        logger.info("settle random card:{0}, {1}, {2}".format(
            show_card, card_type, card_value))

        self.record_round_info(diff_card_award_change[card_type], show_card)
        self.give_award_to_user(show_card)

        self.call_Later(1, self.update_remain_show_time)
示例#7
0
def bet(session_id, bet_num, bet_card_type):
    cur_user = UserManager().get_user_by_sessionid(session_id)
    cur_gold = cur_user.gold
    info = RoundManager().cur_user_bet_info.get(cur_user.user_id, None)
    if info is None:
        info = {
            "spade": 0,
            "heart": 0,
            "club": 0,
            "diamond": 0,
            "joker": 0,
            "gold": cur_gold
        }

    if not cur_user:
        info["desc"] = "user not exist!"
        return 0, info

    if bet_card_type not in [
            CARD_SPADE, CARD_HEART, CARD_CLUB, CARD_DIAMOND, CARD_JOKER
    ]:
        info["desc"] = "invalid bet card type!"
        return 0, info

    total_bet_num = info.get(CARD_DESC[bet_card_type]) + bet_num

    if total_bet_num < Config().min_bet_num or total_bet_num > Config(
    ).max_bet_num:
        info["desc"] = "invalid bet num!"
        info["gold"] = cur_gold
        return 0, info

    if cur_user.gold < bet_num:
        info["desc"] = NEED_MORE_GOLD
        return 0, info
    # 押注时先更改内存中的金币数量, 在结算的时候写入数据库
    cur_user.gold -= bet_num
    # 押注时更改数据金币数量 TODO 此时需要将金币梳理储存在内存,在结算时统一更改
    # cur_gold = cur_user.set_user_gold(-1 * bet_num)
    bet_spade = 0
    bet_heart = 0
    bet_club = 0
    bet_diamond = 0
    bet_joker = 0
    if CARD_SPADE == bet_card_type:
        bet_spade += bet_num
    elif CARD_HEART == bet_card_type:
        bet_heart += bet_num
    elif CARD_CLUB == bet_card_type:
        bet_club += bet_num
    elif CARD_DIAMOND == bet_card_type:
        bet_diamond += bet_num
    else:
        bet_joker += bet_num

    RoundManager().update_bet_info(cur_user.user_id,
                                   spade_change=bet_spade,
                                   heart_change=bet_heart,
                                   club_change=bet_club,
                                   diamond_change=bet_diamond,
                                   joker_change=bet_joker)
    # 获取当局用户押注信息
    player_bet_info = {
        "spade": RoundManager().cur_user_bet_info[cur_user.user_id]["spade"],
        "heart": RoundManager().cur_user_bet_info[cur_user.user_id]["heart"],
        "club": RoundManager().cur_user_bet_info[cur_user.user_id]["club"],
        "diamond":
        RoundManager().cur_user_bet_info[cur_user.user_id]["diamond"],
        "joker": RoundManager().cur_user_bet_info[cur_user.user_id]["joker"]
    }
    return 1, {
        "spade": RoundManager().cur_round_spade_num,
        "heart": RoundManager().cur_round_heart_num,
        "club": RoundManager().cur_round_club_num,
        "diamond": RoundManager().cur_round_diamond_num,
        "joker": RoundManager().cur_round_joker_num,
        "gold": cur_user.gold,
        "player_bet_info": player_bet_info
    }
示例#8
0
    def render(self, request):
        # 从数据库获取概率相关数据
        game_config = GameConfig.get_game_config_info()
        Config().add_base_max_gold = game_config["add_base_max_gold"]
        # self.card_probability = (2439, 4878, 7195, 9512, 10000)         # 各种花色开奖概率
        Config().card_probability = game_config["card_probability"]  # 各种花色开奖概率
        Config().consume_ratio = game_config["consume_ratio"]  # 抽成比例

        # 大小王概率调整规则
        Config().add_base_min_gold = game_config[
            "add_base_min_gold"]  # 触发概率增益金币数额下限
        Config().add_base_max_gold = game_config[
            "add_base_max_gold"]  # 触发概率增益金币数额上限
        Config().deduce_base_min_gold = game_config[
            "deduce_base_min_gold"]  # 触发概率减益金币数额下限
        Config().deduce_base_max_gold = game_config[
            "deduce_base_max_gold"]  # 触发概率减益金币数额上限
        Config().base_ratio = game_config["base_ratio"]  # 每多少数额金币变化触发增减益
        Config().add_ratio = game_config["add_ratio"]  # 每次增益概率幅度(万分比)
        Config().deduce_ratio = game_config["deduce_ratio"]  # 每次减益概率幅度(万分比)

        Config().max_bet_num = game_config["max_bet_num"]  # 最大投注
        Config().min_bet_num = game_config["min_bet_num"]  # 最小投注

        Config().record_card_num = game_config[
            "record_card_num"]  # 最多显示多少局开奖花色详情

        Config().interval_one_round = game_config[
            "interval_one_round"]  # 秒为单位记录广播间隔
        return "ok"
示例#9
0
 def render(self, request):
     return json.dumps(Config().game_config_to_dict())