# Help searching multiple arrays faster.

## Recommended Posts

Before I start asking my question I wanted to clarify that it will be about a video game, I know what the rules are about automating games however automating is not my goal. My goal is write a script that takes the Dark Souls armor data and figures out the best set of armor for a specific weight and poise. Hopefully that is not an issue otherwise sorry for wasting your time.

I've written a script that works but I'm not a very skilled programmer so its very slow(it would take about a day to finish). What the script currently does is go through multiple For loops to check every possible combination of armor and their weight/poise, I've attached the actual script because I'm probably not explaning this very well. My question is whether it canbe written to make the searching faster or more efficient?

tl;dr Writing a script to find the best stat(weight/poise) armor for Dark Souls, need something faster than the attached script.

armorCalculator.au3

##### Share on other sites

I think you had some unnecessary tests in there, and doing the math at intermediate levels seems to help a bit. I'm not sure why the Sleep() statements were in there, but the minimum for a Sleep() is 10ms. So even if you specify Sleep(1), it will still delay 10ms.

You could try this loop:

```Dim \$bestSet[6]

\$bestSet[0] = 36
\$bestSet[1] = 24

For \$helm = 0 To 54
For \$chest = 0 To 55
\$totalWeight2 = \$helmData[\$helm][7] + \$chestData[\$chest][7]
\$totalPoise2 = \$helmData[\$helm][5] + \$chestData[\$chest][5]
For \$glove = 0 To 52
\$totalWeight3 = \$totalWeight2 + \$gloveData[\$glove][7]
\$totalPoise3 = \$totalPoise2 + \$gloveData[\$glove][5]
For \$boot = 0 To 55
\$totalWeight4 = \$totalWeight3 + \$bootsData[\$boot][7]
\$totalPoise4 = \$totalPoise3 + \$bootsData[\$boot][5]
If \$totalWeight4 <= \$bestSet[0] And \$totalPoise4 >= \$bestSet[1] Then
\$bestSet[0] = \$totalWeight4
\$bestSet[1] = \$totalPoise4
\$bestSet[2] = \$helm
\$bestSet[3] = \$chest
\$bestSet[4] = \$glove
\$bestSet[5] = \$boot
EndIf
Next
Next
Next
Next```

##### Share on other sites

Thank you so much Spiff, that works great. I always add sleep to loops, can't remeber where I read this but I thought it was a good idea so that the loop doesn't use too much of the CPU but I guess that would only be an issue with infinite loops. Or maybe I'm wrong on that too heh. Like I said I'm a pretty awful coder I just write stuff that helps me out once in a while nothing too complex.

##### Share on other sites

Your code doesn't look too shabby! Not sure what else you could easily do to speed it up. I threw some timers around the loops and it went from around 125 seconds to about 53. You could order the loops so that the heaviest items are processed first and add extra tests to bypass some of the inner loops. For instance if armor was your outer loop and boots the second, then you could say "If \$totalweight2 > \$bestSet(0) Then ContinueLoop". If you frequently encounter cases where just the armor plus boot weight alone is higher than your best so far, it ought to run faster. If that condition does not occur often, it'll probably slow you down.

The only place where I've seen Sleep() used, other than delays to allow webpages to load or I/O operations to complete or just for effect, is in GUIGetMsg() loops, where (at least in previous Autoit versions) GUIGetMsg() could peg your CPU.

##### Share on other sites

I think this is a bit overkill? I beat New Game+ in cloth. When the DLC comes out on Xbox 360 next month I'll go through New Game++ in cloth.

Anyway, this thread was reported but doesn't violate the rules. It's just number crunching.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...