你错误理解majorpity了,majorpity应该是,如果majorpity=1 则立刻设置guaranteed=1…
- User
你错误理解majorpity了,majorpity应该是,如果majorpity=1 则立刻设置guaranteed=1 majorpity=0然后模拟,帮我更改,#include #include #include #include #include
// 模拟角色池的抽卡 bool simulateRolePull(bool& guaranteedRole, int& rolePullCount, bool majorPity) { const double baseRate = 0.006; const int pityStart = 73; const int hardPity = 90; const double rateIncrease = 0.062;
double pullRate = baseRate; if (rolePullCount >= pityStart) { pullRate += (rolePullCount - pityStart) * rateIncrease; } bool gotGold = (rolePullCount >= hardPity - 1) || (static_cast<double>(std::rand()) / RAND_MAX) < pullRate; if (gotGold) { rolePullCount = 0; double guaranteedRate = 0.5; // 角色池初始概率 if (guaranteedRole || majorPity || (static_cast<double>(std::rand()) / RAND_MAX) < guaranteedRate) { guaranteedRole = false; return true; // 获取限定物品 } else { guaranteedRole = true; // 下次必定限定 return false; // 非限定 } } else { rolePullCount += 1; } return false;}
// 模拟武器池的抽卡 bool simulateWeaponPull(bool& guaranteedWeapon, int& weaponPullCount, bool majorPity) { const double baseRate = 0.006; const int pityStart = 63; const int hardPity = 80; const double rateIncrease = 0.062;
double pullRate = baseRate; if (weaponPullCount >= pityStart) { pullRate += (weaponPullCount - pityStart) * rateIncrease; } bool gotGold = (weaponPullCount >= hardPity - 1) || (static_cast<double>(std::rand()) / RAND_MAX) < pullRate; if (gotGold) { weaponPullCount = 0; double guaranteedRate = 0.75; // 武器池初始概率 if (guaranteedWeapon || majorPity || (static_cast<double>(std::rand()) / RAND_MAX) < guaranteedRate) { guaranteedWeapon = false; return true; // 获取限定物品 } else { guaranteedWeapon = true; // 下次必定限定 return false; // 非限定 } } else { weaponPullCount += 1; } return false;}
double calculateAveragePulls(int roleCount, int weaponCount) { int totalPulls = 0;
for (int i = 0; i < 10000; ++i) { int pulls = 0; bool guaranteedRole = false, guaranteedWeapon = false; int roleObtained = 0, weaponObtained = 0; int rolePullCount = 0, weaponPullCount = 0; // 先抽角色池 while (roleObtained < roleCount) { if (simulateRolePull(guaranteedRole, rolePullCount, false)) { roleObtained++; } pulls++; } // 再抽武器池 while (weaponObtained < weaponCount) { if (simulateWeaponPull(guaranteedWeapon, weaponPullCount, false)) { weaponObtained++; } pulls++; } totalPulls += pulls; } return static_cast<double>(totalPulls) / 10000.0;}
double simulateWithItems(int roleCount, int weaponCount, int items, int initialRolePulls, int initialWeaponPulls, bool majorPityRole, bool majorPityWeapon) { int successfulSimulations = 0; for (int i = 0; i < 10000; ++i) { int pulls = 0; bool guaranteedRole = majorPityRole, guaranteedWeapon = majorPityWeapon; int roleObtained = 0, weaponObtained = 0; int rolePullCount = initialRolePulls, weaponPullCount = initialWeaponPulls;
- Assistant
- User
99 76 C:\Users\surface\Desktop\srtool\expansions\ratecalc.cpp [Error] invalid initialization of non-const reference of type 'bool&' from an rvalue of type 'bool'
- Assistant
这个错误是因为我们尝试将一个右值(即临时创建的值)传递给一个需要左值引用(可更改的值)的参数。为了避免这个问题,我们应该为
simulateRolePull和simulateWeaponPull函数中的majorPity使用左值引用。让我们对
simulateWithItems函数进行必要的调整以修复该问题:bool simulateRolePull(bool& guaranteedRole, int& rolePullCount, bool& majorPity); bool simulateWeaponPull(bool& guaranteedWeapon, int& weaponPullCount, bool& majorPity); double simulateWithItems(int roleCount, int weaponCount, int items, int initialRolePulls, int initialWeaponPulls, bool majorPityRole, bool majorPityWeapon) { int successfulSimulations = 0; for (int i = 0; i < 10000; ++i) { int pulls = 0; bool guaranteedRole = false, guaranteedWeapon = false; bool currentMajorPityRole = majorPityRole; // 使用临时变量 bool currentMajorPityWeapon = majorPityWeapon; // 使用临时变量 int roleObtained = 0, weaponObtained = 0; int rolePullCount = initialRolePulls, weaponPullCount = initialWeaponPulls; // 先抽角色池 while (roleObtained < roleCount && pulls < items) { if (simulateRolePull(guaranteedRole, rolePullCount, currentMajorPityRole)) { roleObtained++; } pulls++; } // 再抽武器池 while (weaponObtained < weaponCount && pulls < items) { if (simulateWeaponPull(guaranteedWeapon, weaponPullCount, currentMajorPityWeapon)) { weaponObtained++; } pulls++; } if (roleObtained >= roleCount && weaponObtained >= weaponCount) { successfulSimulations++; } } return static_cast<double>(successfulSimulations) / 10000.0 * 100.0; } - User
全部代码
- Assistant
- User
92 70 C:\Users\surface\Desktop\srtool\expansions\ratecalc.cpp [Error] invalid initialization of non-const reference of type 'bool&' from an rvalue of type 'bool'
- Assistant
- User
由于抽卡次数太多,srand time 0仍然会造成大量种子相同影响概率,请你换个方法获取seed
- Assistant
- User
为什么每次结果一样,感觉无效
- Assistant
- User
全部模拟次数改为50000次
- Assistant
- User
可否使用多线程计算
- Assistant
- User
第二个功能怎么没了
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.