From 0ab487d6cd2ebf109be991645c896cdf0fcb2fbc Mon Sep 17 00:00:00 2001 From: MistEO Date: Fri, 10 Sep 2021 00:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E5=BB=BA=E5=88=B6?= =?UTF-8?q?=E9=80=A0and=E8=B4=B8=E6=98=93=E7=AB=99=EF=BC=8C=E9=9D=9E?= =?UTF-8?q?=E7=BB=84=E5=90=88=E5=B9=B2=E5=91=98=E7=9A=84=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MeoAssistance/AsstDef.h | 5 + MeoAssistance/InfrastConfiger.cpp | 12 +- MeoAssistance/InfrastConfiger.h | 2 +- MeoAssistance/InfrastStationTask.cpp | 61 ++- MeoAssistance/InfrastStationTask.h | 1 + resource/infrast.json | 643 ++++++++++++++++++++++++++- 6 files changed, 695 insertions(+), 29 deletions(-) diff --git a/MeoAssistance/AsstDef.h b/MeoAssistance/AsstDef.h index 4955c02f96..e1647fb38b 100644 --- a/MeoAssistance/AsstDef.h +++ b/MeoAssistance/AsstDef.h @@ -226,6 +226,11 @@ namespace asst { return name == rhs.name; } }; + // 基建干员组合 + struct OperInfrastComb { + std::vector comb; + int efficiency = 0; // 组合的效率 + }; constexpr double DoubleDiff = 1e-12; } diff --git a/MeoAssistance/InfrastConfiger.cpp b/MeoAssistance/InfrastConfiger.cpp index 3624397357..559916a0b7 100644 --- a/MeoAssistance/InfrastConfiger.cpp +++ b/MeoAssistance/InfrastConfiger.cpp @@ -31,18 +31,22 @@ bool InfrastConfiger::parse(json::value&& json) { std::string key = facility["facility"].as_string(); - std::vector> combs_vec; - for (json::value& comb : facility["combs"].as_array()) + std::vector combs_vec; + for (json::value& comb_json : facility["combs"].as_array()) { std::vector opers; - for (json::value& oper : comb["opers"].as_array()) { + for (json::value& oper : comb_json["opers"].as_array()) { OperInfrastInfo info; info.name = oper["name"].as_string(); info.elite = oper.get("elite", 0); info.level = oper.get("level", 0); opers.emplace_back(std::move(info)); } - combs_vec.emplace_back(std::move(opers)); + OperInfrastComb comb; + comb.comb = std::move(opers); + comb.efficiency = comb_json["efficiency"].as_integer(); + + combs_vec.emplace_back(std::move(comb)); } m_infrast_combs.emplace(key, std::move(combs_vec)); diff --git a/MeoAssistance/InfrastConfiger.h b/MeoAssistance/InfrastConfiger.h index 217026b999..28d7ab3368 100644 --- a/MeoAssistance/InfrastConfiger.h +++ b/MeoAssistance/InfrastConfiger.h @@ -23,7 +23,7 @@ namespace asst { std::unordered_map m_oper_name_feat; // 根据关键字需要特征检测干员名:如果OCR识别到了key的内容但是却没有value的内容,则进行特征检测进一步确认 std::unordered_set m_oper_name_feat_whatever; // 无论如何都进行特征检测的干员名 // 各个设施内的可能干员组合,注意值是vector,是有序的 - std::unordered_map>> m_infrast_combs; + std::unordered_map> m_infrast_combs; // 各个设施的识别结束标记,识别到这个名字就停止继续识别了,一般放列表中最后几个人名 std::unordered_map> m_infrast_end_flag; diff --git a/MeoAssistance/InfrastStationTask.cpp b/MeoAssistance/InfrastStationTask.cpp index 61ef79c0ed..4ffb0d4e6c 100644 --- a/MeoAssistance/InfrastStationTask.cpp +++ b/MeoAssistance/InfrastStationTask.cpp @@ -89,6 +89,7 @@ bool asst::InfrastStationTask::run() return false; } auto cur_opers_info = std::move(detect_ret.value()); + // TODO,可以识别一次,把前6个最优解都列出来(最多6个制造站),然后就不用每次都识别并计算最优解了 std::list optimal_comb = calc_optimal_comb(cur_opers_info); bool select_ret = swipe_and_select(optimal_comb); } @@ -171,35 +172,61 @@ std::list asst::InfrastStationTask::calc_optimal_comb( // 配置文件中的干员组合,和抓出来的干员名比对,如果组合中的干员都有,那就用这个组合 // 注意配置中的干员组合需要是有序的 // Todo 时间复杂度起飞了,需要优化下 - std::list optimal_comb; // OperInfrastInfo是带精英化和等级信息的,基建里识别不到,也用不到,这里只保留干员名 - for (const auto& name_vec : InfrastConfiger::get_instance().m_infrast_combs[m_facility]) { - int count = 0; - std::list temp_comb; - for (const OperInfrastInfo& info : name_vec) { - // 找到了干员名,而且当前精英化等级需要大于等于配置文件中要求的精英化等级 - if (cur_opers_info.find(info.name) != cur_opers_info.cend() - && cur_opers_info.at(info.name).elite >= info.elite) { - ++count; - temp_comb.emplace_back(info.name); + + OperInfrastComb three_optimal_comb; // 三人组合的最优解 + OperInfrastComb single_optimal_comb; // 由三个单人组成的组合 中的最优解 + for (const OperInfrastComb& comb : InfrastConfiger::get_instance().m_infrast_combs[m_facility]) { + if (comb.comb.size() == 3) { + int count = 0; + for (const OperInfrastInfo& info : comb.comb) { + // 找到了干员名,而且当前精英化等级需要大于等于配置文件中要求的精英化等级 + auto find_iter = cur_opers_info.find(info.name); + if (find_iter != cur_opers_info.cend() + && find_iter->second.elite >= info.elite) { + ++count; + } + else { + break; + } } - else { + if (count == 3) { + three_optimal_comb = comb; break; } } - if (count != 0 && count == name_vec.size()) { - optimal_comb = temp_comb; - break; + else if (comb.comb.size() == 1) { + const auto& cur_info = comb.comb.at(0); + auto find_iter = cur_opers_info.find(cur_info.name); + if (find_iter != cur_opers_info.cend() + && find_iter->second.elite >= cur_info.elite) { + single_optimal_comb.comb.emplace_back(cur_info); + single_optimal_comb.efficiency += comb.efficiency; + if (single_optimal_comb.comb.size() >= 3) { + break; + } + } + } + else { + // 配置文件中没有两人的,不可能走到这里,TODO,报错。 + // 以后游戏更新了有双人的再说,思路是一样的,找出双人组合中干员都有的+单人组合中有的。 + // 再建一个OperInfrastComb,比一下效率 } } + OperInfrastComb optimal_comb = three_optimal_comb.efficiency >= single_optimal_comb.efficiency + ? three_optimal_comb : single_optimal_comb; + + std::list optimal_opers_name; std::vector optimal_comb_gbk; // 给回调json用的,gbk的 - for (const std::string& name : optimal_comb) { - optimal_comb_gbk.emplace_back(Utf8ToGbk(name)); + for (const auto& info : optimal_comb.comb) { + optimal_opers_name.emplace_back(info.name); + optimal_comb_gbk.emplace_back(Utf8ToGbk(info.name)); } + json::value opers_json; opers_json["comb"] = json::array(optimal_comb_gbk); m_callback(AsstMsg::InfrastComb, opers_json, m_callback_arg); - return optimal_comb; + return optimal_opers_name; } bool asst::InfrastStationTask::swipe_and_select(std::list& name_comb, int swipe_max_times) diff --git a/MeoAssistance/InfrastStationTask.h b/MeoAssistance/InfrastStationTask.h index 4e8fcbf8f6..23a0102741 100644 --- a/MeoAssistance/InfrastStationTask.h +++ b/MeoAssistance/InfrastStationTask.h @@ -17,6 +17,7 @@ namespace asst { } protected: constexpr static int SwipeMaxTimes = 17; + constexpr static int MaxOpers = 3; // 单个制造站/贸易站最大干员数 // 一边滑动一边识别 virtual std::optional> swipe_and_detect() override; diff --git a/resource/infrast.json b/resource/infrast.json index 1f7d7c409f..0f8c727f38 100644 --- a/resource/infrast.json +++ b/resource/infrast.json @@ -54,6 +54,249 @@ } ], "efficiency": 90 + }, + { + "opers": [ + { + "name": "妲愮惀", + "elite": 2 + } + ], + "efficiency": 40 + }, + { + "opers": [ + { + "name": "椋熼搧鍏", + "elite": 2 + } + ], + "efficiency": 35 + }, + { + "opers": [ + { + "name": "鏂姜鑰", + "elite": 2 + } + ], + "efficiency": 35 + }, + { + "opers": [ + { + "name": "鐧介洩", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "闇滃彾", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "绾㈣眴", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "Castle-3", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "姊呭皵", + "elite": 2 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "甯曟媺鏂", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "姘存湀", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鐧介潰楦", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "璧粯", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鏉拌タ鍗", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鍙查兘鍗庡痉", + "elite": 1 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "棣欒崏", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "璋冮甯", + "elite": 1 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鐭虫", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "娉℃櫘鍗", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鑺", + "elite": 0 + } + ], + "efficiency": 23 + }, + { + "opers": [ + { + "name": "鍏嬫礇鏂", + "elite": 0 + } + ], + "efficiency": 20 + }, + { + "opers": [ + { + "name": "璞嗚嫍", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "娴佹槦", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "澶滃垁", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "铔囧睜绠", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "榛戣", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "鍗$紘", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "绫虫牸椴", + "elite": 0 + } + ], + "efficiency": 10 } ], "endFlag": [ @@ -90,21 +333,255 @@ { "opers": [ { - "name": "鐮", - "elite": 2 - }, - { - "name": "澶滅儫", + "name": "璐濆", "elite": 0 }, + { + "name": "娉℃场", + "elite": 1 + }, + { + "name": "鐏", + "elite": 2 + } + ], + "efficiency": 93 + }, + { + "opers": [ + { + "name": "娓╄拏", + "elite": 2 + }, + { + "name": "寮傚", + "elite": 2 + }, + { + "name": "妫毢", + "elite": 2 + } + ], + "efficiency": 90 + }, + { + "opers": [ + { + "name": "鐮", + "elite": 2 + } + ], + "efficiency": 35 + }, + { + "opers": [ { "name": "鏂戠偣", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "澶滅儫", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "甯曟媺鏂", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "妲愮惀", + "elite": 2 + } + ], + "efficiency": 40 + }, + { + "opers": [ + { + "name": "姊呭皵", + "elite": 2 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "姘存湀", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鐧介潰楦", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "璧粯", + "elite": 2 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鏉拌タ鍗", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鍙查兘鍗庡痉", "elite": 1 } ], - "efficiency": 95 + "efficiency": 25 + }, + { + "opers": [ + { + "name": "棣欒崏", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "璋冮甯", + "elite": 1 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鐭虫", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "娉℃櫘鍗", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "鑺", + "elite": 0 + } + ], + "efficiency": 23 + }, + { + "opers": [ + { + "name": "鍏嬫礇鏂", + "elite": 0 + } + ], + "efficiency": 20 + }, + { + "opers": [ + { + "name": "璞嗚嫍", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "娴佹槦", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "澶滃垁", + "elite": 0 + } + ], + "efficiency": 15 + }, + { + "opers": [ + { + "name": "铔囧睜绠", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "榛戣", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "鍗$紘", + "elite": 0 + } + ], + "efficiency": 10 + }, + { + "opers": [ + { + "name": "绫虫牸椴", + "elite": 0 + } + ], + "efficiency": 10 } ], + "endFlag": [ "瀹夋磥鑾夊", "宓敞", @@ -188,6 +665,159 @@ } ], "efficiency": 100 + }, + { + "opers": [ + { + "name": "绌哄鸡", + "elite": 2 + } + ], + "efficiency": 40 + }, + { + "opers": [ + { + "name": "鑳藉ぉ浣", + "elite": 2 + } + ], + "efficiency": 35 + }, + { + "opers": [ + { + "name": "闆泬", + "elite": 2 + } + ], + "efficiency": 35 + }, + { + "opers": [ + { + "name": "鍙ょ背", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "绌虹垎", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "鏈堣澶", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "绌", + "elite": 2 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "瀹夋瘮灏", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "缂犱父", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "鑺", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "鑺", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "鎱曟柉", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "澶滃垁", + "elite": 0 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "澶滅儫", + "elite": 1 + } + ], + "efficiency": 30 + }, + { + "opers": [ + { + "name": "鐜叞鑾", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "姊撳叞", + "elite": 0 + } + ], + "efficiency": 25 + }, + { + "opers": [ + { + "name": "杩滃北", + "elite": 0 + } + ], + "efficiency": 25 } ], "endFlag": [ @@ -207,7 +837,6 @@ "澶滆幒", "鎺ㄨ繘涔嬬帇", "鏄熺唺", - "閾剁伆", "娴婂績鏂崱钂", "姝岃暰钂傚▍", "鑾柉鎻愰┈",