I am trying to write a Python script that finds combinations of armor items from a game that match certain criteria. I have an object that has keys for each item slot (ie. head, chest, waist, etc.) and a list of all the items that can fit in that slot with their stats in each key. There are 10 slots and many items for each up to a total of 88 or so items.
My question is: Is there some kind of algorithm already used to do stuff like this? An example of what I would want to do is find the combination of armor pieces that gives me stat1 < 35 that has the highest stat2+3+4.
I don’t believe brute forcing it would be practical because it would take ages (correct me if I’m wrong). Any help would be appreciated!
Edit – More details:
Data sample: http://pastebin.com/rTH3Q5Sj The first tuple is 2 head slot items, 2nd tuple is 2 chest slot items.
One thing I might want to do with the sample data is get the combination of helm and chest that has the highest slashing/bludgeoning/piercing total but less than 12 encumbrance total.
It sounds like the elegant solution to this is linear programming. I can help with that if you provide more details.
with only 88 items spread out amongst ten slots, brute forcing it wouldn’t be terrible either. Some combination of the two might be the easiest.
update:
based on the update you gave, I think linear programming is overkill (and difficult to apply). I wrote you this fairly general solution. Study it and understand it. If anybody has any corrections or improvements, I’d love to hear them.
Note that you should be storing the values as floats and not as strings! It’s easier (because it’s often automatic when you need it) to cast to string than a float. Then you can take the ugly casts out of my code. I was just to lazy to do it for you. Note that you can call with as many constraints as you want but only one set of attributes to maximize. This made sense to me. If you study the code and understand it, you should be able to modify it to suit your tastes.
Here’s how I modified your data structure.
note that the values of the outermost dictionary are lists and not tuples as you said. There is a huge distinction!