Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:53:24+00:00 2026-05-16T17:53:24+00:00

I am trying to write a Python script that finds combinations of armor items

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:53:24+00:00Added an answer on May 16, 2026 at 5:53 pm

    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.

    from itertools import ifilter, product
    
    # Definition of ITEMS cut for brevity. See below.    
    
    def find_best(slots, maximize, constraints):
        """example call:
             find_best(['helm', 'chest'], ['slashing', 'bludgeon'],
                       {'encumbrance': 12})
        """
        # save the slot names to construct a nice return value
        slot_names = slots
    
        # pull the actual lists of items for each slot out of the global dict
        slots = [ITEMS[slot] for slot in slots]
    
        # this function calculates the value of a solution
        value = lambda solution: sum(float(slot[attr]) for attr in maximize
                                                       for slot in solution)
    
        # replace our constraints with functions to check solutions
        constraints = [lambda solution:
                           sum(float(slot[attr]) for slot in solution) < constraint
                     for attr, limit in constraints.items()]
    
        # start with all possible combinations
        solutions = product(*slots)
    
        # chain together ifilters to weed out the ones that fail any of the
        # constraints. Note that for optimum performance, you should place the
        # constraints in descending order of probability to fail
        for constraint in constraints:
            solutions = ifilter(constraint, solutions)
    
        # We're going to do decorate, max, undecorate
        solutions = ((value(solution), solution) for solution in solutions)
        value, solution = max(solutions)
    
        # get the indexes and return
        return dict((name, slot.index(item)) for name, slot, item
                    in zip(slot_names, slots, solution))
    

    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.

    ITEMS = { 'helm': [{'Acid':' 2.71',
                            'Bludgeoning': '1.04',
                            'Cold': '2.71',
                            'Encumbrance': '8.00',
                            'Fire': '2.71',
                            'Holy': '2.71',
                            'Impact': '1.30',
                            'Lightning': '2.00',
                            'Name': 'Plate Helm',
                            'Piercing': '1.17',
                            'Slashing': '1.30',
                            'Unholy': '2.71'},
    
                           {'Acid': '2.18',
                            'Bludgeoning': '0.92',
                            'Cold': '2.18',
                            'Encumbrance': '7.00',
                            'Fire': '2.18',
                            'Holy': '2.18',
                            'Impact': '1.15',
                            'Lightning': '1.65',
                            'Name': 'Scale Helm',
                            'Piercing': '1.03',
                            'Slashing': '1.15',
                            'Unholy': '2.18'}],
    
                  'chest':[{'Acid': '5.47',
                            'Bludgeoning': '2.05',
                            'Cold': '5.47',
                            'Encumbrance': '32.00',
                            'Fire': '5.47',
                            'Holy': '5.47',
                            'Impact': '2.57',
                            'Lightning': '4.06',
                            'Name': 'Plate Chest',
                            'Piercing': '2.31',
                            'Slashing': '2.57',
                            'Unholy': '5.47'},
    
                           {'Acid': '4.45',
                            'Bludgeoning': '1.84',
                            'Cold': '4.45',
                            'Encumbrance': '28.00',
                            'Fire': '4.45',
                            'Holy': '4.45',
                            'Impact': '2.30',
                            'Lightning': '3.31',
                            'Name': 'Scale Cuirass',
                            'Piercing': '2.07',
                            'Slashing': '2.30',
                            'Unholy': '4.45'}]}
    

    note that the values of the outermost dictionary are lists and not tuples as you said. There is a huge distinction!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 536k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just add return false in with the onclick... <?php echo… May 17, 2026 at 1:33 am
  • Editorial Team
    Editorial Team added an answer That's an RFC2047 encoded-word. You can partially decode it with… May 17, 2026 at 1:33 am
  • Editorial Team
    Editorial Team added an answer It's more common to have source files under a source… May 17, 2026 at 1:33 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write a script that will automatically update some attachments on a
I'm trying to write (what I thought would be) a simple bash script that
I'm a newbie and I'm trying to write a python script to build rpm
I am new to python (and this site); I am trying to write a
I have been receiving errors when trying to save and run this Python 3.1
I wrote a python script that rotates an image 90 degrees. I am including
I have been trying to use an ajax-style file upload component (like the dojox
I'm currently trying to make some small shell-like utility for a custom script I
I'm trying to extract text from arbitrary html pages. Some of the pages (which
I'm trying to extract data from the following page: http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37# Which, conveniently and inefficiently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.