Skip to content

Commit

Permalink
Made amped querier for crit
Browse files Browse the repository at this point in the history
  • Loading branch information
12345ieee committed Feb 15, 2020
1 parent cd63998 commit d065706
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 17 deletions.
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LIBFLAGS:=-lm
# Query
QUERY_LEECH=leechgem/leechquery
QUERY_MANAGEM=managem/mgquery-alone managem/mgquery-amps managem/mgquery-setup managem/mgquery-omnia
QUERY_CRIT=critgem/critquery
QUERY_CRIT=critgem/critquery critgem/critquery-amps
QUERY_KILLGEM=killgem/kgquery-alone killgem/kgquery-amps killgem/kgquery-setup killgem/kgquery-omnia
QUERY_MGNGEM=managem/mgquery-ngems
QUERY_KGNGEM=killgem/kgquery-ngems
Expand Down Expand Up @@ -107,13 +107,10 @@ $(WINDIR):

# Move
move: | $(BINDIR)
@find "managem/" -type f -executable -exec mv -v {} "$(BINDIR)/" \;

@find "killgem/" -type f -executable -exec mv -v {} "$(BINDIR)/" \;

@if [ -e $(PARSER) ]; then \
mv -v $(PARSER) "$(BINDIR)/"; \
fi
@for exe in $(DEV_ALL); do \
[ -e "$${exe}" ] && mv -v $${exe} "$(BINDIR)/"; \
done; \
: # noop so make doesn't choke

move-white: | $(BINDIR)
@if [ -d "white" ]; then \
Expand Down
55 changes: 55 additions & 0 deletions critgem/crita_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef _KGA_UTILS_H
#define _KGA_UTILS_H

#include <cstdio>

#include "crit_utils.h"
#include "interval_tree.h"
#include "sort_utils.h"
#include "build_utils_2D.h"

inline double gem_amp_power(const gem_Y& gem1, const gem_Y& amp1, double damage_ratio, double crit_ratio)
{
return (gem1.damage+damage_ratio*amp1.damage)*(gem1.crit+crit_ratio*amp1.crit);
}

void print_omnia_table(const gem_Y* amps, const double* powers, int len)
{
printf("Critgem\tAmps\tPower\n");
for (int i=0; i<len; i++)
printf("%d\t%d\t%#.7g\n", i+1, gem_getvalue(amps+i), powers[i]);
printf("\n");
}

template<class gem>
inline void specs_compression(gem** poolf, int* poolf_length, const gem*const* pool, const int* pool_length, int len, bool debug)
{
for (int i = 0; i < len; ++i) {
gem* temp_pool = (gem*)malloc(pool_length[i] * sizeof(gem));
std::copy_n(pool[i], pool_length[i], temp_pool);

compression_2D<0>(poolf + i, poolf_length + i, temp_pool, pool_length[i]);
free(temp_pool);

if (debug)
printf("Critgem value %d speccing compressed pool size:\t%d\n", i + 1, poolf_length[i]);
}
}

template<class gem>
inline void amps_compression(gem** poolAf, int* poolAf_length, const gem*const* poolA, const int* poolA_length, int lena, bool debug)
{
for (int i = 0; i < lena; ++i) {
gem* temp_pool = (gem*)malloc(poolA_length[i] * sizeof(gem));
std::copy_n(poolA[i], poolA_length[i], temp_pool);

compression_2D<0>(poolAf + i, poolAf_length + i, temp_pool, poolA_length[i]);
free(temp_pool);

if (debug)
printf("Amp value %d compressed pool size:\t%d\n", i+1, poolAf_length[i]);
}
}


#endif // _KGA_UTILS_H
237 changes: 237 additions & 0 deletions critgem/critquery-amps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <getopt.h>
#include <cstring>

#include "interval_tree.h"
#include "crit_utils.h"
#include "gfon.h"
#include "effective_skills.h"
#include "print_utils.h"
#include "cmdline_options.h"
#include "crita_utils.h"

