|
@@ -1,6 +1,7 @@
|
|
|
import datetime
|
|
|
import json
|
|
|
import logging
|
|
|
+from itertools import product
|
|
|
|
|
|
|
|
|
OPTIONS = [101, 102, 103, 301, 302, 303, 304, 305]
|
|
@@ -12,7 +13,8 @@ class BetOption:
|
|
|
self.option = option
|
|
|
if odds == 0:
|
|
|
self.odds = 1
|
|
|
- self.odds = odds
|
|
|
+ else:
|
|
|
+ self.odds = odds
|
|
|
self.limitRed = limit
|
|
|
self.total_bet = total_bet
|
|
|
|
|
@@ -85,18 +87,87 @@ async def deal_message(message, broadcast_func):
|
|
|
|
|
|
async def gameRoundEndNotify(data):
|
|
|
global banker_finance
|
|
|
- print(f"收到结束下注GameRoundEndNotify")
|
|
|
+ time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ print(f"{time}:收到结束下注GameRoundEndNotify")
|
|
|
|
|
|
-
|
|
|
+
|
|
|
current_round_income = 0
|
|
|
- all_bet_amount = 0
|
|
|
+
|
|
|
+ current_round_bet_amount = 0
|
|
|
|
|
|
for option in round_option_info.values():
|
|
|
- all_bet_amount += option.total_bet
|
|
|
- current_round_income = all_bet_amount
|
|
|
+ current_round_bet_amount += option.total_bet
|
|
|
+ current_round_income = current_round_bet_amount
|
|
|
|
|
|
|
|
|
option_results = data["optionResult"]
|
|
|
+ win_option = [x["option"] for x in option_results if x["result"] == 1]
|
|
|
+ print(f"本轮中奖选项: {win_option}")
|
|
|
+
|
|
|
+ current_round_income = await bankerSettlement(current_round_income, option_results)
|
|
|
+
|
|
|
+ await playerSettlement(option_results)
|
|
|
+
|
|
|
+ await win_option_combo_analysis(current_round_bet_amount, win_option)
|
|
|
+
|
|
|
+ banker_finance += current_round_income
|
|
|
+ print(
|
|
|
+ f"庄家金币: {round(banker_finance / 100, 2)}¥ 本轮总下注{round(current_round_bet_amount / 100, 2)}¥ 收入: {round(current_round_income / 100, 2)}¥")
|
|
|
+
|
|
|
+
|
|
|
+ with open("庄家盈亏记录.txt", "a", encoding="utf-8") as f:
|
|
|
+ finalxx = f"{time}:庄家金币: {banker_finance / 100}¥ 本轮总下注{current_round_bet_amount / 100}¥ 收入: {current_round_income / 100}¥"
|
|
|
+ print(finalxx)
|
|
|
+ f.write(finalxx + "\n")
|
|
|
+
|
|
|
+ with open("用户记录.txt", "a", encoding="utf-8") as f:
|
|
|
+
|
|
|
+ f.write(f"{time}:{json.dumps(round_user_betinfo, cls=UserEncoder)}\n")
|
|
|
+ round_user_betinfo.clear()
|
|
|
+ init_round_option_info()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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"{'标记':<2} {'组合':<10} {'赔付':<15} {'收入':<10}\n"
|
|
|
+ print(label)
|
|
|
+ f.write(label)
|
|
|
+ for item in sorted_combinations:
|
|
|
+ combo_key = item["combo"]
|
|
|
+ payout = round(item["payout"]/100, 2)
|
|
|
+ income = round((current_round_bet_amount - payout) / 100, 2)
|
|
|
+ badge = "√" if item["open"] else "×"
|
|
|
+ combos = f"{badge:<2} {combo_key:<10} {payout:<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"]
|
|
@@ -109,32 +180,24 @@ async def gameRoundEndNotify(data):
|
|
|
final_out = option_info_option_.total_bet * odds_rate
|
|
|
current_round_income -= final_out
|
|
|
print(
|
|
|
- f"选项{option}中奖了, 赔率{odds_rate}, 该选项总下注{option_info_option_.total_bet / 100}¥, 赔付了{final_out / 100}¥")
|
|
|
+ f"选项{option}中奖了, 赔率{odds_rate}, 该选项总下注{round(option_info_option_.total_bet / 100, 2)}¥, 赔付了{round(final_out / 100, 2)}¥")
|
|
|
+ return current_round_income
|
|
|
|
|
|
-
|
|
|
- for user in round_user_betinfo.values():
|
|
|
- for option in user.betOptionAmounts:
|
|
|
- open_result = next(filter(lambda opt: opt["option"] == option, option_results))
|
|
|
- odds_rate = round_option_info[option].odds
|
|
|
- if open_result is not None and open_result["result"] == 1:
|
|
|
- user.finance += user.betOptionAmounts[option] * odds_rate
|
|
|
- else:
|
|
|
- user.finance -= user.betOptionAmounts[option]
|
|
|
- banker_finance += current_round_income
|
|
|
- print(f"庄家金币: {banker_finance / 100}¥ 本轮总下注{all_bet_amount / 100}¥ 收入: {current_round_income / 100}¥")
|
|
|
|
|
|
- time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
-
|
|
|
- with open("庄家盈亏记录.txt", "a", encoding="utf-8") as f:
|
|
|
- finalxx = f"{time}:庄家金币: {banker_finance / 100}¥ 本轮总收入: {current_round_income / 100}¥"
|
|
|
- print(finalxx)
|
|
|
- f.write(finalxx + "\n")
|
|
|
-
|
|
|
- with open("用户记录.txt", "a", encoding="utf-8") as f:
|
|
|
-
|
|
|
- f.write(f"{time}:{json.dumps(round_user_betinfo, cls=UserEncoder)}\n")
|
|
|
- round_user_betinfo.clear()
|
|
|
- init_round_option_info()
|
|
|
+
|
|
|
+async def playerSettlement(option_results):
|
|
|
+
|
|
|
+ try:
|
|
|
+ for user in round_user_betinfo.values():
|
|
|
+ for option in user.betOptionAmounts:
|
|
|
+ open_result = next(filter(lambda x: x["option"] == option, option_results))
|
|
|
+ odds_rate = round_option_info[option].odds
|
|
|
+ if open_result is not None and open_result["result"] == 1:
|
|
|
+ user.finance += user.betOptionAmounts[option] * odds_rate
|
|
|
+ else:
|
|
|
+ user.finance -= user.betOptionAmounts[option]
|
|
|
+ except Exception as e:
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
async def kickNotify(data, broadcast_func):
|