Patch for considering foldable items in the maximizer

JimblyCakes

New member
I'm a long time user of KolMafia, but a first time contributor. Can I have check-in access? My SourceForge username is jonandersen, if that helps. And yes, I've tested the patch and it works.

Patch:
Add support for considering foldability in the modifier maximizer. Got tired of manually squeezing a stinky cheese diaper every day.

Diff attached as well.

Diff:

Code:
Index: src/net/sourceforge/kolmafia/swingui/MaximizerFrame.java
===================================================================
--- src/net/sourceforge/kolmafia/swingui/MaximizerFrame.java	(revision 9545)
+++ src/net/sourceforge/kolmafia/swingui/MaximizerFrame.java	(working copy)
@@ -367,10 +367,6 @@
 		MaximizerFrame.boosts.clear();
 		if ( equipLevel != 0 )
 		{
-			if ( equipLevel > 1 )
-			{
-				MaximizerFrame.boosts.add( new Boost( "", "(folding equipment is not considered yet)", -1, null, 0.0f ) );
-			}
 			MaximizerFrame.best = new Spec();
 			MaximizerFrame.best.getScore();
 			// In case the current outfit scores better than any tried combination,
@@ -1648,8 +1644,23 @@
 				count += (buy << Evaluator.NPCBUYABLE_SHIFT) | buy;
 			}
 			
-			// TODO: check foldability
-
+			// consider folding
+			int fold = 0;
+			String name = ItemDatabase.getCanonicalName(id);
+			ArrayList foldGroup = ItemDatabase.getFoldGroup(name);
+			if (foldGroup != null)
+			{
+				// if the item can be folded, add up the number of other items we have within the same fold group
+				Integer foldcost = (Integer) foldGroup.get(0);
+				for (int j=1; j<foldGroup.size(); j++)
+				{
+					if (name.equals(foldGroup.get(j))) continue; // don't add the item we are considering folding
+					fold += InventoryManager.getAccessibleCount(ItemDatabase.getItemId((String)foldGroup.get(j)));
+				}
+			
+				count += (fold << Evaluator.FOLDABLE_SHIFT) | fold;
+			}
+			
 			if ( (count & Evaluator.TOTAL_MASK) >= 3 || equipLevel < 3 )
 			{
 				return ItemPool.get( id, count );
 

Attachments

  • diff.txt
    1.6 KB · Views: 36
Last edited by a moderator:

jasonharper

Developer
This patch cannot possibly work right. If multiple forms of the same foldable were all the most beneficial items for their respective slots, the result would be that the maximizer would try to fold & equip all of them - even if you only had one of the items.

Also, you're not limiting the value of 'fold' to SUBTOTAL_MASK - anyone with more than 15 total items from the same fold group would experience some strange problems with this code.
 

JimblyCakes

New member
Good points. Limiting the value of 'fold' to SUBTOTAL_MASK is a basic fix, I've updated the patch.

This is a simple approach, but as you pointed out, it doesn't take into account that once an item is folded, it is no longer available. Perhaps that is a reasonable limitation though. Most foldables have different effects in their different forms, so only one form will be maximal for a particular target. But yes, there are some edge cases where more folding can happen than is optimal. Isn't it better than nothing though?

This patch cannot possibly work right. If multiple forms of the same foldable were all the most beneficial items for their respective slots, the result would be that the maximizer would try to fold & equip all of them - even if you only had one of the items.

Also, you're not limiting the value of 'fold' to SUBTOTAL_MASK - anyone with more than 15 total items from the same fold group would experience some strange problems with this code.
 

Attachments

  • diff2.txt
    1.6 KB · Views: 30

jasonharper

Developer
No, I absolutely do not consider a situation where the maximizer gives fundamentally useless advice to be "better than nothing". This isn't an edge case, it would screw up basically any time you're trying to maximize more than one modifier.
 
Does there exist code in the maximizer for mutually exclusive equipment already? If so, it seems that this could be modified for those cases where the maximizer needs to choose which transmutation in a given fold group is the best, though extending it so that the mutual exclusivity diminishes with additional copies of the folding item sounds like it'd be the hardest part.
 
Top