Skip to content

Commit

Permalink
Add '+vc-x X' to print output with '!' for best X cards locked. This …
Browse files Browse the repository at this point in the history
…works consistently with parameter files.
  • Loading branch information
APN-Pucky committed Jan 23, 2021
1 parent 55ad5db commit 8798d78
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ test.tuo
.settings/
tets.tuo
params/
cmake_install.cmake
CMakeFiles
CMakeCache.txt
.vscode
26 changes: 13 additions & 13 deletions algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Deck* filter_best_deck(std::vector<Deck*> your_decks, Deck* d1,
best_score = cur_score;

std::cout << "Deck improved: " << d1->hash() <<":";
print_deck_inline(get_deck_cost(d1), best_score, d1);
print_deck_inline(get_deck_cost(d1), best_score,d1);
}
}
return cur_return;
Expand Down Expand Up @@ -151,7 +151,7 @@ DeckResults hill_climbing(unsigned num_min_iterations, unsigned num_iterations,
std::vector<const Card*> best_cards = d1->cards;
unsigned deck_cost = get_deck_cost(d1);
fund = std::max(fund, deck_cost);
print_deck_inline(deck_cost, best_score, d1);
print_deck_inline(deck_cost, best_score, d1,true);
std::mt19937& re = proc.threads_data[0]->re;
unsigned best_gap = check_requirement(d1, requirement
#ifndef NQUEST
Expand Down Expand Up @@ -303,10 +303,10 @@ DeckResults hill_climbing(unsigned num_min_iterations, unsigned num_iterations,
for (auto evaluation: evaluated_decks)
{ simulations += evaluation.second.second; }
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
print_sim_card_values(d1,proc,num_iterations);
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(d1), best_score, d1);
print_deck_inline(get_deck_cost(d1), best_score, d1,true);
print_upgraded_cards(d1);
print_sim_card_values(d1,proc,num_iterations);
return std::make_pair(d1->clone(),best_score);
}

Expand Down Expand Up @@ -351,7 +351,7 @@ DeckResults simulated_annealing(unsigned num_min_iterations, unsigned num_iterat

unsigned deck_cost = get_deck_cost(cur_deck);
fund = std::max(fund, deck_cost);
print_deck_inline(deck_cost, best_score, cur_deck);
print_deck_inline(deck_cost, best_score, cur_deck,true);
std::mt19937& re = proc.threads_data[0]->re;
unsigned cur_gap = check_requirement(cur_deck, requirement
#ifndef NQUEST
Expand Down Expand Up @@ -483,10 +483,10 @@ DeckResults simulated_annealing(unsigned num_min_iterations, unsigned num_iterat
for (auto evaluation: evaluated_decks)
{ simulations += evaluation.second.second; }
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
print_sim_card_values(best_deck,proc,num_iterations);
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck,true);
print_upgraded_cards(best_deck);
print_sim_card_values(best_deck,proc,num_iterations);
return std::make_pair(best_deck->clone(),best_score);
}

Expand Down Expand Up @@ -634,7 +634,7 @@ DeckResults genetic_algorithm(unsigned num_min_iterations, unsigned num_iteratio

unsigned deck_cost = get_deck_cost(cur_deck);
fund = std::max(fund, deck_cost);
print_deck_inline(deck_cost, best_score, cur_deck);
print_deck_inline(deck_cost, best_score, cur_deck,true);
std::mt19937& re = proc.threads_data[0]->re;
unsigned cur_gap = check_requirement(cur_deck, requirement
#ifndef NQUEST
Expand Down Expand Up @@ -813,10 +813,10 @@ DeckResults genetic_algorithm(unsigned num_min_iterations, unsigned num_iteratio
for (auto evaluation: evaluated_decks)
{ simulations += evaluation.second.second; }
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
print_sim_card_values(best_deck,proc,num_iterations);
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck,true);
print_upgraded_cards(best_deck);
print_sim_card_values(best_deck,proc,num_iterations);
return std::make_pair(best_deck->clone(),best_score);
}

Expand Down Expand Up @@ -961,7 +961,7 @@ DeckResults beam_climb(unsigned num_min_iterations, unsigned num_iterations, std

unsigned deck_cost = get_deck_cost(cur_deck);
fund = std::max(fund, deck_cost);
print_deck_inline(deck_cost, best_score, cur_deck);
print_deck_inline(deck_cost, best_score, cur_deck,true);
std::mt19937& re = proc.threads_data[0]->re;
unsigned cur_gap = check_requirement(cur_deck, requirement
#ifndef NQUEST
Expand Down Expand Up @@ -1167,9 +1167,9 @@ DeckResults beam_climb(unsigned num_min_iterations, unsigned num_iterations, std
for (auto evaluation: evaluated_decks)
{ simulations += evaluation.second.second; }
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
print_sim_card_values(best_deck,proc,num_iterations);
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck,true);
print_upgraded_cards(best_deck);
print_sim_card_values(best_deck,proc,num_iterations);
return std::make_pair(best_deck->clone(),best_score);
}
114 changes: 85 additions & 29 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void init()
use_fused_commander_level=0;
print_upgraded=false;
print_values=false;
vc_x = 0;
simplify_output=false;
show_ci=false;
use_harmonic_mean=false;
Expand All @@ -191,6 +192,7 @@ void init()
#endif
allowed_candidates.clear();
disallowed_candidates.clear();
disallowed_recipes.clear();

//std::chrono::time_point<std::chrono::system_clock> start_time;
maximum_time=0;
Expand Down Expand Up @@ -1112,15 +1114,19 @@ void print_upgraded_cards(Deck* deck)
std::cout << std::endl;
}
//------------------------------------------------------------------------------
void print_cards_inline(std::vector<const Card*> cards,std::ostream& os)
void print_cards_inline(std::vector<const Card*> cards,std::ostream& os, Deck* deck )
{
std::string last_name="";
unsigned num_repeat(0);
bool first = true;

for (const Card* card: cards)
//for (const Card* card: cards)
//{
for (unsigned i =0; i < cards.size();++i)
{
if (card->m_name == last_name)
auto card = cards[i];

if (deck==nullptr && card->m_name == last_name)
{
++ num_repeat;
}
Expand All @@ -1130,7 +1136,10 @@ void print_cards_inline(std::vector<const Card*> cards,std::ostream& os)
{
os << " #" << num_repeat;
}
os << (first?"":", ") << card->m_name;
if(deck!=nullptr)
os << (first?"":", ") << (deck->card_marks[i]=='!'?"!":"") << card->m_name;
else
os << (first?"":", ") << card->m_name;
first = false;
last_name = card->m_name;
num_repeat = 1;
Expand Down Expand Up @@ -1202,8 +1211,13 @@ void print_score_inline(const FinalResults<long double> score) {
// Calculates and prints individual card value in this deck
void print_sim_card_values(Deck* original_deck, Process& p, unsigned iter) // run_deck == p.your_decks[0]
{
if(!print_values)return;
if(!print_values && vc_x == 0)return;
if(p.your_decks.size() != 1)return; // only for single deck
//auto deck = original_deck;
if (original_deck->strategy == DeckStrategy::random || original_deck->strategy == DeckStrategy::flexible || original_deck->strategy == DeckStrategy::evaluate|| original_deck->strategy == DeckStrategy::evaluate_twice)
{
std::sort(original_deck->cards.begin(), original_deck->cards.end(), [](const Card* a, const Card* b) { return a->m_id < b->m_id; });
}
std::string last_name;
long double score;
Deck* sim_deck = p.your_decks[0];
Expand All @@ -1217,15 +1231,16 @@ void print_sim_card_values(Deck* original_deck, Process& p, unsigned iter) // ru
results = p.evaluate(iter, results);
const FinalResults<long double> fr_base= compute_score(results,p.factors);
long double base = fr_base.points;
std::cout << "Value of Cards: ";
std::multimap<long double,std::string> msn;
std::multimap<std::string,long double> mns;
for (unsigned i =0; i < cards.size();++i)
{
auto card = cards[i];
if (card->m_name == last_name)
{
}
else
{
//if (card->m_name == last_name)
//{
//}
//else
//{
last_name = card->m_name;
//sim it
sim_deck->cards = your_deck->cards; //reset cards
Expand All @@ -1234,13 +1249,44 @@ void print_sim_card_values(Deck* original_deck, Process& p, unsigned iter) // ru
results = p.evaluate(iter, results);
const FinalResults<long double> fr= compute_score(results,p.factors);
score = base - fr.points; //subtract from result to get value
std::cout << card->m_name << " (" << score << "), ";
//std::cout << card->m_name << " (" << score << "), ";
msn.insert(std::make_pair(score, card->m_name));
mns.insert(std::make_pair(card->m_name,score));
//}
}
sim_deck->cards = your_deck->cards; //reset cards
if(vc_x > 0)
{
//std::cout << "Locked Deck: ";
////std::cout << original_deck->cards.size() << " units: ";
////print_score_inline(fr_base);
////std::cout << ": ";
//std::cout << original_deck->commander->m_name;
// print dominions
//if (original_deck->alpha_dominion)
//{ std::cout << ", " << original_deck->alpha_dominion->m_name; }

for (unsigned i =0; i < cards.size();++i)
{
original_deck->card_marks.erase(i);
if(vc_x >= std::distance(msn.find(mns.find(cards[i]->m_name)->second), msn.end())) // or mns.start()
{
original_deck->card_marks[i] = '!';
}
}
}
std::cout << std::endl;
if(print_values)
{
std::cout << "Value of Cards: ";
for (unsigned i =0; i < cards.size();++i)
{
std::cout << cards[i]->m_name << " (" << mns.find(cards[i]->m_name)->second << "), ";
}
std::cout << std::endl;
}
}
//------------------------------------------------------------------------------
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck)
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck, bool print_locked)
{
// print units count
std::cout << deck->cards.size() << " units: ";
Expand Down Expand Up @@ -1312,16 +1358,19 @@ std::cout << " [" << opp_win_points << " per opp win]";
std::cout << ": " << deck->commander->m_name;

// print dominions
if (deck->alpha_dominion)
{ std::cout << ", " << deck->alpha_dominion->m_name; }

// print deck cards
if (deck->strategy == DeckStrategy::random || deck->strategy == DeckStrategy::flexible || deck->strategy == DeckStrategy::evaluate|| deck->strategy == DeckStrategy::evaluate_twice)
{
std::sort(deck->cards.begin(), deck->cards.end(), [](const Card* a, const Card* b) { return a->m_id < b->m_id; });
}
std::cout << ", ";
print_cards_inline(deck->cards);
if (deck->alpha_dominion)
{ std::cout << ", " << deck->alpha_dominion->m_name; }

// print deck cards
if (deck->strategy == DeckStrategy::random || deck->strategy == DeckStrategy::flexible || deck->strategy == DeckStrategy::evaluate|| deck->strategy == DeckStrategy::evaluate_twice)
{
std::sort(deck->cards.begin(), deck->cards.end(), [](const Card* a, const Card* b) { return a->m_id < b->m_id; });
}
std::cout << ", ";
if(print_locked)
print_cards_inline(deck->cards,std::cout, deck);
else
print_cards_inline(deck->cards,std::cout);
}
//------------------------------------------------------------------------------
bool is_timeout_reached()
Expand Down Expand Up @@ -1751,11 +1800,11 @@ DeckResults run(int argc, const char** argv)
std::vector<std::string> opt_effects[3]; // 0-you; 1-enemy; 2-global
std::array<signed short, PassiveBGE::num_passive_bges> opt_bg_effects[2];
std::vector<SkillSpec> opt_bg_skills[2];
std::unordered_set<unsigned> disallowed_recipes;

std::string your_deck_list{argv[1]};
std::string enemy_deck_list{argv[2]};


for (int argIndex = 3; argIndex < argc; ++argIndex)
{
if (strcmp(argv[argIndex], "deck") == 0)
Expand Down Expand Up @@ -2133,6 +2182,13 @@ DeckResults run(int argc, const char** argv)
{
print_values = true;
}
else if (strcmp(argv[argIndex], "+vc-x") == 0)
{
if(check_input_amount(argc,argv,argIndex,1))exit(1);
vc_x = atoi(argv[argIndex+1]);
//print_values = true;
argIndex += 1;
}
else if (strcmp(argv[argIndex], "+ci") == 0)
{
show_ci = true;
Expand Down Expand Up @@ -3074,7 +3130,7 @@ DeckResults run(int argc, const char** argv)
results = p.evaluate(std::get<0>(op), results);
print_results(results, p.factors);
fr = std::make_pair(your_deck->clone(),compute_score(results,p.factors));
print_sim_card_values(your_deck,p,std::get<0>(op));
print_sim_card_values(fr.first,p,std::get<0>(op));
break;
}
case climb_forts: {
Expand Down Expand Up @@ -3280,9 +3336,9 @@ DeckResults start(int argc, const char** argv) {

//result to string
std::stringstream oss;
if(drc.first->commander)oss << drc.first->commander->m_name << "," ;
if(drc.first->alpha_dominion) oss<< drc.first->alpha_dominion->m_name << ",";
print_cards_inline(drc.first->cards,oss);
if(drc.first->commander)oss << drc.first->commander->m_name << ", " ;
if(drc.first->alpha_dominion) oss<< drc.first->alpha_dominion->m_name << ", ";
print_cards_inline(drc.first->cards,oss,drc.first);
std::string decks(oss.str());
std::replace(decks.begin(),decks.end(),'\n',' ');
result_decks.push_back(decks);
Expand Down
6 changes: 4 additions & 2 deletions tyrant_optimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace tuo {
EXTERN unsigned use_fused_commander_level;
EXTERN bool print_upgraded;
EXTERN bool print_values;
EXTERN int vc_x;
EXTERN bool simplify_output;
EXTERN bool show_ci;
EXTERN bool use_harmonic_mean;
Expand All @@ -72,6 +73,7 @@ namespace tuo {
#endif
EXTERN std::unordered_set<unsigned> allowed_candidates;
EXTERN std::unordered_set<unsigned> disallowed_candidates;
EXTERN std::unordered_set<unsigned> disallowed_recipes;
EXTERN std::chrono::time_point<std::chrono::system_clock> start_time;
EXTERN long double maximum_time;
//anneal
Expand Down Expand Up @@ -145,10 +147,10 @@ std::vector<Results<uint64_t>> merge(std::vector<Results<uint64_t>> out, std::ve
// some print functions
void print_score_info(const EvaluatedResults& results, std::vector<long double>& factors);
void print_results(const EvaluatedResults& results, std::vector<long double>& factors);
void print_cards_inline(std::vector<const Card*> cards,std::ostream& =std::cout);
void print_cards_inline(std::vector<const Card*> cards,std::ostream& =std::cout, Deck* =nullptr);
void print_score_inline(const FinalResults<long double> score);
void print_sim_card_values(Deck* original_deck, Process& p, unsigned iter); // run_deck == p.your_decks[0]
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck);
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck,bool print_locked=false);
void print_upgraded_cards(Deck* deck);

struct SimulationData
Expand Down

0 comments on commit 8798d78

Please sign in to comment.