Skip to content

Commit

Permalink
Add Scaling opts
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Oct 7, 2020
1 parent 753c860 commit 715aa24
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
51 changes: 51 additions & 0 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ void init()
eval_iter=8;
eval_turn=8;
requirement.num_cards.clear();
for(unsigned i(0); i < Skill::num_skills;++i){
auto s = static_cast<Skill::Skill>(i);
x_skill_scale[s]=1.0;
n_skill_scale[s]=1.0;
c_skill_scale[s]=1.0;
}
hp_scale = 1.0;
atk_scale = 1.0;
#ifndef NQUEST
//quest = new Quest(); //TODO Quest bugged in Android now here
#endif
Expand Down Expand Up @@ -2329,6 +2337,49 @@ DeckResults run(int argc, const char** argv)
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)
{
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")
{
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);
}
}
}
// climbing options
else if (strncmp(argv[argIndex], "climb-opts:", 11) == 0)
{
Expand Down
6 changes: 6 additions & 0 deletions tyrant_optimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Requirement
#else
#define EXTERN extern
#endif

namespace tuo {
EXTERN Cards all_cards;
EXTERN unsigned opt_num_threads;
Expand Down Expand Up @@ -61,6 +62,11 @@ namespace tuo {
EXTERN unsigned eval_iter;
EXTERN unsigned eval_turn;
EXTERN Requirement requirement;
EXTERN double hp_scale;
EXTERN double atk_scale;
EXTERN std::map<Skill::Skill,double> x_skill_scale;
EXTERN std::map<Skill::Skill,double> n_skill_scale;
EXTERN std::map<Skill::Skill,double> c_skill_scale;
#ifndef NQUEST
EXTERN Quest quest;
#endif
Expand Down
23 changes: 21 additions & 2 deletions xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cards.h"
#include "deck.h"
#include "tyrant.h"
#include "tyrant_optimize.h"
//---------------------- $20 cards.xml parsing ---------------------------------
// Sets: 1 enclave; 2 nexus; 3 blight; 4 purity; 5 homeworld;
// 6 phobos; 7 phobos aftermath; 8 awakening
Expand Down Expand Up @@ -152,6 +153,7 @@ bool parse_file(const std::string & filename, std::vector<char>& buffer, xml_doc
//------------------------------------------------------------------------------
void parse_card_node(Cards& all_cards, Card* card, xml_node<>* card_node)
{
double eps = 1e-4;
xml_node<>* id_node(card_node->first_node("id"));
xml_node<>* card_id_node = card_node->first_node("card_id");
assert(id_node || card_id_node);
Expand All @@ -171,8 +173,15 @@ void parse_card_node(Cards& all_cards, Card* card, xml_node<>* card_node)
if (name_node) { card->m_name = name_node->value(); }
if (level_node) { card->m_level = atoi(level_node->value()); }
if (fusion_level_node) { card->m_fusion_level = atoi(fusion_level_node->value()); }
if (attack_node) { card->m_attack = atoi(attack_node->value()); }
if (health_node) { card->m_health = atoi(health_node->value()); }
if (attack_node) { card->m_attack = atoi(attack_node->value());
if(abs(1-atk_scale)>eps)
card->m_attack = ceil(card->m_attack/(atk_scale));
}
if (health_node) { card->m_health = atoi(health_node->value());
if(abs(1-hp_scale)>eps)
card->m_health = ceil(card->m_health/(hp_scale));

}
if (cost_node) { card->m_delay = atoi(cost_node->value()); }
if (id_node)
{
Expand Down Expand Up @@ -314,6 +323,16 @@ void parse_card_node(Cards& all_cards, Card* card, xml_node<>* card_node)
auto s2 = skill_target_skill(skill_node, "s2");
bool all = skill_node->first_attribute("all");
auto card_id = node_value(skill_node, "card_id", 0);
//scaling
if(abs(1-x_skill_scale[Skill::no_skill]*x_skill_scale[skill_id])>eps)
x = ceil(x/(x_skill_scale[Skill::no_skill]*x_skill_scale[skill_id]));
if(abs(1-n_skill_scale[Skill::no_skill]*n_skill_scale[skill_id])>eps)
n = ceil(n/(n_skill_scale[Skill::no_skill]*n_skill_scale[skill_id]));
if(abs(1-c_skill_scale[Skill::no_skill]*c_skill_scale[skill_id])>eps)
c = ceil(c/(c_skill_scale[Skill::no_skill]*c_skill_scale[skill_id]));



card->add_skill(trig, skill_id, x, y, n, c, s, s2, all, card_id);
}
all_cards.all_cards.push_back(card);
Expand Down

0 comments on commit 715aa24

Please sign in to comment.