# How much Mana do I need?

Dungeon Master was one of the first ever real-time role-playing games, originally released in 1987 on the Atari ST. Among other exciting things for the time, it offered a rather sophisticated spell system based on runes.

Your task today is to write a program or function that evaluates the number of Mana points required to cast a given spell in Dungeon Master.

The 'spell cast' system is the top right cyan box in the above picture.

## Spells, runes and Mana

Dungeon Master spells are composed of 2 to 4 runes, picked among the following categories, in this exact order:

1. Power (mandatory)
2. Elemental Influence (mandatory)
3. Form (optional)
4. Class / Alignment (optional)

It means that valid spells are either:

• Power + Elemental Influence
• Power + Elemental Influence + Form
• Power + Elemental Influence + Form + Class / Alignment

Each category contains 6 runes, and each rune has an associated base Mana cost:

=============================================================================
| Power               | Rune      |   Lo |   Um |   On |   Ee |  Pal |  Mon |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    1 |    2 |    3 |    4 |    5 |    6 |
=============================================================================
| Elemental Influence | Rune      |   Ya |   Vi |   Oh |  Ful |  Des |   Zo |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    2 |    3 |    4 |    5 |    6 |    7 |
=============================================================================
| Form                | Rune      |  Ven |   Ew | Kath |   Ir |  Bro |  Gor |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    4 |    5 |    6 |    7 |    7 |    9 |
=============================================================================
| Class / Alignment   | Rune      |   Ku |  Ros | Dain | Neta |   Ra |  Sar |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    2 |    2 |    3 |    4 |    6 |    7 |
=============================================================================


## Evaluating the Mana cost

The Mana cost of the spell is the sum of the Mana cost of all runes:

• The cost of the Power rune always equals its base cost (from 1 to 6).

• For the other runes, the following formula applies:

where power is the base cost of the Power rune.

## Examples

Spell: Lo Ful
Cost : 1 + floor((1 + 1) * 5 / 2) = 1 + 5 = 6

Spell: Um Ful
Cost : 2 + floor((2 + 1) * 5 / 2) = 2 + 7 = 9

Spell: Pal Vi Bro
Cost : 5 + floor((5 + 1) * 3 / 2) + floor((5 + 1) * 7 / 2) = 5 + 9 + 21 = 35


## Clarifications and rules

• Your input will consist of 2 to 4 strings designating the runes of the spell. You can take them in any reasonable format, such as 4 distinct parameters, an array of strings (e.g. ['Lo', 'Ful']), or just one string with a single-character separator of your choice (e.g. 'Lo Ful'). Please specify the selected input format in your answer.
• The runes are guaranteed to be valid.
• The order of the categories must be respected. Unused categories may be either missing or replaced with some falsy value.
• You can accept the runes in any of these formats: 1. A capital letter followed by lower case ('Ful') 2. All lower case ('ful') 3. All upper case ('FUL'). But you can't mix different formats.
• Quite obviously, we do not care to know whether the spell actually has some effect in the game (for the curious, useful spells are listed here.)
• This is , so the shortest code in bytes wins.
• And remember: Lord Chaos is watching you!

## Test cases

Spell          | Output
---------------+-------
Lo Ful         | 6
Um Ful         | 9
On Ya          | 7
Lo Zo Ven      | 12
Pal Vi Bro     | 35
Ee Ya Bro Ros  | 31
On Ful Bro Ku  | 31
Lo Zo Kath Ra  | 20
On Oh Ew Sar   | 35
Ee Oh Gor Dain | 43
Mon Zo Ir Neta | 68
Mon Des Ir Sar | 75

