Can anyone help me with a complex formula?

Simulated dice for role playing games
Post Reply
LordFlameStryke
Posts: 13
Joined: Wed Nov 25, 2009 9:06 pm
IQ Test: Orange

Can anyone help me with a complex formula?

Post by LordFlameStryke » Fri Jan 24, 2014 4:42 am

I have created a long formula for the classic World of Darkness game to calculate the number of success rolled based on number of dice rolled and a target number. The whole function is as follows (please forgive the lack of formatting).:

@1 ← #1 d10 @ .
@2← #2 .
@ONE ← count1( @1 ) .
@TWO ← count2( @1 ) .
@THREE ← count3( @1 ) .
@FOUR ← count4( @1 ) .
@FIVE ← count5( @1 ) .
@SIX ← count6( @1 ) .
@SEVEN ← count7( @1 ) .
@EIGHT ← count8( @1 ) .
@NINE ← count9( @1 ) .
@TEN ← count10( @1 ) .
if @SEVEN ≥ (#1÷2) then
@TRIPLE ← 1
else
@TRIPLE ← 0
end.
if @2 = 2 then
if @ONE > 0 then
@TWO ← @TWO - @ONE
if @TWO < 0 then
@THREE ← @THREE + @TWO.
@TWO ← 0
if @THREE < 0 then
@FOUR ← @FOUR + @THREE.
@THREE ← 0
if @FOUR < 0 then
@FIVE ← @FIVE + @FOUR.
@FOUR ← 0
if @FIVE < 0 then
@SIX ← @SIX+@FIVE.
@FIVE ← 0
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX.
@SIX ← 0
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@TWO+@THREE+@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@TWO+@THREE+@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
end
end
end
end
end
elif @2=3 then
if @ONE > 0 then
@THREE ← @THREE - @ONE
if @THREE < 0 then
@FOUR ← @FOUR + @THREE.
@THREE ← 0
if @FOUR < 0 then
@FIVE ← @FIVE + @FOUR.
@FOUR ← 0
if @FIVE < 0 then
@SIX ← @SIX+@FIVE.
@FIVE ← 0
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX.
@SIX ← 0
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@THREE+@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@THREE+@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
end
end
end
end
elif @2=4 then
if @ONE > 0 then
@FOUR ← @FOUR - @ONE
if @FOUR < 0 then
@FIVE ← @FIVE + @FOUR.
@FOUR ← 0
if @FIVE < 0 then
@SIX ← @SIX+@FIVE.
@FIVE ← 0
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX.
@SIX ← 0
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@FOUR+@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
end
end
end
elif @2=5 then
if @ONE > 0 then
@FIVE ← @FIVE - @ONE
if @FIVE < 0 then
@SIX ← @SIX+@FIVE.
@FIVE ← 0
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX.
@SIX ← 0
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@FIVE+@SIX+@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
end
end
elif @2=6 then
if @ONE > 0 then
@SIX ← @SIX - @ONE
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX.
@SIX ← 0
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@SIX+@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@SIX+@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
end
elif @2=7 then
if @ONE > 0 then
@SEVEN ← @SEVEN - @ONE
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN.
@SEVEN ← 0
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@SEVEN+@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@SEVEN+@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
end
elif @2=8 then
if @ONE > 0 then
@EIGHT ← @EIGHT - @ONE
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT.
@EIGHT ← 0
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@EIGHT+@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@EIGHT+@NINE+(@TENx2))+"successes"
end
end
end
end
elif @2=9 then
if @ONE > 0 then
@NINE ← @NINE - @ONE
if @NINE < 0 then
@TEN ←@TEN + @NINE.
@NINE ←0
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@NINE+@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@NINE+(@TENx2))+"successes"
end
end
end
else
if @ONE > 0 then
@TEN ← @TEN - @ONE
if @TEN <0 then
"\-\-Botch by"+ABS(@TEN)
elif (@TEN)=0 then
"\-\-Fail"
else
"\-\-"-(@TEN)+"successes"
end
end
end.
if @TRIPLE=1 then
"\nTriple Sevens!"
else
0
end

