Coding Priority

by Moiraine

Back to Mechanic's Corner.

Moiraine2008-07-24 20:24:01
I'm looking for a little help in building my own priority system from scratch. Once I understand how to work on that, I'll be able to build the rest of my own system, which is something I really want to do.

My latest attempts have circled around making databases listing all the afflictions with boolean states. However, I can't seem to even get half the db functions to work, much less the idea as a whole.

Any Cmud gurus out there willing to spend a little one on one time? blackeye.gif
Unknown2008-07-24 21:39:46
I use string lists for priority. Where each affliction is in the list determines its priority, as you can determine with the %ismember function. I don't track current afflictions with string lists. I use a data record variable for that, adding the key/value pair (value is usually 1, but not always) when I get the affliction and simply deleting the key when the affliction is cured or reset.
Catarin2008-07-24 22:02:27
As Zarquan said it's usually a good practice to have a master string list (string list because string list sorting doesn't get messed up in cmud like a db record sorting might. A string list will stay in the order you specify when building/modifying it) and then some other container that holds your current afflictions. You can then do something like loop through your master list and compare it to your current afflictions, curing things when there is a match (however you manage the actual cure).

For example, let's say you have a list called MasterList with all afflictions. Then you have a list called CurrentList with everything you currently have. Your algorithm for actually curing might look something like this:

#FORALL @MasterList {#IF (%ismember(%i, @CurrentList)) {do something with %i}}

This insures that your afflictions are being cured in the priority you have set for them to be cured with.

An alternative method sometimes used is to have all your afflictions stored in a list but you just name your afflictions something easily sorted by. For example, if aeon is your first priority to cure, anytime you get aeon, you add 001_aeon to your list. Let's say paralysis is added with 002_paralysis.

Then when you actually want to cure, you first sort your list of afflictions (currentlist still) and then you go through the list and do your cures. For example let's say you got dizziness, paralysis, and anorexia in that order. Your list would start out looking like this:

006_dizziness|004_paralysis|002_anorexia

Then you decide you want to cure and that code would look something like this:

%sort(@CurrentList)
cure %item(@CurrentList, 1) (or better yet depending on how precisely you set your lists up, #FORALL @CurrentList {cure %i}}

I prefer the former method because I find it easy to build and easy to maintain though this second method can be easy to maintain if you build it properly.

There are a lot of ways to do priority curing. These are just a couple of the more common.
Unknown2008-07-25 01:51:54
Problem with first method: you're looping through every affliction every time you check what to cure, which isn't usually as efficient as just looping through your current afflictions.

Problem with second method: much more rigid in how your priorities are setup, leaving little room for changing things in the future, making maintenance more difficult.

The general concepts are sound, though, and I'm sure each person who builds a system will find a different way to do it. smile.gif
Nezha2008-07-25 06:47:09
I considered adding a priority curing but did not because of the following reasons

1. The afflictions are too few. Maybe the biggest affliction i had was about 6-8 and i was not curing anything that time.. Looking at my logs, there are just not anything that can stack affliction of the same balance to screw things up to warrant the coding..

2. I was still gonna do it, but field tests indicate that it doest really hinder curing at all.. (for emergency: yay allheal/phial/green)

I just prioritized according to balance instead.. i.e. purgative first before salve, or something like that..

You could still do it though. Might be nice actually to have something like that.

However, i might have misunderstood the question.. if the question is about how to build a complete system and not just a priority curing 'module'.. there is a thread somewhere i think.. and well, you can take a look at my system and maybe it will give you an idea or two..
Unknown2008-07-25 11:13:26
Even if your priority system ends up just being "if aff1 then cure aff1 else if aff2 then cure aff2 ...," it's still curing things in a priority order. There's hardly a way to avoid prioritizing your curing, unless you're throwing a random number sequence into it.
Nezha2008-07-25 12:44:53
as I've said, i prioritized according to balance.. what gets eaten first if sya - you have multiple herb-cure affliction though.. is dependent on the behavior of lua tables.. which ive not taken time to investigate too deeply though..

(and of course the system wont eat if you have things like slitlock, etc.. but that's not priority curing, that's just common sense fail checks..)
Catarin2008-07-25 13:09:39
Priority curing is useful primarily because you usually want to cure those afflictions that hinder your ability to cure others before you cure more "minor" afflictions. Let's say you have a queue for herb afflictions that probably works on a principal of fifo (first in first out). Let's say you cure stupidity with pennyroyal and an arm artery with yarrow. You get the arm artery first. You keep trying to eat yarrow but the stupidity is preventing you from doing so. Not only that, your other commands are failing as well. You miss a health application and eating a sparkleberry. One of your attacks fails.

Let's say you have anorexia, which you cure by smoking coltsfoot. Let's say you have a phrenic nerve as well which is cured by smoking myrtle. You keep trying to smoke myrtle and it takes a few tries to cure that phrenic nerve. Meanwhile you cannot cure any of the afflictions you designated as herb or elixir. Nor can you sip health or eat sparkleberry.

It only takes a couple of seconds to get behind in a fight against a good opponent who knows how to take advantage of it. A priority order to curing isn't necessary but it can help. Especially helping to avoid the "one off" type situations of coding in something special to deal with a common affliction.