前几天写完作业闲死了,结果想起翁法罗斯剧情,索性我直接让豆包生成了模拟黄金裔收集火种的程序,扮演来古士(doge),让电脑模拟这个过程(最多快模拟了50000次了)
(本人蒟蒻,只能让豆包写)
代码:
#include <bits/stdc++.h>
using namespace std;
// 黄金裔数据结构
struct GoldenDescendant {
string name;
string titanType;
bool fireCollected; // 记录火种是否收集成功
GoldenDescendant(string n, string t) : name(n), titanType(t), fireCollected(false) {}
};
// 模拟结果类型
enum ResultType {
SUCCESS_FIRE_COLLECTED,
SUCCESS_TRAILBLAZER,
RUNNING
};
// 模拟管理器类
class SimulationManager {
private:
vector<GoldenDescendant> goldenDescendants;
const double baseKillProbability; // 盗火行者基础击杀概率
const long double trailblazerProbability; // 开拓者出现概率
// 生成[0,1)随机数
double randDouble() {
return static_cast<double>(rand()) / RAND_MAX;
}
// 执行单次尝试并返回结果,击杀顺序完全随机
bool executeSingleAttempt(bool& trailblazerAppeared, vector<int>& attemptOrder) {
trailblazerAppeared = false;
// 重置所有黄金裔的火种收集状态
for (size_t i = 0; i < goldenDescendants.size(); ++i) {
goldenDescendants[i].fireCollected = false;
}
// 检查开拓者是否出现
if (randDouble() <= trailblazerProbability) {
trailblazerAppeared = true;
return true;
}
// 生成随机顺序(0到11的随机排列)
attemptOrder.clear();
for (int i = 0; i < 12; ++i) {
attemptOrder.push_back(i);
}
random_shuffle(attemptOrder.begin(), attemptOrder.end());
// 按随机顺序检查每个黄金裔是否成功收集火种(使用C++98兼容的for循环)
for (vector<int>::iterator it = attemptOrder.begin(); it != attemptOrder.end(); ++it) {
int idx = *it;
double random = randDouble();
if (random <= baseKillProbability) {
return false; // 被击杀,尝试失败
}
goldenDescendants[idx].fireCollected = true; // 成功收集火种
}
return true; // 所有黄金裔都成功收集火种
}
// 展示单次尝试的详细情况(每次尝试都展示)
void showAttemptDetails(unsigned long long attemptNumber, bool isSuccessful,
bool isTrailblazer, const vector<int>& attemptOrder) {
cout << "\n\n=====================================" << endl;
cout << " 尝试详情: 第 " << attemptNumber << " 次 " << endl;
cout << "=====================================" << endl;
if (isTrailblazer) {
cout << ">>> 特殊事件:开拓者出现了!" << endl;
cout << ">>> 开拓者的到来改变了一切!" << endl;
return;
}
int successCount = 0;
// 统计成功收集火种的数量(使用C++98兼容的for循环)
for (vector<GoldenDescendant>::iterator it = goldenDescendants.begin();
it != goldenDescendants.end(); ++it) {
if (it->fireCollected) {
successCount++;
}
}
cout << ">>> 本次尝试顺序(随机):" << endl;
// 使用C++98兼容的for循环
for (size_t i = 0; i < attemptOrder.size(); ++i) {
int idx = attemptOrder[i];
cout << " " << i+1 << ". " << goldenDescendants[idx].name;
if (i < attemptOrder.size() - 1) cout << " -> ";
}
cout << endl << endl;
// 按随机顺序展示每个黄金裔的情况(使用C++98兼容的for循环)
for (size_t i = 0; i < attemptOrder.size(); ++i) {
int idx = attemptOrder[i];
GoldenDescendant& current = goldenDescendants[idx];
cout << "[" << i + 1 << "/12] " << current.name << "(" << current.titanType << ")" << endl;
cout << "当前击杀概率: " << fixed << setprecision(2) << (baseKillProbability * 100) << "%" << endl;
if (current.fireCollected) {
cout << ">>> 结果:成功收集火种" << endl;
} else {
cout << ">>> 结果:被盗火行者击杀,收集失败" << endl;
}
cout << endl;
}
cout << ">>> 本次尝试总结:" << successCount << "/12 黄金裔成功收集火种" << endl;
if (isSuccessful) {
cout << ">>> 本次尝试结果:成功收集所有火种" << endl;
} else {
cout << ">>> 本次尝试结果:失败" << endl;
}
}
public:
// 构造函数 - 盗火行者击杀概率70%,顺序完全随机
SimulationManager()
: baseKillProbability(0.7), // 盗火行者击杀概率保持70%
trailblazerProbability(2.9806e-26) { // 保持原极低开拓者概率
// 初始化黄金裔列表
goldenDescendants.push_back(GoldenDescendant("白厄", "负世泰坦"));
goldenDescendants.push_back(GoldenDescendant("提宝", "门径泰坦"));
goldenDescendants.push_back(GoldenDescendant("那刻夏", "理性泰坦"));
goldenDescendants.push_back(GoldenDescendant("阿格莱雅", "浪漫泰坦"));
goldenDescendants.push_back(GoldenDescendant("长夜月", "岁月泰坦"));
goldenDescendants.push_back(GoldenDescendant("万敌", "纷争泰坦"));
goldenDescendants.push_back(GoldenDescendant("丹恒", "大地泰坦"));
goldenDescendants.push_back(GoldenDescendant("风瑾", "天空泰坦"));
goldenDescendants.push_back(GoldenDescendant("赛飞儿", "诡计泰坦"));
goldenDescendants.push_back(GoldenDescendant("遐蝶", "死亡泰坦"));
goldenDescendants.push_back(GoldenDescendant("海瑟音", "海洋泰坦"));
goldenDescendants.push_back(GoldenDescendant("刻律德菈", "律法泰坦"));
// 初始化随机数生成器
srand(static_cast<unsigned int>(time(NULL)));
}
void runSimulation() {
cout << "=== 黄金裔火种收集模拟(随机击杀顺序版) ===" << endl;
cout << "成功条件:" << endl;
cout << "1. 所有黄金裔成功收集火种,或" << endl;
cout << "2. 开拓者出现" << endl;
cout << "盗火行者击杀概率: " << fixed << setprecision(0) << (baseKillProbability * 100) << "%" << endl;
cout << "击杀顺序: 完全随机" << endl;
cout << "开拓者单次出现概率: " << fixed << setprecision(26) << (trailblazerProbability * 100) << "%" << endl;
cout << "\n\n=== 开始展示所有尝试的详细情况 ===" << endl;
cout << "程序将无限次尝试,每次尝试都详细展示,直到成功为止" << endl;
cout << "按Enter键开始...";
cin.get();
ResultType result = RUNNING;
unsigned long long attemptsNeeded = 0;
bool trailblazerAppeared = false;
vector<int> attemptOrder; // 记录本次尝试的顺序
clock_t startTime = clock();
// 无限次尝试,直到成功,每次都详细展示
while (result == RUNNING) {
attemptsNeeded++;
// 执行本次尝试(击杀顺序随机)
bool attemptSuccess = executeSingleAttempt(trailblazerAppeared, attemptOrder);
// 详细展示本次尝试(每次都展示)
showAttemptDetails(attemptsNeeded, attemptSuccess, trailblazerAppeared, attemptOrder);
// 显示大型里程碑进度(每100次尝试)
if (attemptsNeeded % 100 == 0) {
cout << "\n>>> 已累计尝试 " << attemptsNeeded << " 次 <<<" << endl;
}
// 检查是否成功
if (attemptSuccess) {
if (trailblazerAppeared) {
result = SUCCESS_TRAILBLAZER;
} else {
result = SUCCESS_FIRE_COLLECTED;
}
break;
}
}
clock_t endTime = clock();
double elapsed = static_cast<double>(endTime - startTime) / CLOCKS_PER_SEC;
// 输出最终结果
cout << "\n\n=== 最终结果 ===" << endl;
cout << "模拟总耗时: " << fixed << setprecision(6) << elapsed << "秒" << endl;
cout << "总尝试次数: " << attemptsNeeded << endl;
if (result == SUCCESS_TRAILBLAZER) {
cout << ">>> 成功:开拓者出现 <<<" << endl;
cout << "在第 " << attemptsNeeded << " 次尝试中,开拓者出现了!" << endl;
} else if (result == SUCCESS_FIRE_COLLECTED) {
cout << ">>> 成功:火种收集完成 <<<" << endl;
cout << "在第 " << attemptsNeeded << " 次尝试中,所有黄金裔成功收集到火种!" << endl;
}
cout << "\n统计信息:" << endl;
cout << "平均每秒尝试次数: " << fixed << setprecision(0)
<< (attemptsNeeded / elapsed) << endl;
}
};
int main() {
SimulationManager simulator;
simulator.runSimulation();
// 等待用户按键后退出
cout << "\n按Enter键退出...";
cin.get();
return 0;
}