using gem = gem_Y;
using gemA = gem_Y;

void print_amps_table(const gem* gems, const gemA* amps, const double* spec_coeffs, double damage_ratio, double crit_ratio, int len)
{
printf("Gem\tAmps\tPower\t\tSpec coeff\n");
for (int i=0; i<len; i++)
printf("%d\t%d\t%#.7g\t%f\n", i+1, gem_getvalue(amps+i), gem_amp_power(gems[i], amps[i], damage_ratio, crit_ratio), spec_coeffs[i]);
printf("\n");
}

void worker(const cmdline_options& options)
{
FILE* table = file_check(options.tables[0]); // file is open to read
if (table==NULL) exit(1); // if the file is not good we exit

int len = options.target.len;
int lena = 2 * len; // temporary till I find a better way
int max_len = std::max(len, lena);
gem* pool[max_len];
int pool_length[max_len];
pool[0] = (gem*)malloc(sizeof(gem));
pool_length[0]=1;
gem_init(pool[0], 1, 1, 1); // grade damage crit

int prevmax=pool_from_table(pool, pool_length, max_len, table);
fclose(table);
if (prevmax<len-1) {
for (int i = 0; i <= prevmax; ++i) free(pool[i]); // free
if (prevmax>0) printf("Gem table stops at %d, not %d\n",prevmax+1,len);
exit(1);
}

lena = std::min(lena, prevmax + 1);

gem* poolf[lena];
int poolf_length[lena];

specs_compression(poolf, poolf_length, pool, pool_length, lena, options.output.debug);
if (!options.output.quiet) printf("Gem speccing pool compression done!\n");

// amps and gems come from the same table, so we do not get them again
gemA** poolAf = poolf;
int* poolAf_length = poolf_length;

// let's choose the right gem-amp combo
gem gems[len];
gemA amps[len];
double spec_coeffs[len];
gem_init(gems, 1, 1, 1);
amps[0] = {};
spec_coeffs[0]=0;
double crit_ratio = special_ratio_gcfw(options);
double damage_ratio = damage_ratio_gcfw(options);
double growth_comb = options.tuning.combine_growth;

bool skip_computations = options.output.quiet && !(options.print.table || options.target.upto);
int first = skip_computations ? len-1 : 0;
for (int i =first; i<len; ++i) { // for every gem value
gems[i] = {}; // we init the gems
amps[i] = {}; // to extremely weak ones
for (int k=0;k<poolf_length[i];++k) { // first we compare the gem alone
if (gem_power(poolf[i][k]) > gem_power(gems[i])) {
gems[i]=poolf[i][k];
}
}
int j;
int NS=i+1;
double comb_coeff=pow(NS, -growth_comb);
spec_coeffs[i]=comb_coeff*gem_power(gems[i]);
int amps_bound = std::min(2 * (i + 1), lena); // now with amps
for (j=0, NS+=options.amps.number_per_gem; j<amps_bound; ++j, NS+=options.amps.number_per_gem) { // for every amp value from 1 to to bound
double comb_coeff=pow(NS, -growth_comb); // we compute comb_coeff
for (int h=0;h<poolAf_length[j];++h) { // then we search in the amp pool
double Pda = damage_ratio * poolAf[j][h].damage;
double Pca = crit_ratio * poolAf[j][h].crit ;
for (int k=0;k<poolf_length[i];++k) { // and in the gem pool and compare
double Pdamage = poolf[i][k].damage + Pda;
double Pcrit = poolf[i][k].crit + Pca;
double power = Pdamage * Pcrit;
double spec_coeff=power*comb_coeff;
if (spec_coeff>spec_coeffs[i]) {
spec_coeffs[i]=spec_coeff;
gems[i]=poolf[i][k];
amps[i]=poolAf[j][h];
}
}
}
}
if (!options.output.quiet) {
printf("Total value:\t%d\n\n", i+1+options.amps.number_per_gem*gem_getvalue(amps+i));
printf("Gem\n");
printf("Value:\t%d\n",i+1);
if (options.output.debug) printf("Pool:\t%d\n",poolf_length[i]);
gem_print(gems+i);
printf("Amplifier (x%d@%.1f)\n", options.amps.number_per_gem, options.amps.average_gems_seen);
printf("Value:\t%d\n",gem_getvalue(amps+i));
if (options.output.debug) printf("Pool:\t%d\n",poolAf_length[gem_getvalue(amps+i)-1]);
gem_print(amps+i);
printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[i], amps[i], damage_ratio, crit_ratio));
printf("Spec coefficient:\t%f\n\n", spec_coeffs[i]);
}
}