#1 is defined as a positive number called "Number of Dice" and #2 is defined as a positive number called "Target".

When I run the program, I get a result of 0 every time. I have verified the variables are being loaded correctly, although for some reason the first time it is run, @TRIPLE isn't loaded correctly.

Can anyone tell me what I'm doing wrong, or suggest a better way of doing this?

Thanks,

Lord Flame Stryke

Posted with gandreas software's Web Boarder

LordFlameStryke
Posts: 13
Joined: Wed Nov 25, 2009 9:06 pm
IQ Test: Orange

Re: Can anyone help me with a complex formula?

Post by LordFlameStryke » Fri Jan 24, 2014 2:32 pm

Never mind, I figured out the problem -- I was forgetting to complete the "if - else - end" statements.

If anyone is interested, here is my (much cleaner) code:

@1 ← #1 d10 @ .
@2 ← #2 .
@ONE ← count1( @1 ) .
@TWO ← count2( @1 ) .
@THREE ← count3( @1 ) .
@FOUR ← count4( @1 ) .
@FIVE ← count5( @1 ) .
@SIX ← count6( @1 ) .
@SEVEN ← count7( @1 ) .
@EIGHT ← count8( @1 ) .
@NINE ← count9( @1 ) .
@TEN ← count10( @1 ) .
if @2 ≥ 3 then
@TWO ← 0
else
0
end .
if @2 ≥ 4 then
@THREE ← 0
else
0
end .
if @2 ≥ 5 then
@FOUR ← 0
else
0
end .
if @2 ≥ 6 then
@FIVE ← 0
else
0
end .
if @2 ≥ 7 then
@SIX ← 0
else
0
end .
if @2 ≥ 8 then
@SEVEN ← 0
else
0
end .
if @2 ≥ 9 then
@EIGHT ← 0
else
0
end .
if @2 = 10 then
@NINE ← 0
else
0
end .
if @ONE > 0 then
@TWO ← @TWO - @ONE
else
0
end .
if @TWO < 0 then
@THREE ← @THREE + @TWO .
@TWO ← 0
else
0
end .
if @THREE < 0 then
@FOUR ← @FOUR + @THREE .
@THREE ← 0
else
0
end .
if @FOUR < 0 then
@FIVE ← @FIVE + @FOUR .
@FOUR ← 0
else
0
end .
if @FIVE < 0 then
@SIX ← @SIX + @FIVE .
@FIVE ← 0
else
0
end .
if @SIX < 0 then
@SEVEN ← @SEVEN + @SIX .
@SIX ← 0
else
0
end .
if @SEVEN < 0 then
@EIGHT ← @EIGHT + @SEVEN .
@SEVEN ← 0
else
0
end .
if @EIGHT < 0 then
@NINE ← @NINE + @EIGHT .
@EIGHT ← 0
else
0
end .
if @NINE < 0 then
@TEN ← @TEN + @NINE .
@NINE ← 0
else
0
end .
@TOTAL ← @TWO + @THREE + @FOUR + @FIVE + @SIX + @SEVEN + @EIGHT + @NINE + @TEN .
@TOTAL10 ← @TOTAL + @TEN .
if @TOTAL < 0 then
“\-\-Botch by” + abs( @TEN )
elif @TOTAL = 0 then
“\-\-Fail”
else
if @2 < 10 then
“\-\-” - @TOTAL10
else
“\-\-” - @TOTAL
end
end

I had written the code in Notepad, as the Dicenomicon editor cries when I use something this large. This is why I initially forgot the complete functions.

This version runs well, and was copied directly from the Dicenomicon editor. Feel free to copy it for your own use. #1 is still a positive integer labelled "Number of Dice", and #2 is still a positive integer labelled "Target". If you put in a target less than 2 or greater than 10, it should still operate as if it was minimum 2 and maximum 10, although I admit I haven't tried this so I'm not 100% certain.

Posted with gandreas software's Web Boarder

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests