0
\$\begingroup\$

The wealth system in d20 Modern always gives me a slight headache at character creation, because I know there's a better way to buy things, but I don't know exactly how, so I'm coming up with an algorithm to automatically buy things in the correct order to minimize losses, sticking it in a program, and just stop thinking about the whole thing. Help if you can, pls.


Algorithm

[Wealth is your Wealth Bonus, and DC is the Purchase DC of the item on the list. > is greater than, < is less than, >= is greater than or equal to, and <= is less than or equal to]

Wealth is a random value generated at the beginning (let's say 1 to 100), and the list of items purchased can contain up to 25 items of equally random purchase DCs. Just in case that's relevant. In the link above, it mentions things like 1d6 and 2d6. In the format xdy, x= number of dice rolled, and y = number of sides each dice have. So 2d6 would generate a number from 2 to 12. 1d6 would generate one from 1 to 6.

-

Run the following through all items in the list first, since if the following conditions are met, the item is free, but might not remain free if you lose wealth:

If DC <15 and (Wealth - DC) > 0 Purchase item

-

Then, determine if there are items on the list that would jump up a tier if you lost 1 wealth (So, if Wealth - DC = -10 or -15) [Don't check for Wealth - DC = 0, because it should have already been bought if it was.]

If there isn't, then purchase an item with DC >=15 and (Wealth - DC) > 0

Repeat that until there are either no more items fitting the conditions, or until you are on the verge of jumping up a tier.

-

(I haven't figured out how to optimize against tier-jumping. I'm inclined to immediately buy anything that might tip over in to -16 territory, and abandon anything that ends up there. If there are none, then prioritize any in the threat of going over a tier, and abandon any that might go in to the -16+ territory. There's some way to better formulate around these tiers, but it's rather mind-racking, and frustrating that I can't seem to figure it out!.)

-

Repeat the last process (that I actually outlined), but determining if items would jump up a tier if you lost 2 wealth If there isn't, then purchase an item with DC>=15 and (Wealth - DC) < 0 and (Wealth - DC) > -11 (I have no idea where in the queue I should put this, but I just felt like this would be the lowest priority purchase.)

If an item comes with a restriction of +2 or greater (and you only care about the wealth you have at the end), then, unless the black market adjustment pushes the item over a tier, take the black market because you don't lose as much wealth that way. If it's only +1, then take the license unless you have 9 wealth or less, in which case obey the previous rule on restriction.

\$\endgroup\$
  • 4
    \$\begingroup\$ This might be a good question if you made fewer assumptions about everyone knowing the rules of D&D. Abstract your problem, and you may get answers more quickly. \$\endgroup\$ – Engineer Aug 14 '16 at 11:24
  • 2
    \$\begingroup\$ Agree with @ArcaneEngineer - as is, this question seems a bit too d20 nich for GDSE. It would fit better at RPG Stack Exchange. \$\endgroup\$ – Pikalek Aug 14 '16 at 14:17
  • 1
    \$\begingroup\$ What is your actual question? \$\endgroup\$ – user1430 Aug 14 '16 at 15:09
  • \$\begingroup\$ Actual question: What algorithm do I need in order minimize the loss of wealth in the system linked to (It's only about 2 paragraphs long). \$\endgroup\$ – SangoProductions Aug 14 '16 at 20:29
  • \$\begingroup\$ I didn't assume anyone knew anything of D&D (Nor D20 Modern). I gave every bit of information that was relevant. I admittedly did forget that you can't buy something if the (Wealth - DC) < -20. \$\endgroup\$ – SangoProductions Aug 14 '16 at 20:33
1
\$\begingroup\$

but I don't know exactly how / just stop thinking about the whole thing

Provided that you don't need to know how the algorithm ultimately works, but only need to do the job, you might look into Genetic Algorithms. It is a highly iterative process that starts with a random genome per candidate, and, using an analogue to natural selection, slowly converges from those initial inputs toward an approximately optimal solution. The catch is that you must provide a fitness function by which to judge the genes of each successive generation. In your case this would be an evaluation of how much money was spent by each candidate (gene set). You do this for say 100 sets of virtual "genes", look at the best ones as judged by your fitness function(s), and perform gene crossover and mutation to arrive at the next generation of 100. These will gradually improve. "Genes" are either a random sequence of bits or some variables randomised each run.

Important: You must make sure that your genes represent some behaviour of your code, not some state. This is crucial, or you won't be able to converge on a solution. The change in a gene needs to be directly proportional to some measure of failure / success. See top answer here.

Rinse, repeat till you are happy with result. This process can be fully automated in code.

Genetic Programming may also be useful; though I doubt it will be necessary in your case - as I imagine you only need your parameters to evolve - not your code as such.

These are large topics so I will not go further here. Refer there for a simple starter tutorial.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ true. That might be a good idea. \$\endgroup\$ – SangoProductions Aug 14 '16 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.