Bug - Fixed Modifier maximizer wants to put one weapon in mainhand/offhand simulaneously

antimarty

Member
I have just one finger cymbals in inventory; apparently it's my best +MP item for the weapon and offhand slots. When I maximize MP, mafia first puts it into the weapon slot, then removes it to put it in the offhand slot, and then aborts with a message about "Why bother putting a weapon into your offhand if you don't have anything in your on-hand?"

r10763
 

Fluxxdog

Active member
Bug in later version: r11306

Had to revive this one as I had the bug myself, rather than post a duplicate. This time it was with a witty rapier.
Code:
Maximizing -familiar,mysticality experience,equip mayfly bait necklace,equip Juju Mojo Mask,equip Crown of Thrones...
Maximizing...
310 combinations checked, best score 10.06
Wielding witty rapier...
Equipment changed.
Taking off witty rapier...
Equipment changed.
Holding witty rapier...
Why bother putting a weapon into your offhand if you don't have anything in your on-hand? "On-hand?" Whatever.
Returned: false
==>ran again in maximizer, added dump<==
Maximizing...
SLOT 0
[googly-ball hat (257), Crown of Thrones (536,871,169)]
SLOT 1
[ocarina of space (771)]
SLOT 2
[ball-in-a-cup (257)]
SLOT 3
[paperclip cape (536,871,169)]
SLOT 4
[cane-mail shirt (536,871,169)]
SLOT 5
[buoybottoms (536,871,169)]
SLOT 6
[stainless steel scarf (536,871,425), bone spurs (257), C.A.R.N.I.V.O.R.E. button (514), Juju Mojo Mask (536,871,169), mayfly bait necklace (536,871,169)]
SLOT 7
[witty rapier (514)]
SLOT 8
[rave whistle (257)]
SLOT 9
[little box of fireworks (257), Loathing Legion helicopter (536,871,169)]
SLOT 10
[]
SLOT 11
[wristwatch of the white knight (257)]
SLOT 12
[witty rapier (514)]
310 combinations checked, best score 10.06
Edit: I do realize that there is a mention of this in the help button that comes with the maximizer. However, this problem doesn't occur with accessories. I have 2 stinky cheese eyes at full power (+20% meat & items)
Code:
> maximize? meat,item,dump

