# EL formula help...

#### Valdier

##### Explorer
I am currently working on a monster database with a web front end... I have gotten to the point where I am mostly finished with my 1.0 design...

The final stage I am at is generating an estimated EL for an unlimited number of monsters.

I am currently thinking something along these lines. (no specific language in the example- using java though)

int elArray[];
int a;
int b;

while(combinedTwoCR's){
for(int i = 0; i < elArray.length; i++){
for(int j = 0; j < elArray.length; i++){
//pseudo code now
if a(+/- 1) = b (+/- 1)
delete a,
delete b,
start again... until no combined then take the highest value and call it the EL

}
}

Anyone already write a formula for this? the important part being that it will work with any number of monsters of any CR.

a preview of the program can be seen at:

www.valdier.com/backup/monsterFinder

feel free to email me if you have any suggestions. I am not an algorithm person

#### Valdier

##### Explorer
Ok so after sleeping and talking to a friend I realized half of what I am doing is a waste of time

I will post my final formula here when I am done.

#### Valdier

##### Explorer
Ok, so here is the final formula I used for determining EL's in case anyone cares
(Note it is in java)

public static Integer calculate(ArrayList list){

int current;
int next;
int temp;

while(list.size() > 1){
java.util.Collections.sort(list);

current = ((Integer)list.get(0)).intValue();
next = ((Integer)list.get(1)).intValue();

if((current == next) || (current + 1 == next)){
temp = current;
list.remove(0);
list.remove(0);
}
else{
list.remove(0);
}
}
return (Integer)list.get(0);
}

If anyone has any comments feel free to send them

#### malakai6276

##### First Post
ncie job...

it;s refreshing to see good code doing good things.... thanks... i'll add it to my library....

--J

#### dvvega

##### Explorer

1) your monster list "screws up" under certain conditions ...

Example: select CR and Cold climate, click search. I get a list.
Select the Bear, Polar at the top and add to encounter. All the monsters up to (not including) ettin are removed from the list. So I cannot add another bear, or any dragons for example.

I did some more testing, and it's almost as if you're "dropping" the first two monsters after a transaction.

Perhaps you should allow the user to type in a number next to the monster desired??

2) the EL calculation is wrong, in some cases. In particular for mixed pairs of CRs (pg 101, DMG).

Example: take two monsters, one CR 14, one CR 16 (Two Bronze Dragons, one an Adult, one a Mature Adult).

Your value for EL = 16. The correct value should be 17.

#### Leopold

##### Management(tm)
now if only there were a way to add in manual CR's and come out with the total. I LOVE the breakdown of xp by classes. Is there a way to space it out even more? LIke get a chart from 1-10 and than go forward to 11-20?

I like it very nice just add some customizations and it will be a staple of my gaming computer!!

#### MonkeyBoy

##### First Post
ahem...

you should split apart the list handling from the calculation. e.g.

(treat this a pseudo-code, me no do java no more...)

int getELFrompair(int a, int b)
{
if((a == b) || ((a + 1) == b))
{
return a+2;
}
else
{
return b;
}
}

int getELFromList(list theList)
{
int temp;
while(theList.length > 1)
{
temp = getElFromPair(theList(0), theList(1));
theList.delete(0);
theList(0) = temp;
}
return theList(0);
}

you should probably also be working on a copy of the list rather than destroying it as you go??

this means that you can then re-use your EL combination code without being tied to a list implementation...

and that'll make correcting slight errors in the combination code easier...

Last edited:

#### MonkeyBoy

##### First Post
right...

OK, quick nip to the car-park later...

it appears that what you actually need to do is somewhat more complex...

this is somewhat pseudocode-like.

(once you have your list to work on)

look at the head of the list
search the rest of the list for
either;
a matched CR
or;
a CR 2 points lower than the head
if you find one;
delete both the head and the pair node
if you had a match, replace with a single entry with CR = HeadCR + 2
if it was a pair with CR 2 lower replace with a single entry with CR = HeadCR + 1

repeat this until you cannot find a suitable pair for the head, or until the list is one long

if you cannot match the head, you must then try again on the rest of the list without the head

Now; each time you reduce, you have to start again on the WHOLE list - you treat a combined CR as a single creature, so that allows you to revisit "irreducible" CRs later.

I suggest you use recursion to do this - your end case for any recursion wants to be whenever a reduction is made

There may come a point where you cannot reduce the list; the rules approach this from the opposite (easier) direction, assuming you will construct an encounter from CRs rather than wanting to build the CR / EL from the encounter.

There also rises the spectre of having lists that reduce only if tackled in a specific order...

Your other option is to invent a mechanism yourself which WILL reduce all lists, i.e. to plug the gaps

Good Luck!

#### MonkeyBoy

##### First Post
further

to reduce the chances of being unable to reduce the list, you need to find an orderin which to process the entries which raises the lower CRs towards the higher.

