In the game are many playable and non-playable characters, the total number of which could be up to around 60 depending on the level. Each character has a dictionary named with his/her name which contains all the character's attributes. At the start of a turn, each character generates an initiative score which is the sum of the character's initiative attribute value plus a random dice (d10) roll. What I want is for the highest initiative scoring character to be ranked 1st, and the progressively lower scoring characters to be ranked 2nd, 3rd, 4th, etc. This will allow me to have the highest scoring character act first, the second highest scoring character act second etc. I have done a workaround for this but as you will see below if I am doing this for 30, 40, 50, 60 or more chacracter the code will be waay too big. I need to find a way to do the same thing in a more compact way. If anyone has any ideas or suggestions or could turn me on to some processes that would help sove this I would appreciate it greatly.
from random import randint ish_roll = (randint(1,10)) #roll for character Ishido ish_tot= Ishido['i'] + ish_roll kent_roll = (randint(1,10)) #roll for character Kentaro kent_tot= Kentaro['i'] + kent_roll while kent_tot == ish_tot: #reroll if same as Ishido kent_roll = (randint(1,10)) kent_tot= Kentaro['i'] + kent_roll arren_roll = (randint(1,10)) #roll for character Arren arren_tot= Arren['i'] + arren_roll while arren_tot == kent_tot or ish_tot: arren_roll = (randint(1,10)) arren_tot= Arren['i'] + arren_roll roths_roll = (randint(1,10)) #roll for character Roths roths_tot= Roths['i'] + roths_roll while roths_tot == arren_tot or kent_tot or ish_tot: roths_roll = (randint(1,10)) roths_tot= Roths['i'] + roths_roll brig_roll = (randint(1,10)) #roll for character Brigand brig_tot= Brigand['i'] + brig_roll while brig_tot == roths_tot or arren_tot or kent_tot or ish_tot: brig_roll = (randint(1,10)) brig_tot= Brigand['i'] + brig_roll #what follows is the part not practical for many game characters if kent_tot >= ish_tot: kent_rank = 1 ish_rank = 2 else: kent_rank = 2 ish_rank = 1 if arren_tot >= kent_tot and ish_tot: arren_rank = 1 kent_rank = kent_rank + 1 ish_rank = ish_rank + 1 elif arren_tot <= kent_tot and ish_tot: arren_rank = 3 #and so on, which for 40-60 game characters, or less even, will be an enormous amount of code
I need to be able to accomplish the same thing, more or less, without needing to create a monster amount of code as will occur at the end of my code snippet.
Any help? Thanks.