Maximizing...
SLOT 0
[bounty-hunting helmet (257), Hodgman's porkpie hat (536,871,169), Crown of Thrones (536,871,169)]
SLOT 1
[Coily™ (514)]
SLOT 2
[Bag o' Tricks (257), Hodgman's garbage sticker (536,871,169)]
SLOT 3
[Camp Scout backpack (257), paperclip cape (536,871,169)]
SLOT 4
[origami pasties (257), cane-mail shirt (536,871,169)]
SLOT 5
[poodle skirt (257), Brimstone Boxers (536,871,169), Hodgman's lobsterskin pants (536,871,169), buoybottoms (536,871,169)]
SLOT 6
[stinky cheese eye (514), frosty halo (∞), Order of the Silver Wossname (513), mayfly bait necklace (536,871,169), molten medallion (536,871,169), Juju Mojo Mask (536,871,169), stainless steel scarf (536,871,425)]
SLOT 7
[octopus's spade (2,056)]
SLOT 8
[bottle-rocket crossbow (257)]
SLOT 9
[little box of fireworks (257), Loathing Legion helicopter (536,871,169)]
SLOT 10
[]
SLOT 11
[wristwatch of the white knight (257)]
SLOT 12
[bottle-rocket crossbow (257), octopus's spade (2,056)]
66408 combinations checked, best score 474.50
It doesn't try equipping 3 eyes.
 
Last edited:

slyz

Developer
I don't have Double-Fisted Skull Smashing, so I can't reproduce this.

To resume, the problem occurs when the same weapon is the best item for the weapon and the off-hand slot, but you only have one?
 

fronobulax

Developer
Staff member
I had problems several days ago specifically with the witty rapier. The maximizer wanted to equip one off hand, and one on hand and failed in executing that. I did have two in the inventory and wondered whether it was just a data problem with the the rapier but I never followed up.
 

slyz

Developer
Oh, if you had two in your inventory, the problem probably comes from EquipmentRequest then. What happens if you equip a 1h weapon, leave a second in your inventory, and use "equip offhand X" ?
 

fronobulax

Developer
Staff member
Oh, if you had two in your inventory, the problem probably comes from EquipmentRequest then. What happens if you equip a 1h weapon, leave a second in your inventory, and use "equip offhand X" ?

The character with the rapiers has moved into HC so doesn't have any but putting Knob Goblin tongs in the weapon slot and then "equip offhand knob goblin tongs" does leave me with two sets of tongs equipped.

I did just strip down to my Birthday Suit (or rather the character did) and Maximize on Spell Damage and choosing and then equipping both to tongs worked as expected. I remain suspicious of the properties of the rapier as understood by KoL and KoLmafia although I have no rational reason for doing so.
 

Theraze

Active member
This could be the issue that Veracity mentioned about two weeks or so back where the maximizer tries to acquire each item singly, so it runs acquire/retrieve_item and unequips the existing item. Relevant posts 772-775 in autoBasement script. Maybe related to 776-777 as well, which is the outfit command's grasp of a/r_i.

Summary: Items are considered as individually important, rather than as a group. As such, it acquires and equips each individually. Because of this, mafia sometimes strips items from your equipped section to move it to your inventory so it can re-equip it to another slot. Veracity mused about considering the total amount needed and retrieving that once instead.
 

slyz

Developer
I think the maximizer simply executes the command associated to a boost ("equip off-hand witty rapier", for example). It doesn't have any code to retrieve, relying instead on the CLI command.

My guess is that something is happening with the "equip" command.

EDIT: or with InventoryManager.retrieveItem()

EDIT2: or with the inventory list, while the maximizer is doing his thing
 
Last edited:

Fluxxdog

Active member
I don't have Double-Fisted Skull Smashing, so I can't reproduce this.

To resume, the problem occurs when the same weapon is the best item for the weapon and the off-hand slot, but you only have one?
Correct.
 

relyk

New member
maximize function and interaction with closet

Version: v15.4 r11389

My logout script looks like this:
Code:
	cli_execute("maximize adventure");
	
	if( can_interact() ){
		batch_open();
		int[item] inventory = get_inventory() ;
		foreach it in inventory
			put_closet( inventory[it], it ) ;
		batch_close();
	}
So it's just maximizing adventures from equipment and storing the rest in the closet. Now what it's storing includes 3 Natty Blue Ascots for farming, where the outfit is built from "maximize meat" command. If I run maximize meat again, it ends up doing this:
Code:
Maximizing...
384 combinations checked, best score 430.24
Removing items from closet...
You acquire an item: ancient turtle shell helmet
Putting on ancient turtle shell helmet...
Equipment changed.
Removing items from closet...
You acquire an item: duct tape shirt
Putting on duct tape shirt...
Equipment changed.
Removing items from closet...
You acquire an item: boneana hammock
Putting on boneana hammock...
Equipment changed.
Removing items from closet...
You acquire an item: natty blue ascot
Putting on natty blue ascot...
Equipment changed.
Taking off natty blue ascot...
Equipment changed.
Putting on natty blue ascot...
Equipment changed.
Taking off natty blue ascot...
Equipment changed.
Putting on natty blue ascot...
Equipment changed.
And I end up with the first two accessory slots empty and the third containing a Natty Blue Ascot. The two other Natty Blue Ascots are still in the closet. The first problem (and probably causes the bug) is that the Natty Blue Ascot is listed as (1 max) in gear changer, so Mafia thinks you can only equip one. It then pulls one from the closet and tries to equip it in each slot; I assume because there are 3 total available. If I then pull the other two from the closet and use the maximize command again, it will equip all three appropriately, now showing (3 max). I've managed to get it to (4 max) with all 3 ascots, so I assume it's incrementing. If you repeat the process, it again only equips the single ascot and shows (1 max). Seems like this is just an issue with incorrect data, but couldn't mafia self-correct if it's incrementing the max number you can equip?
 

Fluxxdog

Active member
"maximize meat" pulls 1 ascot and equips acc1, removes, equips acc2, removes, equips acc3. Is there a possible connection to this bug report? Would adding "dump" to the maximize command help with debugging?
 

Theraze

Active member
As I said there...

This could be the issue that Veracity mentioned about two weeks or so back where the maximizer tries to acquire each item singly, so it runs acquire/retrieve_item and unequips the existing item. Relevant posts 772-775 in autoBasement script. Maybe related to 776-777 as well, which is the outfit command's grasp of a/r_i.

Summary: Items are considered as individually important, rather than as a group. As such, it acquires and equips each individually. Because of this, mafia sometimes strips items from your equipped section to move it to your inventory so it can re-equip it to another slot. Veracity mused about considering the total amount needed and retrieving that once instead.

If this shouldn't get merged to the other post, then it's definitely tied into the thing Veracity was talking about. Basically, currently maximizer individually does retrieve_item on each item singly. It needs to collect them all together...
 

roippi

Developer
Since I'm going in and fixing this, here's a question to further my knowledge. It's really not a big deal here, but I like doing things the Right Way.

If I have a collection of Strings, what is the most efficient algorithm to determine which (if any) are equal to others in the collection?

Baseline method is to do brute-force nested foreach loops. I believe that's O(n^2)? My next thought was to sort the collection then just do a sequential comparison... probably ends up being close to O(nlogn)?

Just curious; the collection in question happens to be trivially small in this specific case.
 

Catch-22

Active member
If I have a collection of Strings, what is the most efficient algorithm to determine which (if any) are equal to others in the collection?

Baseline method is to do brute-force nested foreach loops. I believe that's O(n^2)? My next thought was to sort the collection then just do a sequential comparison... probably ends up being close to O(nlogn)?

What is your end result?

If you don't want duplicates in the collection, use a set instead.

If you want to determine the number of elements in a collection equal to any given object, use frequency.
 

roippi

Developer
Can't use a set, because I need to first count up the number of duplicate strings (say, three "pull & equip blue natty ascot") and then remove all of them and add a "pull & equip 3 blue natty ascot".

Frequency sounds pretty cool (though in this case has a bit of extra O(n) overhead on the removal step), yay 1.5.

Edit: wait, will that work on string literals?

Edit2: yes. "More formally, returns the number of elements e in the collection such that (o == null ? e == null : o.equals(e))." Since String overrides equals(), should be okay.
 
Last edited:

Catch-22

Active member
Can't use a set, because I need to first count up the number of duplicate strings (say, three "pull & equip blue natty ascot") and then remove all of them and add a "pull & equip 3 blue natty ascot".

You can still use a set in this case, by tracking the amount of times the add method returns false, you'd know there's 1+falsecount of that element.

Another alternative, if you could change the way your original data is being stored, might make things easier. I had a brief look at maximize and I can only guess you are working with the possibles ArrayList. If possibles were instead a map populated like this:

Code:
map.containsKey( string ) ? map.put( string, map.get( string ) + 1 ) : map.put( string, 1 );

You'd be able to have a map of "possible things" with "amount of times they are possible" as the value. Once you have that, your problem becomes very simple to solve indeed :)
 
Last edited:

heeheehee

Developer
Staff member
If I have a collection of Strings, what is the most efficient algorithm to determine which (if any) are equal to others in the collection?

You'd be able to have a map of "possible things" with "amount of times they are possible" as the value. Once you have that, your problem becomes very simple to solve indeed :)

HashMap will give you N, assuming you have a perfect hash function and collisions are negligible. Otherwise, use a TreeMap (or sort the list) for O(N log N). (we're ignoring length of list). Or you could radix sort it for "linear" time. (negligible, since the number of buckets is way larger than the number of items you're considering, and either way: you're considering a total of maybe up to 10 items? Does efficiency _really_ matter here? Overhead of data structures may very well make the supposedly optimal solutions be the worst in practice.

(basically, nothing fancy is needed -- both of the propositions are certainly valid)
 

Catch-22

Active member
Like I said, mostly an educational exercise.

I can also sympathize with wanting to do things the best possible way :)

I get in trouble sometimes for spending too much time on things at work when they only need a quick hack though :(
 
Top