therefore i suggest you sort the list in ascending order before beginning (which i think you were, on reflection)

but, you may need to do a search to find the "best next reduction" in order to work towards constructing combined CRs which are equal to or 2 less than another higher in the list.

suddenly this looks non-trivial, neh?

#### MonkeyBoy

##### First Post
ahem...

you might like to take a look at this (dusted off my java books, you got me interested you see...)

Its just a noddy class to try out my pseudo code above, seems to pas a first-glance look

#### Attachments

• elcombinator.zip
1.7 KB · Views: 1,696

#### Valdier

##### Explorer
Valdier

Sorry I hadn't replied earlier, I actually figured once I corrected myself that nobody would look at the thread again

Glad to see people are doing so. One major thing I need to do with this is the CR < 1 calculations... that is a real pain.

When I wrote the EL calculations I originally was thinking only mixed pairs within 1 CR of each other mattered but I now see I was wrong

I will post my final EL calculation when I update it.

#### Valdier

##### Explorer
Ok, here we go...

This is the latest version, not handling EL < 1. Didn't take too much, just another if/else. As a note, I am destroying the object each time rather than caching it because it makes debugging 100x easier. I will start caching all the data once I am sure everything works right

public static Integer calculateEL(ArrayList list){

int current;
int next;
int temp;

while(list.size() > 1){
java.util.Collections.sort(list);

current = ((Integer)list.get(0)).intValue();
next = ((Integer)list.get(1)).intValue();

if((current == next) || (current + 1 == next)){
temp = current;
list.remove(0);
list.remove(0);

if(temp < 2){
if(next == 1){
}
else{
}
}
else{
}
}
else if((current + 2) == next){
temp = current;
list.remove(0);
list.remove(0);

}
else{
list.remove(0);
}
}
return (Integer)list.get(0);
}

#### Valdier

##### Explorer

'1) your monster list "screws up" under certain conditions ... '

Should be fixed now... it was an early thing I had in there when I was still adding "features" now the list for whatever you searched for "should stay" and should stay in the same sort order you had. I know the name sort arrow doesn't always highlight but that is intentional actually.

'2) the EL calculation is wrong, in some cases. In particular for mixed pairs of CRs (pg 101, DMG).'

Fixed also, the feedback from you and monkeyboy let me know I was doing the math wrong

thanks

*As a note, the reason I don't have it let you add a number next to a monster is because it's too hard to parse html responses to match the check box array that is returned by the browser. I suppose it is "technically" possible, I just don't have the patience to do it

#### Valdier

##### Explorer

'now if only there were a way to add in manual CR's and come out with the total. I LOVE the breakdown of xp by classes. Is there a way to space it out even more? LIke get a chart from 1-10 and than go forward to 11-20?'

I'm not sure exactly what you mean by this... do you mean, allow a text field that lets people enter X cr's and then spit out the final EL for them? I could do that fairly easy I suppose.

As far as the experience chart goes, as far as I can tell, I cannot reproduce the actual chart or the formulas for obtaining the numbers, but I can reproduce what the final value would be for that grouping of CR's. Are you just asking for a wider range than the standard +/- 4 that I have right now?

I just picked that range based off the DMG suggestion of level ranges and what they should be for encounters.

'I like it very nice just add some customizations and it will be a staple of my gaming computer!!'

Let me know what all else I can add, I am doing it mostly as a hobby currently so anything reasonable I will throw in. You can either drop suggestions here or email from the link on the page.

#### Leopold

##### Management(tm)
thanks for adding in the CR window! Now if only you could make it portable for us laptop users who need to travel around and not require it to be hooked up to the web to use!

#### Valdier

##### Explorer
Leopold said:
thanks for adding in the CR window! Now if only you could make it portable for us laptop users who need to travel around and not require it to be hooked up to the web to use!

Well... I will see what I can do... biggest problem is having to emulate my own DB for doing searches of the data, I will see what I can come up with although it will be a while.

Have to convert it to a swing app instead of a JSP/web app.

#### Geoff Watson

##### First Post
One way of working out EL, is to add all the XP values of the monsters together, and look at the closest CR to the total, and use that as the EL.

It doesn't work exactly, but will usually be close enough, as well as being a lot easier to write code for.

Geoff.

#### Valdier

##### Explorer
That is a possibility also Geoff, other than CE's <1 I have the formula working now, I could do CR's < 1 if I had any desire to actually spend the 30 minutes it would take to add the if/elses and update the database

#### Leopold

##### Management(tm)
Valdier said:
That is a possibility also Geoff, other than CE's <1 I have the formula working now, I could do CR's < 1 if I had any desire to actually spend the 30 minutes it would take to add the if/elses and update the database

please do as this incorporates goblins, orcs, kobolds and all othe manner of small critters my pc's like to kill

Replies
68
Views
3K
Replies
9
Views
618
Replies
17
Views
3K
Replies
25
Views
958
Replies
6
Views
435