if (options.output.quiet) { // outputs last if we never seen any
printf("Total value:\t%d\n\n", len+options.amps.number_per_gem*gem_getvalue(amps+len-1));
printf("Gem\n");
printf("Value:\t%d\n", len);
gem_print(gems+len-1);
printf("Amplifier (x%d@%.1f)\n", options.amps.number_per_gem, options.amps.average_gems_seen);
printf("Value:\t%d\n", gem_getvalue(amps+len-1));
gem_print(amps+len-1);
printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[len-1], amps[len-1], damage_ratio, crit_ratio));
printf("Spec coefficient:\t%f\n\n", spec_coeffs[len-1]);
}

gem* gemf=gems+len-1; // gem that will be displayed
gemA* ampf=amps+len-1; // amp that will be displayed

if (options.target.upto) {
double best_sc=0;
int best_index=0;
for (int i =0; i<len; ++i) {
if (spec_coeffs[i] > best_sc) {
best_index=i;
best_sc=spec_coeffs[i];
}
}
printf("Best setup up to %d:\n\n", len);
printf("Total value:\t%d\n\n", gem_getvalue(gems+best_index)+options.amps.number_per_gem*gem_getvalue(amps+best_index));
printf("Gem\n");
printf("Value:\t%d\n", gem_getvalue(gems+best_index));
gem_print(gems+best_index);
printf("Amplifier (x%d@%.1f)\n", options.amps.number_per_gem, options.amps.average_gems_seen);
printf("Value:\t%d\n", gem_getvalue(amps+best_index));
gem_print(amps+best_index);
printf("Spec base power: \t%#.7g\n", gem_amp_power(gems[best_index], amps[best_index], damage_ratio, crit_ratio));
printf("Spec coefficient:\t%f\n\n", best_sc);
gemf = gems+best_index;
ampf = amps+best_index;
}

gem* gem_array = NULL;
if (options.target.chain) {
if (len < 3) printf("I could not add chain!\n\n");
else {
int value = gem_getvalue(gemf);
int valueA= gem_getvalue(ampf);
double NS = value + options.amps.number_per_gem*valueA;
double amp_damage_scaled = damage_ratio * ampf->damage;
double amp_crit_scaled = crit_ratio * ampf->crit;
gemf = gem_putchain(poolf[value-1], poolf_length[value-1], &gem_array, amp_damage_scaled, amp_crit_scaled);
printf("Setup with chain added:\n\n");
printf("Total value:\t%d\n\n", value+options.amps.number_per_gem*gem_getvalue(ampf));
printf("Gem\n");
printf("Value:\t%d\n", value);
gem_print(gemf);
printf("Amplifier (x%d@%.1f)\n", options.amps.number_per_gem, options.amps.average_gems_seen);
printf("Value:\t%d\n", valueA);
gem_print(ampf);
printf("Spec base power w. chain:\t%#.7g\n", gem_amp_power(*gemf, *ampf, damage_ratio, crit_ratio));
double CgP = pow(NS, -growth_comb);
printf("Spec coefficient:\t%f\n\n", CgP*gem_cfr_power(*gemf, amp_damage_scaled, amp_crit_scaled));
}
}

