123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import datetime
- import json
- import logging
- from itertools import product
- OPTIONS = [101, 102, 103, 301, 302, 303, 304, 305]
- TIMES_LIMIT = 10
- autoOutEnter = 0
- class BetOption:
- def __init__(self, option, odds, limit, total_bet=0):
- self.option = option
- if odds == 0:
- self.odds = 1
- else:
- self.odds = odds
- self.limitRed = limit
- self.total_bet = total_bet
- def to_json(self):
- return {'option': self.option, 'odds': self.odds, 'total_bet': self.total_bet}
- def __str__(self):
- return (f"BetOption(option={self.option}, odds={self.odds}, "
- f"limitRed={self.limitRed}, totalBet={self.total_bet})")
- class BetOptionEncoder(json.JSONEncoder):
- def default(self, obj):
- if isinstance(obj, BetOption):
- return obj.to_json()
-
- return json.JSONEncoder.default(self, obj)
- class User:
-
- def __init__(self, bet_count, uid, amount):
- self.bet_count = bet_count
- self.uid = uid
- self.betAmount = amount
- self.finance = 0
- self.betOptionAmounts = {option: 0 for option in OPTIONS}
- class UserEncoder(json.JSONEncoder):
- def default(self, obj):
- if isinstance(obj, User):
- return {"uid": obj.uid, "bet_count": obj.bet_count, "betAmount": obj.betAmount, "finance": obj.finance}
-
- return json.JSONEncoder.default(self, obj)
- def init_round_option_info():
- global round_option_info
- round_option_info = {option: BetOption(option, 0, 0) for option in OPTIONS}
- round_option_info = {}
- init_round_option_info()
- banker_finance = 0
- DATA_SYN_NOTIFY_UID = -9999
- async def write_message_2_log_file(log):
- with open("开奖记录.log", "a", encoding="utf-8") as f:
- time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- f.write(f"{time}:{log}\n")
- async def deal_message(message, broadcast_func):
- try:
- msg_type, data = parse_message(message)
- if msg_type == "BetNotify":
- await betNotify(data)
- elif msg_type == "GameDataSynNotify":
- await gameDataSynNotify(data)
- elif msg_type == "ShowOddsNotify":
- await ShowOddsNotify(data)
- elif msg_type == "KickNotify":
- await kickNotify(data, broadcast_func)
- elif msg_type == "GameRoundEndNotify":
- await gameRoundEndNotify(data, broadcast_func)
- elif msg_type == "MergeAutoBetNotify":
- await MergeAutoBetNotify(data)
- else:
- logging.info(f"Received message: {message}")
- except Exception as e:
- logging.info(f"Received message: {message}")
- async def judge_auto_out_and_int(broadcast_func):
- global autoOutEnter, TIMES_LIMIT
- autoOutEnter += 1
- if autoOutEnter >= TIMES_LIMIT:
- autoOutEnter = 0
- await broadcast_func('''CMD:
- window.__require("PokerMasterHallSocket").PokerMasterHallSocket.getInstance().requestLeaveRoom();//立即退出
- setTimeout(function(){
- window.HMFExtension.openPokerMasterGameWithRoomId("716619","")
- },3000);//3秒后自动进入
- ''')
- async def gameRoundEndNotify(data, broadcast_func):
- global banker_finance
- await write_message_2_log_file(json.dumps(round_option_info, cls=BetOptionEncoder))
- await write_message_2_log_file(data)
- init_round_option_info()
- await judge_auto_out_and_int(broadcast_func)
- async def win_option_combo_analysis(current_round_bet_amount, win_option):
-
- try:
- win_npc = {key: value for key, value in round_option_info.items() if key in [101, 102, 103]}
- win_card = {key: value for key, value in round_option_info.items() if key in [301, 302, 303, 304, 305]}
-
- combinations = list(product(win_npc.keys(), win_card.keys()))
-
- combination_payouts = []
- for npc_key, card_key in combinations:
- npc_info = win_npc[npc_key]
- card_info = win_card[card_key]
- payout = (npc_info.odds * npc_info.total_bet) + (card_info.odds * card_info.total_bet)
- combination_payouts.append({
- "combo": f"{npc_key}x{card_key}",
- "payout": payout,
- "open": npc_key in win_option and card_key in win_option
- })
-
- sorted_combinations = sorted(combination_payouts, key=lambda x: x["payout"], reverse=True)
-
- with open("庄家盈亏记录.txt", "a", encoding="utf-8") as f:
- label = f"{'标记':<4} {'组合':<10} {'赔付':<15} {'收入':<10}\n"
- print(label)
- f.write(label)
- for item in sorted_combinations:
- combo_key = item["combo"]
- payout = item["payout"]
- income = round((current_round_bet_amount - payout) / 100, 2)
- badge = "√" if item["open"] else "×"
- combos = f"{badge:<4} {combo_key:<10} {round(payout / 100, 2):<15}¥ {income:<10}¥\n"
- print(combos)
- f.write(combos)
- except Exception as e:
- print(e)
- async def bankerSettlement(current_round_income, option_results):
- for open_result in option_results:
-
- option = open_result["option"]
- result = open_result["result"]
-
- option_info_option_ = round_option_info[option]
- odds_rate = option_info_option_.odds
- if result == 1:
-
- final_out = option_info_option_.total_bet * odds_rate
- current_round_income -= final_out
- print(
- f"选项{option}中奖了, 赔率{odds_rate}, 该选项总下注{round(option_info_option_.total_bet / 100, 2)}¥, 赔付了{round(final_out / 100, 2)}¥")
- return current_round_income
- async def kickNotify(data, broadcast_func):
- print(f"被踢下线了: {data}")
- await broadcast_func('''CMD:
- setTimeout(function(){
- window.HMFExtension.openPokerMasterGameWithRoomId("716619","")
- lws.send("====>>>>被踢后3秒自动进入716619房间");
- },3000);//被踢后3秒后自动进入
- ''')
- async def ShowOddsNotify(data):
-
- option_odds = data["option_odds"]
- for optionInfo in option_odds:
- option_ = optionInfo["option"]
- odds_ = optionInfo["odds"] / 100
- limit_red_ = optionInfo["limitRed"]
-
- print(f"选项: {option_}, 赔率: {odds_}, 限红: {limit_red_}, 总下注: {0}")
- round_option_info[option_] = BetOption(option_, odds_, limit_red_, 0)
- async def gameDataSynNotify(data):
-
-
-
- for optionInfo in data["optionInfo"]:
- option_ = optionInfo["option"]
- odds_ = optionInfo["odds"] / 100
- limit_red_ = optionInfo["limitRed"]
- total_bet_ = optionInfo["totalBet"]
-
-
- print(f"同步下注选项: {option_}, 赔率: {odds_}, 限红: {limit_red_}, 总下注: {total_bet_}")
- round_option_info[option_] = BetOption(option_, odds_, limit_red_, total_bet_)
-
-
-
-
-
- print(f"同步后下注信息:", list(map(lambda x: str(x), round_option_info.values())))
- async def MergeAutoBetNotify(data):
- print("收到合并通知")
- bet_notifys = data["notify"]
- for bet_notify in bet_notifys:
- await betNotify(bet_notify)
- async def betNotify(data):
-
-
-
- uid = data["uid"]
- option = data["detail"]["option"]
- bet_amount = data["detail"]["betAmount"]
-
-
-
-
-
-
-
-
-
-
-
-
-
- round_option_info[option].total_bet += bet_amount
-
-
- def parse_message(message):
-
- msg_type, json_str = message.split(':', 1)
-
- data = json.loads(json_str)
-
- return msg_type, data
|