Delfigamer

If all else fail...

Sep 8th, 2016
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.45 KB | None | 0 0
  1. -- ...bruteforce the wiener out of it!
  2.  
  3. -- So, I've recorded the total EXP values needed to advance a character to the next level in Disgaea 1.
  4. -- From a coding standpoint, it is more effective to implement a formula for total EXP, and then calculate ENEXT as a difference.
  5. -- Otherwise, you'd have to calculate a few thousand ENEXTs for every mob in a particularly deep dungeon,
  6. -- which is not a smart thing to do when your game runs on a PS2
  7. -- The EXP curve behaves very differently before LV99 and after LV99. Let's start with the first part.
  8. -- Assuming that EXP is given by a polynome, I've taken a few values as control points and obtained this approximation:
  9. --    EXP = 0.0100003 * LV^4 + 0.289923 * LV^3 + 1.05555 * LV^2 + 1.14207 * LV + 0.50246
  10. -- Most likely, the actual formula is an integer expression of a similar nature. I assumed it was something of this form:
  11. --    EXP = floor(((((A * LV + B) * LV + C) * LV + D) * LV + E) / 1000)
  12. -- This program tries different values of A..E in the neighbourhood of the ones above and compares the results with actual EXP from the game.
  13. -- As it stands, the EXP function for 1<=LV<=98 may be perfectly represented by this expression:
  14. --    EXP = floor(((((10 * LV + 290) * LV + 1050) * LV + 1271) * LV + 486) / 1000)
  15. local exp = {
  16.     3,
  17.     9,
  18.     22,
  19.     43,
  20.     75,
  21.     121,
  22.     184,
  23.     267,
  24.     373,
  25.     508,
  26.     673,
  27.     875,
  28.     1117,
  29.     1404,
  30.     1740,
  31.     2132,
  32.     2585,
  33.     3104,
  34.     3696,
  35.     4365,
  36.     5120,
  37.     5967,
  38.     6912,
  39.     7962,
  40.     9126,
  41.     10410,
  42.     11822,
  43.     13371,
  44.     15066,
  45.     16913,
  46.     18923,
  47.     21104,
  48.     23466,
  49.     26019,
  50.     28771,
  51.     31733,
  52.     34915,
  53.     38329,
  54.     41984,
  55.     45891,
  56.     50062,
  57.     54508,
  58.     59241,
  59.     64273,
  60.     69616,
  61.     75282,
  62.     81285,
  63.     87636,
  64.     94350,
  65.     101439,
  66.     108917,
  67.     116798,
  68.     125096,
  69.     133826,
  70.     143001,
  71.     152638,
  72.     162750,
  73.     173353,
  74.     184464,
  75.     196096,
  76.     208267,
  77.     220993,
  78.     234291,
  79.     248176,
  80.     262666,
  81.     277779,
  82.     293531,
  83.     309941,
  84.     327026,
  85.     344804,
  86.     363294,
  87.     382515,
  88.     402486,
  89.     423225,
  90.     444752,
  91.     467086,
  92.     490248,
  93.     514258,
  94.     539136,
  95.     564902,
  96.     591577,
  97.     619183,
  98.     647740,
  99.     677271,
  100.     707797,
  101.     739339,
  102.     771921,
  103.     805565,
  104.     840294,
  105.     876129,
  106.     913096,
  107.     951217,
  108.     990515,
  109.     1031016,
  110.     1072742,
  111.     1115719,
  112.     1159971,
  113.     1205523,
  114.     1303823,
  115.     1340870,
  116.     1377638,
  117.     1414198,
  118.     1450612,
  119.     1486933,
  120.     1523205,
  121.     1559465,
  122.     1595747,
  123.     1632078,
  124.     1668484,
  125.     1704986,
  126.     1741603,
  127.     1778352,
  128.     1815248,
  129.     1852303,
  130.     1889530,
  131.     1926939,
  132.     1964540,
  133.     2002341,
  134.     2040350,
  135.     2078573,
  136.     2117018,
  137.     2155689,
  138.     2194593,
  139.     2233733,
  140.     2273114,
  141.     2312741,
  142.     2352616,
  143.     2392743,
  144.     2433126,
  145.     2473766,
  146.     2514668,
  147.     2555833,
  148.     2597263,
  149.     2638961,
  150.     2680929,
  151.     2723168,
  152.     2765680,
  153.     2808467,
  154.     2851530,
  155.     2894871,
  156.     2938490,
  157.     2982390,
  158.     3026572,
  159.     3071035,
  160.     3115782,
  161.     3160814,
  162.     3206130,
  163.     3251733,
  164.     3297623,
  165.     3343800,
  166.     3390266,
  167.     3437020,
  168.     3484065,
  169.     3531399,
  170.     3579025,
  171.     3626942,
  172.     3675151,
  173.     3723652,
  174.     3772447,
  175.     3821534,
  176.     3870916,
  177.     3920591,
  178.     3970561,
  179.     4020826,
  180.     4071386,
  181.     4122242,
  182.     4173394,
  183.     4224842,
  184.     4276586,
  185.     4328628,
  186.     4380966,
  187.     4433601,
  188.     4486535,
  189.     4539766,
  190.     4593295,
  191.     4647122,
  192.     4701247,
  193.     4755672,
  194.     4810395,
  195.     4865417,
  196.     4920738,
  197.     4976359,
  198.     5032279,
  199.     5088498,
  200.     5145018,
  201.     5201838,
  202.     5258957,
  203.     5316377,
  204.     5374097,
  205.     5432118,
  206.     5490440,
  207.     5549062,
  208.     5607985,
  209.     5667208,
  210.     5726733,
  211.     5786560,
  212.     5846687,
  213.     5907116,
  214.     5967846,
  215.     6028877,
  216.     6090211,
  217.     6151846,
  218.     6213782,
  219.     6276021,
  220.     6338562,
  221.     6401404,
  222.     6464549,
  223.     6527996,
  224.     6591745,
  225.     6655796,
  226.     6720149,
  227.     6784805,
  228.     6849764,
  229.     6915025,
  230.     6980588,
  231.     7046455,
  232.     7112623,
  233.     7179095,
  234.     7245869,
  235.     7312946,
  236.     7380326,
  237.     7448009,
  238.     7515995,
  239.     7584284,
  240.     7652876,
  241.     7721771,
  242.     7790969,
  243.     7860470,
  244.     7930275,
  245.     8000383,
  246.     8070794,
  247.     8141508,
  248.     8212526,
  249.     8283847,
  250.     8355471,
  251.     8427399,
  252.     8499630,
  253.     8572165,
  254.     8645003,
  255.     8718145,
  256.     8791590,
  257.     8865339,
  258.     8939392,
  259.     9013748,
  260.     9088408,
  261.     9163372,
  262.     9238640,
  263.     9314211,
  264.     9390086,
  265.     9466265, -- 250
  266. }
  267.  
  268. local function approximate(lv, a,b,c,d,e)
  269.     local v = a
  270.     v = v * lv + b
  271.     v = v * lv + c
  272.     v = v * lv + d
  273.     v = v * lv + e
  274.     return math.floor(v/1000)
  275. end
  276.  
  277. local function distance(a,b,c,d,e)
  278.     local s = 0
  279.     for i = 1, 98 do
  280.         local v = approximate(i, a,b,c,d,e)
  281.         s = s + math.pow(v - exp[i], 2)
  282.     end
  283.     return s
  284. end
  285.  
  286. local mindist = 1e30
  287. for a = 9,11 do
  288.     for b = 280, 300 do
  289.         for c = 1000, 1100 do
  290.             for d = 1000, 1300 do
  291.                 for e = 300, 700 do
  292.                     local dist = distance(a,b,c,d,e)
  293.                     if dist < mindist then
  294.                         print(string.format('%4i %4i %4i %4i %4i %s',
  295.                             a,b,c,d,e, dist))
  296.                         mindist = dist
  297.                     end
  298.                 end
  299.             end
  300.         end
  301.     end
  302. end
Add Comment
Please, Sign In to add comment