Feature Change item string fuzzy matching to prefer owned items

The CLI commands `use`, `drink`, `equip`, `maximize`, and others, all use fuzzy matching for items when an exact match of an item name is not provided. If multiple items match the string that you submit, mafia chooses 1 of them for you. This can result in unexpected behaviour, especially when new content is added (like the new replica IotMs in LoL). Also, if you type something like `use closed-circuit` into the GCLI, mafia sometimes thinks you want to purchase and unpackage a new closed-circuit phone system instead of use the bound one you have in your inventory.

Typing the exact item name is also not always an option when special characters are used. If I want to specify to equip kramco in a maximize string using an exact match, I need to use `™`, which contains a semicolon which breaks the line and breaks maximizer. The current workaround is to use pilcrows and an itemid, which is a very bad user experience for a variety of reasons.

I understand that the current matching strategy is:
1. Check for exact match of any item name
2. Check for fuzzy match of any item name

I propose changing the way item-string matching to the following:
1. Check for exact match of any item name
2. Check for fuzzy match against items in players' inventories (and closets, etc. if appropriate settings are enabled)
3. Check for fuzzy match of any item name

I believe this would solve most/all issues with replica IotM item-name confusion, and it would more closely match what native KoL does, and what most players probably expect when they type an incomplete item name.

It is possible that some existing scripts rely on the current behaviour, but those scripts made dangerous decisions when they were written to use fuzzy matching in the first place, and future game updates are likely to break them down the line.
 

Veracity

Developer
Staff member
Fuzzy matching is for user input.

Scripts are able to - nay, are expected to - use exact matching; since the script author only needs to enter exact names once - at script creation time - depending on KoLmafia to work around your laziness, is, well, lazy.
 

fronobulax

Developer
Staff member
Dunno.

Script writers need to write what they mean. gUI users usually have some kind of assist in selection. So this only applies in a place where a user is actually typing something. I am not certain we always know when we are parsing a string whether we are only expecting a real item or whether a command, script name or some other non-item would be allowed. This FR would be what we want for some commands but it is probably not what is wanted for buy and acquire. In other areas of the code if there is more than one fuzzy match that triggers some kind of failure and a case could be made that should happen more often. But in my experience fuzzy matching is biased towards the beginning of the string and I expect replicat Mr. A. would never fuzzy match Mr. Accessory as a possibility.
 

Ryo_Sangnoir

Developer
Staff member
Looking at the code, it should prioritise shorter names (for CLI commands), so kramco / replica kramco should already go the way you want in aftercore.
Typing the exact item name is also not always an option when special characters are used. If I want to specify to equip kramco in a maximize string using an exact match, I need to use `™`, which contains a semicolon which breaks the line and breaks maximizer. The current workaround is to use pilcrows and an itemid, which is a very bad user experience for a variety of reasons.
Another workaround is to equip the Kramco first, then do -offhand to not change the offhand. This doesn't help -equip or bonus, but it does help force-equip.
(and closets, etc. if appropriate settings are enabled)
This makes the feature implementation substantially more complicated, is not required by any of your examples, and is not how KoL works, besides. If this is implemented, I would rather it take from inventory only. Do you really want it to prefer identifying items in your stash, and then ignoring the stashed item and buying it from the mall?
 
Fuzzy matching is for user input.

Scripts are able to - nay, are expected to - use exact matching; since the script author only needs to enter exact names once - at script creation time - depending on KoLmafia to work around your laziness, is, well, lazy.
Agreed. Mostly. As discussed in the original post, some maximizer strings must use fuzzy matching, or they break the maximize command. But otherwise, this request is about manual GCLI input.

This FR would be what we want for some commands but it is probably not what is wanted for buy and acquire. In other areas of the code if there is more than one fuzzy match that triggers some kind of failure and a case could be made that should happen more often.
I agree that for buying items, it's less clear what it should do. But I also think that it's unclear to the user what it will do with the current implementation as well. I suspect that users are more likely to be careful to type a complete item name when attempting to buy an expensive item, than when trying to equip or use an expensive item that they already own.

So I think it would be better to prefer matching an item the user owns, since that is what will be expected in most cases. In the other cases (buying something), it is unclear what the user will expect, and so there's no clear guidance on what should be done. I would treat this as a "don't care state", and I would probably just allow it to prefer buying items you already own as well. But if there is a compelling reason for it to do something else, that would be fine, too.

I think the suggestion of throwing an error when there are multiple matches is also a reasonable approach to the problem. It doesn't solve the issues with maximizer breaking with items like kramco, though. Ryo's suggested workaround for that still offers an incomplete solution.

This makes the feature implementation substantially more complicated, is not required by any of your examples, and is not how KoL works, besides. If this is implemented, I would rather it take from inventory only. Do you really want it to prefer identifying items in your stash, and then ignoring the stashed item and buying it from the mall?
No, I don't want that, but that's why I have the preference to retrieve from stash set to false, which is the default, and what most players will prefer for a variety of reasons already. Players who routinely use their clan stash may, in fact, want that behaviour? I don't know. I'm not one of them.
 
Top