• Tangential - but for people that like this system, The Magical Land of Wozz is a Japanese SNES game (English translation available) that implements nearly the same system - where any string of letters becomes a spell. google.co.jp/webhp?ie=UTF-8#q=magical+land+of+wozz – Coty Johnathan Saxman Jun 30 '17 at 7:10
• I have a vague memory of watching someone play Dungeon Master (I don't think it was on the ST). They had equipped one of their fighters with a magic necklace, and every so often they would check whether it had recharged and if so cast another rune of what I think was a light producing spell of some sort, so that the fighter was able to cast this spell every ten minutes or so, and eventually gained a level in wizardry. – Neil Jun 30 '17 at 8:39
• @Neil This necklace was probably either the Moonstone (+3 Mana) or the Pendant Feral (+1 Wizard Skill). All items are listed here. – Arnauld Jun 30 '17 at 8:55
• this script should output all possible input combinations – NieDzejkob Jul 1 '17 at 12:43

$1 \G1 11 11  Try it online! Link includes test cases. Takes space-separated runes. Explanation: The initial stages simply convert each rune to a digit, which is then converted to unary. The numbers after the first are multiplied by one more than the first number, following which the first number is doubled. The final stage integer divides all the result by 2 and takes the sum. # Go, 205 bytes func c(s []string)int{f,l:=strings.IndexByte,len(s) p:=f("UOEPM",s[0][0])+3 r:=p-1+p*(f("VOFDZ",s[1][0])+3)/2 if l>2{r+=p*(f("war o",s[2][1])+5)/2} if l>3{r+=p*(f("it Ra",s[3][len(s[3])-2])+3)/2} return r}  It's a callable function, takes runes as a slice of strings, e.g. []string{"Um", "Ful"}. Try it on the Go Playground. # C, 225 Thanks to @ceilingcat for some very nice pieces of golfing - now even shorter i;b(r,s)char*r;{for(i=17;i--&&"& ;$ # 4 %        ; B * 6 $8 6 5 - >3 + A@( . 6 5 "[s+i]-3-(*r^r[1]););return~i?i/2+1:0;}main(n,r)int**r;{n=b(*++r,0);printf("%d\n",n-(b(r[1],17)+b(r[2],34)+b(r[3],51))*~n/2);}  Try it online! A more ungolfed version of my original answer: #include<stdio.h> char*a="& ;$ # 4 %      "
"  ; B * 6 $8 " " 6 5 - >3 +" " A@( . 6 5 "; int b(char*r,int s){ for(int i=0;i<17;i++) if(a[i+s]-3==(r[0]^r[1])) return i/2+1; return 0; } #define c(p,r,i)(p+1)*b(r[i+1],i*17)/2 int main(int n,char**r){ int x=b(r[1],0); printf("%d\n",x+c(x,r,1)+c(x,r,2)+c(x,r,3)); }  You need to supply four command line arguments - so for the first test case you need to run ./a.out Lo Ful "" "" • @ceilingcat Good job getting rid of the #define – Jerry Jeremiah Sep 11 '20 at 4:58 ## Haskell, 623 bytes Using ADTs instead of numerical voodoo. NOTE: Add 36 for {-# LANGUAGE GADTs,ViewPatterns #-} • Score is computed assuming that it is compiled/run with -XGADTs -XViewPatterns data P=Lo|Um|On|Ee|Pal|Mon deriving(Enum,Read,Eq) data E=Ya|Vi|Oh|Ful|Des|Zo deriving(Enum,Read,Eq) data F=Ven|Ew|Kath|Ir|Bro|Gor deriving(Enum,Read,Eq) data C=Ku|Ros|Dain|Neta|Ra|Sar deriving(Enum,Read,Eq) data S where S::P->E->S Q::P->E->F->S R::P->E->F->C->S k(a:b:x)=let{p=read a;e=read b}in case x of{[]->S p e;[c]->Q p e(read c);[c,d]->R p e(read c)(read d)} c,d::Enum a=>a->Int c=succ.fromEnum d=(+2).fromEnum e Bro=7 e x=(+2).d$x
f x|c xelem[1,5,6]=d x|2>1=c x
g p f x =(div2).(*f x).succ$c p h(S x y)=c x+g x d y h(Q x y z)=h(S x y)+g x e z h(R x y z t)=h(Q x y z)+g x f t main=print.h.k.words=<<getLine Input: a single spell as a normal string e.g. Lo Ful Um Ful Multilining can be done by replacing the last line with main=interact$unlines.map(show.h.k.words).lines