Skip to content

Commit

Permalink
规则读取与结果恢复
Browse files Browse the repository at this point in the history
  • Loading branch information
hjenryin committed Feb 3, 2025
1 parent 9f4b600 commit c6e4ce3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
8 changes: 1 addition & 7 deletions src/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,12 @@ States ChefRandomizer::operator()(States s) {
debugIntegrity(s);
double random = (double)rand() / RAND_MAX;
double p_randomChef = 0.9;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
int path;
#pragma GCC diagnostic pop
calls++;
p_randomChef = 0.85;
if (random < 1 - p_randomChef) {
path = 0;
success += swapChefTool(s);

} else if (random >= 1 - p_randomChef) {
path = 1;
success += randomChef(s);
}

Expand Down Expand Up @@ -253,7 +247,7 @@ bool Randomizer::unrepeatedRandomRecipe(const Skill &skill, Recipe **recipes,
int count = 0;
Recipe *r = NULL;
auto &rl = this->r;
float p_sameRarity = 0.4;
double p_sameRarity = 0.4;
do {
if (rand() / RAND_MAX < p_sameRarity) {
int rarity = recipes[index]->rarity;
Expand Down
9 changes: 6 additions & 3 deletions src/StatesRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ void StatesSerializer::serialize(std::ostream &stream, States *state) {

States *StatesSerializer::deserialize(std::istream &stream) {
States *state = new States();
std::vector<Chef> chefs(NUM_CHEFS);
std::vector<int> recipe(DISH_PER_CHEF * NUM_CHEFS);
std::vector<Chef> chefs;
std::vector<int> recipe;
std::stringstream iss;
decompress(stream, iss);
cereal::PortableBinaryInputArchive archive(iss);
archive(chefs, recipe);

if (chefs.size() != NUM_CHEFS ||
recipe.size() != NUM_CHEFS * DISH_PER_CHEF) {
return NULL;
}
for (size_t i = 0; i < NUM_CHEFS; i++) {
state->setChef(i, chefs[i]);
}
Expand Down
28 changes: 13 additions & 15 deletions src/banquetRuleGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ loadBanquetRuleFromJson(const Json::Value &rulesTarget, const GDMap &allBuffs,
/**
* @todo Error handling.
*/
std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
bool print) {
std::tuple<int, int, RuleInfo>
loadFirstBanquetRule(const Json::Value &gameData) {
auto &buffsGD = gameData["buffs"];
auto &intentsGD = gameData["intents"];
auto &rulesGD = gameData["rules"];
Expand All @@ -113,15 +113,6 @@ std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
for (auto &intent : intentsGD) {
intentsMap[intent["intentId"].asInt()] = intent;
}
// find the rule in rulesGD with Id ruleID
Json::Value ruleGD = rulesGD[0];
if (print) {
auto ruleName = ruleGD.isMember("Title") ? ruleGD["Title"].asString()
: ruleGD["title"].asString();
std::cout << "请核对规则:" << UNDERLINE << ruleName << NO_FORMAT
<< "。若规则还是上周的,说明还没有更新,请过段时间再运行。"
<< std::endl;
}

std::vector<std::string> ruleNames;
for (const auto &rule : rulesGD) {
Expand All @@ -132,10 +123,17 @@ std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
int selectedIndex = 0;
bool ruleSelected = false;

std::cout << "默认最新规则:" << ruleNames[selectedIndex]
<< ",确认请按回车,按其他任意键选择其他规则。" << std::endl;
int key = _getch();
if (key == 13) { // Enter
ruleSelected = true;
}

while (!ruleSelected) {
system("cls");
std::cout << "请使用方向键选择规则,若没有本周规则,说明还没有更新,请"
"过段时间再运行"
std::cout << "请使用方向键选择规则,回车确认,若没有本周规则,说明还没"
"有更新,请过段时间再运行"
<< std::endl;
for (size_t i = 0; i < ruleNames.size(); ++i) {
if (i == selectedIndex) {
Expand All @@ -145,7 +143,7 @@ std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
}
}

int key = _getch();
key = _getch();
switch (key) {
case 72: // Up arrow
selectedIndex =
Expand All @@ -163,7 +161,7 @@ std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
}

std::cout << "已选择规则:" << ruleNames[selectedIndex] << std::endl;
ruleGD = rulesGD[selectedIndex];
auto ruleGD = rulesGD[selectedIndex];
Json::Value rulesTarget;
if (ruleGD.isMember("Group")) {
rulesTarget = ruleGD["Group"];
Expand Down
3 changes: 1 addition & 2 deletions src/banquetRuleGen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ void banquetRuleGenerated(BanquetRuleTogether *rule, States &s,
*
* @param ruleID If -1, use the first rule in the json file.
*/
std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData,
bool print = false);
std::tuple<int, int, RuleInfo> loadFirstBanquetRule(const Json::Value &gameData);
std::tuple<int, int, RuleInfo>
loadBanquetRuleFromInput(const Json::Value &ruleData, bool print = false);
#endif
3 changes: 1 addition & 2 deletions src/bcjh_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ int main(int argc, char *argv[]) {
<< NO_FORMAT << std::endl;
}
testJsonUpdate(gameData, usrData);
auto [num_guests, chefs_per_guest, rl] =
loadFirstBanquetRule(ruleData, true);
auto [num_guests, chefs_per_guest, rl] = loadFirstBanquetRule(ruleData);
if (num_guests == -1) {
std::cout << "读取规则失败。" << std::endl;
exit(1);
Expand Down

0 comments on commit c6e4ce3

Please sign in to comment.