if (options.print.parens) {
printf("Gem speccing scheme:\n");
print_parens_compressed(gemf);
printf("\n\n");
printf("Amplifier speccing scheme:\n");
print_parens_compressed(ampf);
printf("\n\n");
}
if (options.print.tree) {
printf("Gem tree:\n");
print_tree(gemf, "");
printf("\n");
printf("Amplifier tree:\n");
print_tree(ampf, "");
printf("\n");
}
if (options.print.table) print_amps_table(gems, amps, spec_coeffs, damage_ratio, crit_ratio, len);


if (options.print.equations) { // it ruins gems, must be last
printf("Gem equations:\n");
print_equations(gemf);
printf("\n");
printf("Amplifier equations:\n");
print_equations(ampf);
printf("\n");
}

for (int i =0;i<len;++i) free(pool[i]); // free gems
for (int i =0;i<len;++i) free(poolf[i]); // free gems compressed
if (options.target.chain && len > 2) {
free(gem_array);
}
}

int main(int argc, char** argv)
{
cmdline_options options = cmdline_options();
options.has_printing();
options.has_extra_search();
options.has_amps();
options.has_combine_growth();
options.set_num_tables(1);

options.skills.amps = 200;
options.amps.number_per_gem = 2; // multiple gems in trap
options.amps.average_gems_seen = 2.5; // with amps on the side
options.tuning.combine_growth = 1.145648; // 13c

if(!options.parse_args(argc, argv))
return 1;
options.table_selection(0, "table_crit");

worker(options);
return 0;
}

5 changes: 3 additions & 2 deletions include/build_utils_2D.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#ifndef _BUILD_UTILS_2D_H
#define _BUILD_UTILS_2D_H

#include <sort_utils.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <numeric>

#include "sort_utils.h"

template<int ACC, class gem>
inline void compression_2D(gem** pool_out_p, int* pool_length_out_p, gem* temp_pool, int pool_length_in)
{
gem_sort(temp_pool, pool_length_in, AS_LAMBDA(gem_12_less<ACC>));

int broken = 0;
decltype(get_second(gem {})) lim_second = -1; /* also remove gems with second = 0 */
decltype(get_second(gem {})) lim_second = -1; /* do not remove gems with second = 0 */
/* Look at gems from high X to low, keep track of the
* best Y seen till now, discard gems that don't beat that Y
*/
Expand Down
2 changes: 1 addition & 1 deletion include/build_utils_3D.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef _BUILD_UTILS_3D_H
#define _BUILD_UTILS_3D_H

#include <sort_utils.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <numeric>

#include "sort_utils.h"
#include "interval_tree.h"

template<int ACC, int ACC_TR, class gem>
Expand Down
14 changes: 13 additions & 1 deletion include/crit_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,26 @@ inline void gem_init(gem_Y *p_gem, int grd, float damage, float crit)
// Chain adder section
// -------------------

inline double gem_cfr_power(const gem_Y& gem1, double amp_damage_scaled, double amp_crit_scaled)
{
return (gem1.damage + amp_damage_scaled) * (gem1.crit + amp_crit_scaled);
}

#include "chain_adder.h"

gem_Y* gem_putchain(const gem_Y* pool, int pool_length, gem_Y** gem_array)
{
return gem_putchain_templ(pool, pool_length, gem_array,
[](gem_Y* arg) {gem_init(arg, 1, 0, 0);},
[](gem_Y* arg) {gem_init(arg, 1, DAMAGE_CHHIT, 0);},
[](gem_Y arg) {return gem_power(arg);});
}

gem_Y* gem_putchain(const gem_Y* pool, int pool_length, gem_Y** gem_array, double amp_damage_scaled, double amp_crit_scaled)
{
return gem_putchain_templ(pool, pool_length, gem_array,
[](gem_Y* arg) {gem_init(arg, 1, DAMAGE_CHHIT, 0);},
[=](gem_Y arg) {return gem_cfr_power(arg, amp_damage_scaled, amp_crit_scaled);});
}


#endif // _CRIT_UTILS_H
Loading

0 comments on commit d065706

Please sign in to comment.