Skip to content

Commit

Permalink
Fix Freeze Climb bug
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Apr 9, 2019
1 parent 1ee15ae commit 0139924
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ commit:
-git commit
push: commit
git push
release: ahk push

release-noahk: push
git tag $(shell git describe --tags --abbrev=0 | perl -lpe 'BEGIN { sub inc { my ($$num) = @_; ++$$num } } s/(v\d+\.\d+\.)(\d+)/$$1 . (inc($$2))/eg')
git push --tags

release: ahk release-noahk

pull: commit
git pull
30 changes: 16 additions & 14 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace {
unsigned min_deck_len{1};
unsigned max_deck_len{10};
unsigned opt_freezed_cards{0};
unsigned freezed_cards{0};
unsigned fund{0};
long double target_score{100};
long double min_increment_of_score{0};
Expand Down Expand Up @@ -146,6 +147,7 @@ void init()
min_deck_len=1;
max_deck_len=10;
opt_freezed_cards=0;
freezed_cards=0;
fund=0;
target_score=100;
min_increment_of_score=0;
Expand Down Expand Up @@ -287,10 +289,6 @@ Java_de_neuwirthinformatik_Alexander_mTUO_TUOIntentService_stringFromJNI( JNIEnv
}
#endif
using namespace std::placeholders;
//------------------------------------------------------------------------------
unsigned freezed_cards(const Deck* your_deck) {
return std::min<unsigned>(opt_freezed_cards, your_deck->cards.size());
}
void copy_deck(Deck* src,Deck* dst)
{
dst->commander = src->commander;
Expand Down Expand Up @@ -1939,6 +1937,8 @@ FinalResults<long double> hill_climbing(unsigned num_min_iterations, unsigned nu
// use the best deck from all passed decks
copy_deck(filter_best_deck(your_decks, d1, best_score, evaluated_decks, zero_results, skipped_simulations, proc),d1);

// update freezed_cards
freezed_cards = std::min<unsigned>(opt_freezed_cards, d1->cards.size());
const Card* best_commander = d1->commander;
const Card* best_alpha_dominion = d1->alpha_dominion;
std::vector<const Card*> best_cards = d1->cards;
Expand Down Expand Up @@ -1995,8 +1995,8 @@ FinalResults<long double> hill_climbing(unsigned num_min_iterations, unsigned nu


// << main climbing loop >>
for (unsigned from_slot(freezed_cards(d1)), dead_slot(freezed_cards(d1)); ;
from_slot = std::max(freezed_cards(d1), (from_slot + 1) % std::min<unsigned>(max_deck_len, best_cards.size() + 1)))
for (unsigned from_slot(freezed_cards), dead_slot(freezed_cards); ;
from_slot = std::max(freezed_cards, (from_slot + 1) % std::min<unsigned>(max_deck_len, best_cards.size() + 1)))
{
if(is_timeout_reached()){ break;}
if (deck_has_been_improved)
Expand Down Expand Up @@ -2071,7 +2071,7 @@ FinalResults<long double> hill_climbing(unsigned num_min_iterations, unsigned nu
for (auto it = card_candidates.begin(); it != card_candidates.end();++it)
{
const Card* card_candidate = *it;
for (unsigned to_slot(is_random ? from_slot : card_candidate ? freezed_cards(d1) : (best_cards.size() - 1));
for (unsigned to_slot(is_random ? from_slot : card_candidate ? freezed_cards : (best_cards.size() - 1));
to_slot < (is_random ? (from_slot + 1) : (best_cards.size() + (from_slot < best_cards.size() ? 0 : 1)));
++ to_slot)
{
Expand Down Expand Up @@ -2139,6 +2139,8 @@ FinalResults<long double> simulated_annealing(unsigned num_min_iterations, unsig
// use the best deck from all passed decks
copy_deck(filter_best_deck(your_decks, cur_deck, best_score, evaluated_decks, zero_results, skipped_simulations, proc),cur_deck);

// update freezed_cards
freezed_cards = std::min<unsigned>(opt_freezed_cards, cur_deck->cards.size());

unsigned deck_cost = get_deck_cost(cur_deck);
fund = std::max(fund, deck_cost);
Expand Down Expand Up @@ -2192,8 +2194,8 @@ FinalResults<long double> simulated_annealing(unsigned num_min_iterations, unsig

deck_cost = 0;

unsigned from_slot(freezed_cards(cur_deck));
unsigned from_slot_tmp(freezed_cards(cur_deck));
unsigned from_slot(freezed_cards);
unsigned from_slot_tmp(freezed_cards);
unsigned to_slot(1);

if(debug_print >0)std::cout << "Starting Anneal" << std::endl;
Expand All @@ -2202,14 +2204,14 @@ FinalResults<long double> simulated_annealing(unsigned num_min_iterations, unsig
cur_deck->commander = prev_deck->commander;
cur_deck->alpha_dominion = prev_deck->alpha_dominion;
cur_deck->cards = prev_deck->cards;
from_slot = std::max(freezed_cards(cur_deck), (from_slot+1) % std::min<unsigned>(max_deck_len, cur_deck->cards.size() +1));
from_slot = std::max(freezed_cards, (from_slot+1) % std::min<unsigned>(max_deck_len, cur_deck->cards.size() +1));
const Card* candidate = all_candidates.at(std::uniform_int_distribution<unsigned>(0,all_candidates.size()-1)(re));


if((!candidate || (candidate->m_category == CardCategory::normal && candidate->m_type != CardType::commander && candidate->m_category != CardCategory::dominion_alpha)))
{

to_slot = std::uniform_int_distribution<unsigned>(is_random ? from_slot : candidate ? freezed_cards(cur_deck) : (cur_deck->cards.size() -1),(is_random ? (from_slot+1) : (cur_deck->cards.size() + ( from_slot < cur_deck->cards.size() ? 0 : 1)))-1)(re);
to_slot = std::uniform_int_distribution<unsigned>(is_random ? from_slot : candidate ? freezed_cards : (cur_deck->cards.size() -1),(is_random ? (from_slot+1) : (cur_deck->cards.size() + ( from_slot < cur_deck->cards.size() ? 0 : 1)))-1)(re);
if(candidate ?
(from_slot < cur_deck->cards.size() && (from_slot == to_slot && candidate == cur_deck->cards[to_slot]))
:
Expand Down Expand Up @@ -2335,8 +2337,8 @@ void mutate(Deck* src, Deck* cur_deck, std::vector<const Card*> all_candidates,

unsigned deck_cost = 0;

unsigned from_slot(freezed_cards(cur_deck));
unsigned from_slot_tmp(freezed_cards(cur_deck));
unsigned from_slot(freezed_cards);
unsigned from_slot_tmp(freezed_cards);
unsigned to_slot(1);

bool finished = false;
Expand All @@ -2354,7 +2356,7 @@ void mutate(Deck* src, Deck* cur_deck, std::vector<const Card*> all_candidates,
if((!candidate || (candidate->m_category == CardCategory::normal && candidate->m_type != CardType::commander && candidate->m_category != CardCategory::dominion_alpha)))
{

to_slot = std::uniform_int_distribution<unsigned>(is_random ? from_slot : candidate ? freezed_cards(cur_deck) : (cur_deck->cards.size() -1),(is_random ? (from_slot+1) : (cur_deck->cards.size() + ( from_slot < cur_deck->cards.size() ? 0 : 1)))-1)(re);
to_slot = std::uniform_int_distribution<unsigned>(is_random ? from_slot : candidate ? freezed_cards : (cur_deck->cards.size() -1),(is_random ? (from_slot+1) : (cur_deck->cards.size() + ( from_slot < cur_deck->cards.size() ? 0 : 1)))-1)(re);
if(candidate ?
(from_slot < cur_deck->cards.size() && (from_slot == to_slot && candidate == cur_deck->cards[to_slot]))
:
Expand Down

0 comments on commit 0139924

Please sign in to comment.