_TITLE "Steve's Simple Dice Roller"
QuickRoll 10, 2, 10, 0, 0, 0, 0
PrintResults
QuickRoll 2, 5, 6, 1, 0, 3, 0
PrintResults
INPUT "Dice to Roll =>"; d$
old$ = d$
RollDice d$
PrintResults
SUB QuickRoll
(S
, D
, N
, DM
, TM
, KH
, KL
)
Results(0, 0) = TM
Rolls
(i
- 1) = INT(RND * N
) + 1 + DM
'PRINT Rolls(i - 1), 'UNREMARK THIS LINE TO SEE UNSORTED NUMBERS
'PRINT 'AND THIS LINE TO SEE UNSORTED NUMBERS
'The dice sorting routine, optimized to use _MEM and a comb sort algorithm. It's more than fast enough for our needs here I think. ;)
IF D
> 1 THEN 'No need to try and sort only 1 dice.
gap = 10 * gap \ 13
i = 0
swapped = 0
o = m.OFFSET + i * 4
o1 = m.OFFSET + (i + gap) * 4
swapped = -1
i = i + 1
'FOR i = 1 TO d: PRINT Rolls(i - 1),: NEXT: PRINT 'UNREMARK THIS LINE TO SEE THE SORTED NUMBERS, BEFORE WE DISCARD LOW OR HIGH
IF KH
THEN 'drop the undesired low rolls IF KL
THEN 'drop the undesired high rolls Results(j, i) = Rolls(i - 1)
total = 0
total = total + Results(j, i)
total = total + Results(0, 0) 'Results 0,0 holds our total modifier
Results(j, 0) = total 'And store the total in the 0 element of the array
'First strip spaces if any
d$
= UCASE$(text$
) 'Then make it UCASE for ease of parsing
'Parse the text for the proper number and size dice to roll
l
= INSTR(d$
, "D") 'l is the location of the D which tells us how many dice to roll and what size MID$(d$
, l
) = "@" 'Replace the D with something else so we don't accept it as a scientific notation value l1
= INSTR(l
+ 1, d$
, "+") 'l1 is the location of the dice modifier (+/-), which is optional
l2
= INSTR(d$
, "S") 'l2 is the location of S, which is the number of sets of dice we want to roll
l3
= INSTR(d$
, "T") 'l3 is the location of the total modifier, if any IF l1
> l3
AND l3
<> 0 THEN l1
= 0 'In case we have a T-100 and not a +/- to the dice rolls first
l4
= INSTR(d$
, "KH") 'l4 tells us how many of the high rolls to keep IF l4
= 0 THEN l4
= -INSTR(d$
, "KL") 'or how many of the low rolls to keep
Results(0, 0) = tm
Rolls
(i
- 1) = INT(RND * n
) + 1 + dm
'PRINT Rolls(i - 1), 'UNREMARK THIS LINE TO SEE UNSORTED NUMBERS
'PRINT 'AND THIS LINE TO SEE UNSORTED NUMBERS
'The dice sorting routine, optimized to use _MEM and a comb sort algorithm. It's more than fast enough for our needs here I think. ;)
IF d
> 1 THEN 'No need to try and sort just one dice
gap = 10 * gap \ 13
i = 0
swapped = 0
o = m.OFFSET + i * 4
o1 = m.OFFSET + (i + gap) * 4
swapped = -1
i = i + 1
'FOR i = 1 TO d: PRINT Rolls(i - 1),: NEXT: PRINT 'UNREMARK THIS LINE TO SEE THE SORTED NUMBERS, BEFORE WE DISCARD LOW OR HIGH
IF kh
THEN 'drop the undesired low rolls IF kl
THEN 'drop the undesired high rolls Results(j, i) = Rolls(i - 1)
total = 0
total = total + Results(j, i)
total = total + Results(0, 0) 'Results 0,0 holds our total modifier
Results(j, 0) = total 'And store the total in the 0 element of the array
PRINT " = "; Results
(s
, 0)