Advertisement
Guest User

Untitled

a guest
May 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <limits.h>
  5.  
  6. /*
  7.  
  8. quick facts:
  9.  
  10. compatibility: 0-255.  saved over the life of your yojimbo
  11.   starts at 128(P) 50(U)
  12.   change:
  13.   Y uses Z (Zanmato)                     +4
  14.   Y uses WA / !W (Wakizashi vs all)      +3
  15.   Y uses WO /  W (Wakizashi vs one)      +1
  16.   Y uses K (Kozuka)                      +0
  17.   Y uses D (Diagoro)                     -1
  18.   Y is dismissed on first turn           -3
  19.   Y is KOed                             -10
  20.   Y gets paid 0g                        -20
  21.  
  22.   dismiss on any other turn is ok, no change
  23.   so always dismiss rather than let him die
  24.   never pay 0g under any circumstance
  25.  
  26. gil: 0-999M
  27.   money you pay him.  program only allows 1+ because 0 is autodismiss
  28.   only pay in powers of 2; extra gold before next power of 2 is useless
  29.  
  30. giltotal: 0-999M
  31.   total money you had before pay.  with option 1, you get increase
  32.   relative to option 2 for >=50% of g paid, and decrease for <=50%.
  33.  
  34. option: 1-3
  35.   what you said when you hired yojimbo for the first time
  36.   1 "To train as a summoner."
  37.   2 "To gain the power to destroy fiends."
  38.   3 "To defeat the most powerful enemies."
  39.  
  40.   Compared to 2, 1 is better when you spend over half your gold on
  41.   a single payment, and worse otherwise.  Never choose 1.
  42.   Compared to 2, 3 is slightly worse for generating one hit kos against lvl 1 mobs
  43.   and much better for one hit kos against lv 2-6 mobs.  2 is always slightly better
  44.   at generating good non-OHKO attacks (ie WA/WO) against any mob
  45.  
  46.   If playing NA, and only interested in non-boss mobs or no OHKOS, option 2 is best,
  47.   otherwise option 3.  Considering the massive difficulty of generating OHKOS, and
  48.   the "cheapness" of them, maybe the small regular bonus on option 2 is best.
  49.  
  50.   If playing EU, always choose option 3; you won't need the slighty bonus on non
  51.   bosses.
  52.  
  53. zlvl: 1-6
  54.   Target's zanmoto level
  55.   1: almost all regular mobs
  56.   2: a handful (<12) of special mobs
  57.   3: anima and adamantoise
  58.   4: almost all normal bosses
  59.   5: all monster arena creations, and all final boss fight
  60.   6: dark aeons (&penance???) (EU only extras)
  61.  
  62. od: 0-1
  63.   if Y's overdrive bar is active, he gets a bonus to motivation.  Using him seriously
  64.   in NA you will need to keep overdrive full all the time.  Perhaps the same in EU,
  65.   but it's so easy there that you may be able to do without.
  66.  
  67. pal: 0-1
  68.   if 1, EU version.  if 0, NA version.  NA version is buttfuckingly difficult; against
  69.   regular mobs with max OD, compat, best option (2) you must pay 4096 gold to eliminate
  70.   the possibility of dog attack.  EU version is retardedly easy; against any boss, with
  71.   option 3, od filled, but out of the box compat, paying 1 gold gives zero dog attacks
  72.   and 1/4 of paid attacks Z-killer.  Good bye penance?
  73.  
  74. Attack stats:
  75.   Diagoro:   Pow 10 Pierce Can Crit
  76.   Kozuka:    Pow 13 Pierce Can Crit
  77.   Wakizashi: Pow 18 Pierce Can Crit
  78.   Wakizashi+:Pow 18 Pierce Can Crit All
  79.   Zanmato:   OHKO (no overkill)     All
  80. */
  81.  
  82. typedef struct
  83. {
  84.   int compat; // compatibility: 0-255
  85.   int gil; // gil paid: 1-999M
  86.   int giltotal; // total gil before payment: 1-999M
  87.   int option; // cave selection: 1-3
  88.   int zlvl; // target's Zlvl: 1-6
  89.   int od; // overdrive: 0-1
  90.   int pal; // international: 0-1
  91. } input_t;
  92.  
  93. typedef struct
  94. {
  95.   int freeattack; // chance of free attack: parts in 4096
  96.  
  97.   // assuming free attack occurs:
  98.   int freeZ; // chance of free Z: parts in 4096
  99.   int freeWA;
  100.   int freeWO;
  101.   int freeK;
  102.   int freeD;
  103.  
  104.   // assuming free attack doesn't occur
  105.   int Z; // still parts in 4096
  106.   int WA;
  107.   int WO;
  108.   int K;
  109.   int D;
  110.  
  111. } output_t;
  112.  
  113.  
  114. // checks for invalid numbers in input
  115. #define RANGEJA(a,b,c)\
  116. if ((a) < (b))        \
  117.   (a) = (b);          \
  118. if ((a) > (c))        \
  119.   (a) = (c)
  120. void sanatize_input (input_t *in)
  121. {
  122.   RANGEJA (in->compat, 0, 255);
  123.   RANGEJA (in->gil, 1, 999999999);
  124.   RANGEJA (in->giltotal, in->gil, 999999999);
  125.   RANGEJA (in->option, 1, 3);
  126.   RANGEJA (in->zlvl, 1, 6);
  127.   RANGEJA (in->od, 0, 1);
  128.   RANGEJA (in->pal, 0, 1);
  129. }
  130. #undef RANGEJA
  131.  
  132. #ifndef MAX
  133. #define MAX(a,b) ((a)>(b)?(a):(b))
  134. #endif
  135. #ifndef MIN
  136. #define MIN(a,b) ((a)<(b)?(a):(b))
  137. #endif
  138.  
  139. // return number of intersections of [a,b] with [c,d]
  140. int intersect (a, b, c, d)
  141. {
  142.   int i = MAX (a, c);
  143.   int j = MIN (b, d);
  144.  
  145.   return MAX (j - i + 1, 0);
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152. // make a calculation
  153. void do_yojimbo (const input_t *in, output_t *out)
  154. {
  155.   int i, j, k, m, m2;
  156.  
  157.   // constants of north america vs pal
  158.   int GIL_MULT = in->pal ? 4 : 2;
  159.   int COMPAT_DIV = in->pal ? 4 : 30;
  160.   int OD_BONUS = in->pal ? 20 : 2;
  161.  
  162.   // do that shit
  163.   if (1)
  164.   {
  165.     // free attack: c/1024, parts of 4096
  166.     out->freeattack = in->compat * 4;
  167.  
  168.     // free attack: [c/4] + 0..63
  169.     i = in->compat / 4;
  170.     j = i + 63;
  171.     out->freeD = intersect (i, j, 0, 31) * 64;
  172.     out->freeK = intersect (i, j, 32, 47) * 64;
  173.     out->freeWO = intersect (i, j, 48, 63) * 64;
  174.     out->freeWA = intersect (i, j, 64, 79) * 64;
  175.  
  176.     //freeZ: only happens with lvl 1 mobs
  177.     k = intersect (i, j, 80, 999) * 64;
  178.     if (in->zlvl == 1)
  179.     {
  180.       out->freeZ = k;
  181.     }
  182.     else
  183.     {
  184.       out->freeZ = 0;
  185.       out->freeWA += k;
  186.     }
  187.  
  188.     // step 1: payment
  189.     k = in->gil;
  190.     m = -2;
  191.     while (k)
  192.     {
  193.       k /= 2;
  194.       m += 1;
  195.     }
  196.     // special case: 1 gil gives m = 0
  197.     if (m < 0)
  198.       m = 0;
  199.     m *= GIL_MULT;
  200.  
  201.     // step 2: motivation
  202.     m += in->compat / COMPAT_DIV;
  203.  
  204.     // step 3: "poor person" option 1
  205.     if (in->option == 1)
  206.       m *= 0.75 + (in->gil * 0.5 / in->giltotal);
  207.  
  208.     // step 4: z lvl
  209.     // also calculate step 2 zlvl
  210.     if (in->option == 3)
  211.     {
  212.       m2 = m * 4 / 5;
  213.       if (in->zlvl <= 3)
  214.         m = m * 4 / 5;
  215.       else
  216.         m = m * 2 / 5;
  217.     }
  218.     else
  219.     {
  220.       m2 = m;
  221.       m /= in->zlvl;
  222.     }
  223.  
  224.     // step 5: overdrive
  225.     if (in->od)
  226.     {
  227.       m += OD_BONUS;
  228.       m2 += OD_BONUS;
  229.     }
  230.  
  231.     // step 6: add random number and choose attack
  232.     // chance of Z:
  233.     k = intersect (m, m + 63, 80, 999);
  234.     out->Z = k * 64;
  235.  
  236.     // other options are only if Z fails
  237.     k = 64 - k;
  238.     i = m2;
  239.     j = m2 + 63;
  240.  
  241.     out->D = intersect (i, j, 0, 31) * k;
  242.     out->K = intersect (i, j, 32, 47) * k;
  243.     out->WO = intersect (i, j, 48, 63) * k;
  244.     out->WA = intersect (i, j, 64, 999) * k;
  245.   }
  246.  
  247. }
  248.  
  249.  
  250. int main (int argc, char **argv)
  251. {
  252.   printf ("use: compat ___gil___ _giltotal option zlvl od pal\n");
  253.   if (argc != 8)
  254.   {
  255.     printf ("oops?\n");
  256.     return 0;
  257.   }
  258.  
  259.   input_t i;
  260.   output_t o;
  261.  
  262.   i.compat = atoi (argv[1]);
  263.   i.gil = atoi (argv[2]);
  264.   i.giltotal = atoi (argv[3]);
  265.   i.option = atoi (argv[4]);
  266.   i.zlvl = atoi (argv[5]);
  267.   i.od = atoi (argv[6]);
  268.   i.pal = atoi (argv[7]);
  269.  
  270.   sanatize_input (&i);
  271.   printf ("     %6i %9i %9i %6i %4i %2i %3i\n", i.compat, i.gil, i.giltotal, i.option,
  272.     i.zlvl, i.od, i.pal);
  273.  
  274.   do_yojimbo (&i, &o);
  275.  
  276.   printf ("Free attack: %5.2f%%\n", o.freeattack / 40.96);
  277.   printf ("  Z: %5.2f%%\n", o.freeZ / 40.96);
  278.   printf (" !W: %5.2f%%\n", o.freeWA / 40.96);
  279.   printf ("  W: %5.2f%%\n", o.freeWO / 40.96);
  280.   printf ("  K: %5.2f%%\n", o.freeK / 40.96);
  281.   printf ("  D: %5.2f%%\n", o.freeD / 40.96);
  282.   printf ("Paid attack: %5.2f%%\n", 100.0 - o.freeattack / 40.96);
  283.   printf ("  Z: %5.2f%%\n", o.Z / 40.96);
  284.   printf (" !W: %5.2f%%\n", o.WA / 40.96);
  285.   printf ("  W: %5.2f%%\n", o.WO / 40.96);
  286.   printf ("  K: %5.2f%%\n", o.K / 40.96);
  287.   printf ("  D: %5.2f%%\n", o.D / 40.96);
  288.  
  289.   printf ("Combined attack chance:\n");
  290.   double d1, d2;
  291.   double f1 = o.freeattack / 4096.0;
  292.   double f2 = 1.0 - f1;
  293.   d2 = 0.0;
  294.  
  295.   d1 = o.freeZ * f1 + o.Z * f2;
  296.   d2 += d1 * 4.0;
  297.   printf ("  Z: %5.2f%%\n", d1 / 40.96);
  298.  
  299.   d1 = o.freeWA * f1 + o.WA * f2;
  300.   d2 += d1 * 3.0;
  301.   printf (" !W: %5.2f%%\n", d1 / 40.96);
  302.  
  303.    d1 = o.freeWO * f1 + o.WO * f2;
  304.   d2 += d1 * 1.0;
  305.   printf ("  W: %5.2f%%\n", d1 / 40.96);
  306.  
  307.   d1 = o.freeK * f1 + o.K * f2;
  308.   d2 += d1 * 0.0;
  309.   printf ("  K: %5.2f%%\n", d1 / 40.96);
  310.  
  311.   d1 = o.freeD * f1 + o.D * f2;
  312.   d2 -= d1 * 1.0;
  313.   printf ("  D: %5.2f%%\n", d1 / 40.96);
  314.  
  315.   printf ("Average compat change: %4.1f", d2 / 4096.0);
  316.  
  317.  
  318.  
  319.   return 0;
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement