Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vakomash committed Mar 17, 2024
1 parent a090a1b commit e5113f2
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 174 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Ofast")
endif()
if(STATIC)
set( BUILD_SHARED_LIBRARIES OFF)
set( BOOST_USE_STATIC_LIBS ON )
set( Boost_USE_STATIC_LIBS ON )
set( CMAKE_EXE_LINKER_FLAGS "-static")
endif()
Expand All @@ -36,7 +35,7 @@ if (OPENMP_FOUND)
endif()
endif()
find_package(Boost COMPONENTS system thread filesystem regex timer REQUIRED)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
include_directories( ${Boost_INCLUDE_DIR} )

target_link_libraries(tuo ${Boost_LIBRARIES} )

Expand Down
346 changes: 174 additions & 172 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,204 +3268,206 @@ DeckResults run(int argc, const char **argv)
}

if (!tokenParsed)
if (strcmp(argv[argIndex], "genetic") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), genetic));
if (std::get<1>(opt_todo.back()) < 10)
if (strcmp(argv[argIndex], "genetic") == 0)
{
opt_num_threads = 1;
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), genetic));
if (std::get<1>(opt_todo.back()) < 10)
{
opt_num_threads = 1;
}
opt_do_optimization = true;
opt_multi_optimization = true;
argIndex += 1;
}
opt_do_optimization = true;
opt_multi_optimization = true;
argIndex += 1;
}
else if (strcmp(argv[argIndex], "genetic-pool") == 0 || strcmp(argv[argIndex], "beam-size") == 0 || strcmp(argv[argIndex], "size") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
pool_size = std::stod(argv[argIndex + 1]);
argIndex += 1;
}
else if (strcmp(argv[argIndex], "genetic-gen") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
generations = std::stod(argv[argIndex + 1]);
argIndex += 1;
}
else if (strcmp(argv[argIndex], "genetic-opts") == 0)
{
if (check_input_amount(argc, argv, argIndex, 3))
exit(1);
opt_pool_keep = std::stod(argv[argIndex + 1]);
opt_pool_cross = std::stod(argv[argIndex + 2]);
opt_pool_mutate = std::stod(argv[argIndex + 3]);
argIndex += 3;
}
else if (strcmp(argv[argIndex], "beam") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), beam));
if (std::get<1>(opt_todo.back()) < 10)
else if (strcmp(argv[argIndex], "genetic-pool") == 0 || strcmp(argv[argIndex], "beam-size") == 0 || strcmp(argv[argIndex], "size") == 0)
{
opt_num_threads = 1;
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
pool_size = std::stod(argv[argIndex + 1]);
argIndex += 1;
}
opt_do_optimization = true;
opt_multi_optimization = true;
argIndex += 1;
}
else if (strcmp(argv[argIndex], "reorder") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), reorder));
if (std::get<1>(opt_todo.back()) < 10)
else if (strcmp(argv[argIndex], "genetic-gen") == 0)
{
opt_num_threads = 1;
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
generations = std::stod(argv[argIndex + 1]);
argIndex += 1;
}
opt_do_reorder = true;
argIndex += 1;
}
else if (strncmp(argv[argIndex], "scale-opts:", 11) == 0)
{
std::string climb_opts_str(argv[argIndex] + 11);
boost::tokenizer<boost::char_delimiters_separator<char>> climb_opts{climb_opts_str, boost::char_delimiters_separator<char>{false, ",", ""}};
for (const auto &opt : climb_opts)
else if (strcmp(argv[argIndex], "genetic-opts") == 0)
{
const auto dot_pos = opt.find(".");
const auto slash_pos = opt.find("/");
const bool has_value = (dot_pos != std::string::npos);
if (slash_pos == std::string::npos)
throw std::runtime_error("scale-opts:" + opt + " requires an argument");
const std::string &opt_type = has_value ? opt.substr(0, dot_pos) : "";
const std::string opt_name{has_value ? opt.substr(dot_pos + 1, slash_pos - dot_pos - 1) : opt.substr(0, slash_pos)};
const std::string opt_value{opt.substr(slash_pos + 1)};
if ((opt_name == "hp"))
{
hp_scale = atof(opt_value.c_str());
}
else if ((opt_name == "atk"))
{
atk_scale = atof(opt_value.c_str());
}
else if (opt_name == "x")
{
x_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
}
else if (opt_name == "n")
if (check_input_amount(argc, argv, argIndex, 3))
exit(1);
opt_pool_keep = std::stod(argv[argIndex + 1]);
opt_pool_cross = std::stod(argv[argIndex + 2]);
opt_pool_mutate = std::stod(argv[argIndex + 3]);
argIndex += 3;
}
else if (strcmp(argv[argIndex], "beam") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), beam));
if (std::get<1>(opt_todo.back()) < 10)
{
n_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
opt_num_threads = 1;
}
else if (opt_name == "c")
opt_do_optimization = true;
opt_multi_optimization = true;
argIndex += 1;
}
else if (strcmp(argv[argIndex], "reorder") == 0)
{
if (check_input_amount(argc, argv, argIndex, 1))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), reorder));
if (std::get<1>(opt_todo.back()) < 10)
{
c_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
opt_num_threads = 1;
}
else
opt_do_reorder = true;
argIndex += 1;
}
else if (strncmp(argv[argIndex], "scale-opts:", 11) == 0)
{
std::string climb_opts_str(argv[argIndex] + 11);
boost::tokenizer<boost::char_delimiters_separator<char>> climb_opts{ climb_opts_str, boost::char_delimiters_separator<char>{false, ",", ""} };
for (const auto& opt : climb_opts)
{
std::cerr << "Error: Unknown scale option " << opt_name << " of " << opt_type;
if (has_value)
const auto dot_pos = opt.find(".");
const auto slash_pos = opt.find("/");
const bool has_value = (dot_pos != std::string::npos);
if (slash_pos == std::string::npos)
throw std::runtime_error("scale-opts:" + opt + " requires an argument");
const std::string& opt_type = has_value ? opt.substr(0, dot_pos) : "";
const std::string opt_name{ has_value ? opt.substr(dot_pos + 1, slash_pos - dot_pos - 1) : opt.substr(0, slash_pos) };
const std::string opt_value{ opt.substr(slash_pos + 1) };
if ((opt_name == "hp"))
{
std::cerr << " (value is: " << opt_value << ")";
hp_scale = atof(opt_value.c_str());
}
else if ((opt_name == "atk"))
{
atk_scale = atof(opt_value.c_str());
}
else if (opt_name == "x")
{
x_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
}
else if (opt_name == "n")
{
n_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
}
else if (opt_name == "c")
{
c_skill_scale[skill_name_to_id(opt_type)] = atof(opt_value.c_str());
}
else
{
std::cerr << "Error: Unknown scale option " << opt_name << " of " << opt_type;
if (has_value)
{
std::cerr << " (value is: " << opt_value << ")";
}
std::cerr << std::endl;
exit(1);
}
std::cerr << std::endl;
exit(1);
}
}
}
// climbing options
else if (strncmp(argv[argIndex], "climb-opts:", 11) == 0)
{
std::string climb_opts_str(argv[argIndex] + 11);
boost::tokenizer<boost::char_delimiters_separator<char>> climb_opts{climb_opts_str, boost::char_delimiters_separator<char>{false, ",", ""}};
for (const auto &opt : climb_opts)
// climbing options
else if (strncmp(argv[argIndex], "climb-opts:", 11) == 0)
{
const auto delim_pos = opt.find("=");
const bool has_value = (delim_pos != std::string::npos);
const std::string &opt_name = has_value ? opt.substr(0, delim_pos) : opt;
const std::string opt_value{has_value ? opt.substr(delim_pos + 1) : opt};
auto ensure_opt_value = [](const bool has_value, const std::string &opt_name)
std::string climb_opts_str(argv[argIndex] + 11);
boost::tokenizer<boost::char_delimiters_separator<char>> climb_opts{ climb_opts_str, boost::char_delimiters_separator<char>{false, ",", ""} };
for (const auto& opt : climb_opts)
{
if (!has_value)
const auto delim_pos = opt.find("=");
const bool has_value = (delim_pos != std::string::npos);
const std::string& opt_name = has_value ? opt.substr(0, delim_pos) : opt;
const std::string opt_value{ has_value ? opt.substr(delim_pos + 1) : opt };
auto ensure_opt_value = [](const bool has_value, const std::string& opt_name)
{
if (!has_value)
{
throw std::runtime_error("climb-opts:" + opt_name + " requires an argument");
}
};
if ((opt_name == "iter-mul") or (opt_name == "iterations-multiplier"))
{
throw std::runtime_error("climb-opts:" + opt_name + " requires an argument");
ensure_opt_value(has_value, opt_name);
iterations_multiplier = std::stoi(opt_value);
}
};
if ((opt_name == "iter-mul") or (opt_name == "iterations-multiplier"))
{
ensure_opt_value(has_value, opt_name);
iterations_multiplier = std::stoi(opt_value);
}
else if ((opt_name == "egc") or (opt_name == "endgame-commander") or (opt_name == "min-commander-fusion-level"))
{
ensure_opt_value(has_value, opt_name);
use_fused_commander_level = std::stoi(opt_value);
}
else if (opt_name == "use-all-commander-levels")
{
use_top_level_commander = false;
}
else if (opt_name == "use-all-card-levels")
{
use_top_level_card = false;
}
else if ((opt_name == "recent-boost") or (opt_name == "rb")) // prefer new cards in hill climb and break climb loop faster
{
prefered_recent = true;
}
else if ((opt_name == "recent-boost-times") or (opt_name == "rbt")) // prefer new cards in hill climb and break climb loop faster
{
ensure_opt_value(has_value, opt_name);
prefered_factor = std::stoi(opt_value);
}
else if ((opt_name == "recent-boost-percent") or (opt_name == "rbp")) // prefer new cards in hill climb and break climb loop faster
{
ensure_opt_value(has_value, opt_name);
recent_percent = std::stoi(opt_value);
}
else if ((opt_name == "otd") or (opt_name == "open-the-deck"))
{
mode_open_the_deck = true;
}
else
{
std::cerr << "Error: Unknown climb option " << opt_name;
if (has_value)
else if ((opt_name == "egc") or (opt_name == "endgame-commander") or (opt_name == "min-commander-fusion-level"))
{
std::cerr << " (value is: " << opt_value << ")";
ensure_opt_value(has_value, opt_name);
use_fused_commander_level = std::stoi(opt_value);
}
else if (opt_name == "use-all-commander-levels")
{
use_top_level_commander = false;
}
else if (opt_name == "use-all-card-levels")
{
use_top_level_card = false;
}
else if ((opt_name == "recent-boost") or (opt_name == "rb")) // prefer new cards in hill climb and break climb loop faster
{
prefered_recent = true;
}
else if ((opt_name == "recent-boost-times") or (opt_name == "rbt")) // prefer new cards in hill climb and break climb loop faster
{
ensure_opt_value(has_value, opt_name);
prefered_factor = std::stoi(opt_value);
}
else if ((opt_name == "recent-boost-percent") or (opt_name == "rbp")) // prefer new cards in hill climb and break climb loop faster
{
ensure_opt_value(has_value, opt_name);
recent_percent = std::stoi(opt_value);
}
else if ((opt_name == "otd") or (opt_name == "open-the-deck"))
{
mode_open_the_deck = true;
}
else
{
std::cerr << "Error: Unknown climb option " << opt_name;
if (has_value)
{
std::cerr << " (value is: " << opt_value << ")";
}
std::cerr << std::endl;
exit(1);
}
std::cerr << std::endl;
exit(1);
}
}
}
else if (strcmp(argv[argIndex], "debug") == 0)
{
opt_todo.push_back(std::make_tuple(0u, 0u, debug));
opt_num_threads = 1;
// disable saving to db
use_db_write= false;
use_db_load = false;
}
else if (strcmp(argv[argIndex], "debuguntil") == 0)
{
// output the debug info for the first battle that min_score <= score <= max_score.
// E.g., 0 0: lose; 100 100: win (non-raid); 20 100: at least 20 damage (raid).
if (check_input_amount(argc, argv, argIndex, 2))
else if (strcmp(argv[argIndex], "debug") == 0)
{
opt_todo.push_back(std::make_tuple(0u, 0u, debug));
opt_num_threads = 1;
// disable saving to db
use_db_write = false;
use_db_load = false;
}
else if (strcmp(argv[argIndex], "debuguntil") == 0)
{
// output the debug info for the first battle that min_score <= score <= max_score.
// E.g., 0 0: lose; 100 100: win (non-raid); 20 100: at least 20 damage (raid).
if (check_input_amount(argc, argv, argIndex, 2))
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 2]), debuguntil));
opt_num_threads = 1;
argIndex += 2;
// disable saving to db
use_db_write = false;
use_db_load = false;
}
else
{
std::cerr << "Error: Unknown option " << argv[argIndex] << std::endl;
exit(1);
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 2]), debuguntil));
opt_num_threads = 1;
argIndex += 2;
// disable saving to db
use_db_write= false;
use_db_load = false;
}
else
{
std::cerr << "Error: Unknown option " << argv[argIndex] << std::endl;
exit(1);
}
}
}
load_db(prefix);
Expand Down

0 comments on commit e5113f2

Please sign in to comment.