' Dice simulator for Warhammer - by Squigger, 25/04/1999 V2 ' This script was written to enable quick theoretical fiddling for ' "what if?" situations for Warhammer. As rolling lots of dice and ' accurately keeping track of the results from hitting to randomising ' to wounding to saving can be a bugger, especially with lots of dice, ' this is perfect. ' Yes you have to work out the chances of hitting and wounding ' youself (oh how difficult...). If that bothers you, perhaps you ' might like to write the appropriate code... ' It does both simulation of dice and statistical calculation - expect ' them to be slightly different. I have decided not to round up or ' down the statistical chances, that can give skewed and misleading ' results. The dice results are not given in decimal places - they ' never use fractions whereas the statistics do. ' If you are desperate for rounded off statsistical results, just ' change: ' statisticalhits = round((percentchancetohit * dicetoroll),2) ' in the statistical section to: ' statisticalhits = int(percentchancetohit * dicetoroll) ' do the same for all four statistical calculation lines. ' As you can run several copies of the script at once, by giving each ' simulation a different name you can effectively see how a single ' unit fares against different enemies in different situations, as ' long as you feed in the right information. For example, you could ' have three windows open, comparing how each component of a chariot ' fares against a volley of arrows (do not evaluate a goblin chariot, ' it is quite depressing :) Or you might choose to simulate several ' turns by feeding results from a previous run into a new one. For ' example, you can see how much better it is to have a character in a ' unit as opposed to by himself. Then you can see how the rest of ' his unit fares as compared to him (the selfish git ;). ' It's a simple little programme, but with great possibilities. windowtitle = "Dice simulator for Warhammer - by Squigger" hits = 0 ontarget = 0 wounds = 0 kills = 0 '********************* ' Get initial input windowname = inputbox ("What are do you wish to call this simulation?", windowtitle, "") yesno = msgbox ("Will these attacks / shots be randomised?", vbyesno + vbdefaultbutton2, windowtitle) dicetoroll = inputbox ("number of attacks / shots: ", windowtitle, 0) rolltohit = inputbox ("roll to hit: ", windowtitle, 0) if rolltohit = 0 then rolltohit = 10 tohit = 7 - rolltohit if yesno = vbyes then randomhit = csng(inputbox ("chance in 6 to hit target when randomised: ", windowtitle, 0)) rolltowound = inputbox ("roll to wound: ", windowtitle, 0) if rolltowound = 0 then rolltowound = 7 towound = 7 - rolltowound rolltosave = inputbox ("roll to save: ", windowtitle, 0) if rolltosave = 0 then rolltosave = 7 if rolltosave > 6 then rolltosave = 7 tosave = 7 - rolltosave '********************* ' Simulation ' seed the random number generator randomize ' first roll to hit ' enable working out of shooting which needs more than 6 to hit if (rolltohit > 6) and (rolltohit < 10) then tohit = 1 for d = 0 to dicetoroll -1 randomdice = round((6 * rnd),2) if randomdice <= tohit then hits = hits + 1 next firsthits = hits hits = 0 secondtohit = 10 - rolltohit for d = 0 to firsthits -1 randomdice = round((6 * rnd),2) if randomdice <= secondtohit then hits = hits + 1 next elseif rolltohit => 10 then ' 10 to hit, impossible hits = 0 else ' ordinary hits, 6 or less to hit for d = 0 to dicetoroll -1 randomdice = round((6 * rnd),2) if randomdice <= tohit then hits = hits + 1 next end if ' roll to randomise hits if necessary if yesno = vbyes then for d = 0 to hits -1 randomdice = round((6 * rnd),2) if randomdice <= randomhit then ontarget = ontarget + 1 next else ontarget = hits end if ' roll to wound for d = 0 to ontarget -1 randomdice = round((6 * rnd),2) if randomdice <= towound then wounds = wounds + 1 next ' roll saves for d = 0 to wounds -1 randomdice = round((6 * rnd),2) if randomdice > tosave then kills = kills + 1 next '********************* ' Statistical calculation ' enable working out of shooting which needs more than 6 to hit if (rolltohit > 6) and (rolltohit < 10) then tohit = 1 percentchancetohit = tohit / 6 statisticalhits = round((percentchancetohit * dicetoroll),2) firststatisticalhits = statisticalhits secondtohit = 10 - rolltohit percentchancetohit = secondtohit / 6 statisticalhits = round((percentchancetohit * firststatisticalhits),2) elseif rolltohit => 10 then ' 10 to hit, impossible statisticalhits = 0 else ' ordinary hits, 6 or less to hit percentchancetohit = tohit / 6 statisticalhits = round((percentchancetohit * dicetoroll),2) end if if yesno = vbyes then percentchanceontarget = randomhit / 6 statisticalontarget = round((percentchanceontarget * statisticalhits),2) else statisticalontarget = statisticalhits end if percentchancetowound = towound / 6 statisticalwounds = round((percentchancetowound * statisticalontarget),2) percentkills = (6 - tosave) / 6 statisticalkills = round((percentkills * statisticalwounds),2) '********************* ' Present results tabs = vbtab + vbtab resultline0 = windowname + chr(13) + chr(13) resultline1 = "Simulated" + tabs + "Statistical" + chr(13) if dicetoroll < 10 then resultline2 = cstr(dicetoroll) + " attacks" + tabs + cstr(dicetoroll) + " attacks" + chr(13) else resultline2 = cstr(dicetoroll) + " attacks" + vbtab + cstr(dicetoroll) + " attacks" + chr(13) end if resultline3 = cstr(hits) + " hits" + tabs + cstr(statisticalhits) + " hits" + chr(13) if yesno = vbyes then resultline3a = cstr(ontarget) + " on target" + vbtab + cstr(statisticalontarget) + " on target" + chr(13) else resultline3a = "" end if if wounds > 9 then resultline4 = cstr(wounds) + " wounds" + vbtab + cstr(statisticalwounds) + " wounds" + chr(13) else resultline4 = cstr(wounds) + " wounds" + tabs + cstr(statisticalwounds) + " wounds" + chr(13) end if resultline5 = cstr((wounds - kills)) + " saves" + tabs + cstr(statisticalwounds - statisticalkills) + " saves" + chr(13) resultline6 = cstr(kills) + " kills" + tabs + cstr(statisticalkills) + " kills" resultstring = resultline0 + resultline1 + resultline2 + resultline3 _ + resultline3a + resultline4 + resultline5 + resultline6 msgbox resultstring, vbokonly, windowtitle