Now have the ability to do partial solutions that will create potential paths to the goal, and a test that runs the scripts from plans in different scenarios. Also, this ai_debug thing needs some work.
This commit is contained in:
parent
3f83d3f0bb
commit
fc66d221d4
11 changed files with 252 additions and 107 deletions
56
ai_debug.cpp
Normal file
56
ai_debug.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "ai_debug.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
/*
|
||||
* Yeah this is weird but it's only to debug things like
|
||||
* the preconditions which are weirdly done.
|
||||
*/
|
||||
void dump_only(AIProfile& profile, State state, bool matching, bool show_as) {
|
||||
for(auto& [name, name_id] : profile) {
|
||||
if(state.test(name_id) == matching) {
|
||||
fmt::println("\t{}={}", name, show_as);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dump_state(AIProfile& profile, State state) {
|
||||
for(auto& [name, name_id] : profile) {
|
||||
fmt::println("\t{}={}", name,
|
||||
state.test(name_id));
|
||||
}
|
||||
}
|
||||
|
||||
void dump_action(AIProfile& profile, Action& action) {
|
||||
fmt::println(" --ACTION: {}, cost={}", action.$name, action.$cost);
|
||||
|
||||
fmt::println(" PRECONDS:");
|
||||
dump_only(profile, action.$positive_preconds, true, true);
|
||||
dump_only(profile, action.$negative_preconds, true, false);
|
||||
|
||||
fmt::println(" EFFECTS:");
|
||||
dump_only(profile, action.$positive_effects, true, true);
|
||||
dump_only(profile, action.$negative_effects, true, false);
|
||||
}
|
||||
|
||||
State dump_script(AIProfile& profile, std::string msg, State start, Script& script) {
|
||||
fmt::println("--SCRIPT DUMP: {}", msg);
|
||||
fmt::println("# STATE BEFORE:");
|
||||
dump_state(profile, start);
|
||||
fmt::print("% ACTIONS PLANNED:");
|
||||
for(auto& action : script) {
|
||||
fmt::print("{} ", action.$name);
|
||||
}
|
||||
fmt::print("\n");
|
||||
|
||||
for(auto& action : script) {
|
||||
dump_action(profile, action);
|
||||
|
||||
start = action.apply_effect(start);
|
||||
fmt::println(" ## STATE AFTER:");
|
||||
dump_state(profile, start);
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue