#Code for matching number of each symbol type, locking successes from random import randint ################################################################### #THIS SECTION IS TO BE ADJUSTED TO MATCH THE CHARACTER DESIRED##### #die pool is final 'character' selection of dice based upon weapon and abilities #the numbers refer to the die_type listed below (order of sequence does not matter) #base character would be one of each type [0,1,2,3,4,5] #Where the die type is 0=attack, 1=slashing, 2=piercing, 3=bludgeoning, 4=movement, 5=defence #eg. sword would be Sword: 1 attack, 2 slash, 1 pierce, 0 bludgeon, 1 move, 1 defence [0, 1, 1, 2, 4, 5] # monster/all attack die = [0,0,0,0,0,0] # sword = [0,1,1,2,4,5] or [0,1,1,1,4,5] or [0,1,1,0,0] die_pool = [1,0,0,0,0,5] #each type of die in the pool/hand #number of times each face/symbol must be rolled/locked (assuming 6 sided die here) eg [0,0,0,2,0,1] means two 4's and one 6 must be rolled #symbols[position in array]: 0 slashing, 1 bludgeoning, 2 piercing, 3 moving, 4 defence, 5 wildcard successval = [4,0,0,0,0,0] any_success_val = 4 #any type of success (not currently in use) ################################################################### """ new_values = raw_input("Enter new values? ") print new_values if new_values == "y": print"Enter the 6 dice types (eg. 0,1,1,2,0,0 for a swordsman)" print"Where the die type is 0=attack, 1=slashing, 2=piercing, 3=bludgeoning, 4=movement, 5=defence" die_pool = input("Dice types? ") print str(die_pool) print"Enter the number of successful matches needed in a turn for each of the 6 types of symbol (eg. 0,1,0,2,1,0) for 1 bludgeoning, 2 movement, 1 defence" print"Where 0=slashing, 1=bludgeoning, 2=piercing, 3=moving, 4=defence, 5=wildcard" successval = input("Matches required? ") print str(successval) """ initialdice = 6 #number of dice rolled numrolls = 3 #number of rolls allowed per turn num_tests = 500 #total number of turns to undertake full_success = 0 #total number of complete matches dice_rolled = 0 #total number of dice rolled in all trials symbol_name=['slashing ','bludgeoning','piercing ','movement ','defence ','wild '] #symbols: #0 slashing, 1 bludgeoning, 2 piercing, 3 moving, 4 defence, 5 wildcard #Symbols on die: Red: slashing (ssbpmd) Yellow: piercing (ppbsmd) Green: bludgeoning (bbpsmd) # Black: attack (bpsmdw) Pink: move (mmbpsd) Yellow: defence (ddbpsm) die_type = [[0 for x in range(6)] for x in range (6)] die_type[0] = [0,1,2,3,4,5] #attack #orig [0,1,2,3,4,5] die_type[1] = [0,0,1,2,3,5] #slashing #-def +wild #orig [0,0,1,2,3,4] #[0,1,2,3,4,5] no pierce and add wild card die_type[2] = [0,1,2,2,3,5] #piercing #-def +wild #orig [0,1,2,2,3,4] #[0,5,2,2,3,4] no bludgeon and add wild card die_type[3] = [0,1,1,2,3,5] #bludgeoning#-def +wild #orig [0,1,1,2,3,4] #[5,1,1,2,3,4] no slashing add wild card die_type[4] = [0,1,2,3,3,5] #movement #orig [0,1,2,3,3,4] #[0,1,2,3,3,5] no defence add wild card die_type[5] = [0,1,2,5,4,4] #defence #orig [0,1,2,3,4,4] #[0,1,2,5,4,4] no movement add wild card #hierarchy symbol > die_type > die_pool die_locked = [0,0,0,0,0,0] #1 when locked symbols_matched = [0,0,0,0,0,0] #counters keeping track of symbols that are rolled #die_type[die_pool[dice]][roll] print "Success required: " for i in range(0,initialdice): print symbol_name[i]+"\t\t\t\t\t\t "+str(i+1) + ": " +str(successval[i]) for i in range(0,initialdice): print "Die "+str(i)+" type: "+str(die_pool[i]) #counters #numdice = initialdice num_trials = 0 successes = 0 #code start #number of trials for iterations in range (0,num_tests): #numdice = initialdice success = [0 for x in range(initialdice)] die_locked = [0 for x in range(initialdice)] num_trials += 1 #print"_____________________________________" #print "Trial: " + str(iterations+1) #3 rolls (turns) for turns in range (0,numrolls): #print " Turn "+str(turns+1) + ", Number of dice " + str(initialdice) for dice in range (0, initialdice): #print " Die " +str(dice+1) + ":", if die_locked[dice] == 0: roll = randint(1,6) symbol = die_type[die_pool[dice]][roll-1] symbols_matched[symbol] += 1 dice_rolled += 1 #print str(roll) +", " + symbol_name[symbol]+" "+str(symbol) +"", if successval[symbol] > success[symbol]: die_locked[dice] = 1 success[symbol] +=1 #print "**match**", #else: #print "-, locked", #print"" match = 1 for i in range (0,initialdice): if success[i] != successval[i]: match = 0 if match == 1: full_success += 1 #print " ***** Successful match *****" print "Number of trials " + str(num_trials) print "Successes: " + str(float(full_success)/float(num_tests)) print "Total dice rolled: "+str(dice_rolled) for i in range (0,initialdice): #print "Symbol "+str(i)+" "+symbol_name[i]+": "+str(symbols_matched[i])+" =%.2f" % round((float(symbols_matched[i])/float(dice_rolled)),2) print "Symbol "+str(i)+" "+symbol_name[i]+": "+str(symbols_matched[i])+"="+str(float(symbols_matched[i])/float(dice_rolled))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question