彧哉 风光无限342111
关注数: 2 粉丝数: 0 发帖数: 273 关注贴吧数: 45
根据今天的鸣潮团子结果写了个python代码 import random from collections import defaultdict class DangoRace: def __init__(self, odds=None): self.dangos = list(range(6)) # 六个团子编号0-5 self.dango_names = ["今汐", "长离", "卡卡罗", "守岸人", "椿", "珂莱塔"] self.positions = defaultdict(list) # 存储每个位置的堆叠(底层到顶层) self.current_positions = {} # 存储每个团子的当前位置 self.special_actions = defaultdict(bool) # 初始化所有团子在起始位置0(独立存在,不堆叠) for dango in self.dangos: self.current_positions[dango] = 0 self.positions[0].append(dango) # 每个团子独立加入位置0 # 初始化赔率,默认为1.25 self.odds = odds if odds else [1.25] * 6 def simulate_race(self): winner = None while winner is None: # 随机决定本回合行动顺序 turn_order = self.dangos.copy() random.shuffle(turn_order) # 处理长离团子的特殊行动 if self.special_actions[1]: if 1 in turn_order: turn_order.remove(1) turn_order.append(1) self.special_actions[1] = False for dango in turn_order: current_pos = self.current_positions[dango] if current_pos >= 24: continue stack = self.positions.get(current_pos, []) if not stack: continue try: idx = stack.index(dango) except ValueError: continue # 特殊技能处理 dice = self.roll_dice(dango) dice = self.apply_skills_before_move(dango, dice, stack, idx) new_pos = current_pos + dice new_pos = min(new_pos, 24) dice = self.apply_skills_after_move(dango, dice, new_pos) # 关键修改点:位置0的特殊移动逻辑 if current_pos == 0: # 仅移动自身,不带走其他团子 moving_stack = [dango] stack.remove(dango) # 从原位置单独移除 if not stack: # 清理空位置 del self.positions[current_pos] else: # 原有堆叠移动逻辑 moving_stack = stack[idx:] del stack[idx:] if not stack: del self.positions[current_pos] # 添加到新位置(堆叠到顶部) self.positions[new_pos].extend(moving_stack) for d in moving_stack: self.current_positions[d] = new_pos if new_pos == 24: winner = moving_stack[0] break if 24 in self.positions and self.positions[24]: winner = self.positions[24][0] break # 获取完整排名(逻辑不变) final_ranking = [] final_stack = self.positions.get(24, []) if final_stack: final_ranking.extend(final_stack[::-1]) remaining_dangos = [d for d in self.dangos if d not in final_stack] remaining_dangos.sort(key=lambda x: (-self.current_positions[x], x)) final_ranking.extend(remaining_dangos) return final_ranking # 以下方法保持不变 def roll_dice(self, dango): if dango == 4: return random.choice([2, 3]) return random.randint(1, 3) def apply_skills_before_move(self, dango, dice, stack, idx): if dango == 0 and len(stack) > 1 and idx < len(stack) - 1: if random.random() < 0.4: new_idx = len(stack) - 1 stack.insert(new_idx, stack.pop(idx)) if dango == 1 and idx > 0: if random.random() < 0.65: self.special_actions[1] = True if dango == 2: current_pos = self.current_positions[dango] others = [self.current_positions[d] for d in self.dangos if d != dango] if current_pos == min(others + [current_pos]): dice += 3 if dango == 4: if random.random() < 0.5: bonus = len(stack) - 1 dice += bonus return dice def apply_skills_after_move(self, dango, dice, new_pos): if dango == 5: if random.random() < 0.28: dice *= 2 return dice # 示例运行部分保持不变 if __name__ == "__main__": default_odds = [1.25] * 6 user_odds = [] print("请输入每个团子的赔率(默认为1.25):") for i, name in enumerate(["今汐", "长离", "卡卡罗", "守岸人", "椿", "珂莱塔"]): while True: try: value = input(f"{name}团子的赔率 ({i+1}/6): ") if value.strip() == "": user_odds.append(default_odds[i]) break odds = float(value) if odds > 0: user_odds.append(odds) break else: print("赔率必须大于0,请重新输入。") except ValueError: print("请输入有效数字。") win_counts = defaultdict(int) total_races = 10000 for _ in range(total_races): race = DangoRace(odds=user_odds) ranking = race.simulate_race() if ranking: winner = ranking[0] win_counts[winner] += 1 dango_names = ["今汐", "长离", "卡卡罗", "守岸人", "椿", "珂莱塔"] print("\n比赛结果:") print(f"总比赛次数:{total_races}") print("\n每个团子的获胜概率和基础回报率:") for dango in sorted(win_counts.keys()): probability = (win_counts[dango] / total_races) * 100 base_return = probability * user_odds[dango] / 100 print(f"{dango_names[dango]}团子: " f"获胜概率 {probability:.2f}% ({win_counts[dango]}次获胜), " f"基础回报率 {base_return:.4f}") total_investment_return = sum((win_counts[dango] / total_races) * user_odds[dango] for dango in win_counts) print(f"\n总投资回报率: {total_investment_return:.4f}")
1 下一页