示例#1
0
 def run(self, seed):
     cList = []
     self.seed = seed
     self.config = AutoConfig.generate( self.seed )
     # * Initialize limits
     timeCount = 1000
     cCount = 1000
     cMax = 10000
     scaleSize = 100
     currentYear = 0
     # * Generate cs
     i = 0
     while i < cCount:
         newc = Creature.createFromGen([
             RandomEx.r.randomInt(0, scaleSize), RandomEx.r.randomInt(0, scaleSize),
             RandomEx.r.randomInt(0, scaleSize), RandomEx.r.randomInt(0, scaleSize),
             RandomEx.r.randomInt(0, scaleSize), RandomEx.r.randomInt(0, scaleSize),
             RandomEx.r.randomInt(0, scaleSize), RandomEx.r.randomInt(0, scaleSize) ], self.config)
         cList += [ newc ]
         i += 1
     # * Run simulation
     for i in range(0, timeCount):
         # {} Loop through cs
         for c in cList:
             # ? Check whether the unit is still alive
             if c.isAlive == False:
                 continue
             # * Chance for an event!
             dice20 = RandomEx.r.randomInt( 1, 20 )
             # ? Chance for event or wandering
             if dice20 >= self.config.chance_of_0_19_event:
                 # * Get a random c B
                 B = cList[ RandomEx.r.randomInt( 0, len(cList) - 1) ]
                 # ? Chance for encounter or reproduce
                 if RandomEx.r.randomInt( 1, 20 ) > self.config.chance_of_0_19_encounter: # 50%
                     Creature.encounter(self.config, c, B)
                 else:
                     Creature.reproduce(self.config, c, B)
             else:
                 Creature.wandering(self.config, c)
             # * Time pass!
             Creature.timePass(self.config, c)
         # * Remove dead cs
         cList = [c for c in cList if c.isAlive == True ]
         # [] Debug outputs
         SystemPlus.consoleClear()
         SystemPlus.consolePrintL(str(i) + "|" + str(len(cList)))
         SystemPlus.consolePrintL(str(i) + "|" + str(len(cList)))
         SystemPlus.consolePrintL(str(i) + "|" + str(len(cList)))
         currentYear = i
         # [] Time to stop debugging
         if len(cList) < 10 or len(cList) > cMax:
             break
     # * A list of cs that still remain on the battle field.
     self.rlt_remainList = {}
     # [] Time to stop debugging
     SystemPlus.consoleClear()
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("")
     # * Set up the result set
     # {} Loop through remained ced
     for c in cList:
         # [] Output remained c's name and energy.
         SystemPlus.consolePrintL(c.name + "|" + str( c.energy ) + ", ")
         # ? Check if it's the same type of c.
         if c.name in self.rlt_remainList:
             # * Add them together, if it is.
             self.rlt_remainList[c.name].Add += c
         else:
             # * Create a new list if it's not
             self.rlt_remainList[c.name] = [ c ]
     # * Set up general result information
     self.rlt_endYear = currentYear
     self.rlt_creatureCount = len(cList)
     # [] Print the end year and total c count
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("")
     SystemPlus.consolePrintL("Year: " + str(self.rlt_endYear))
     SystemPlus.consolePrintL("Alive: " + str(self.rlt_creatureCount))
     # [] Print general creature types and counts.
     for key, value in self.rlt_remainList.items():
         SystemPlus.consolePrintL( str( key ) + "|" + str(len( value )) + ", " )
示例#2
0
 def consoleClear(self):
     self.outputBuffer.clear()
     SystemPlus.consoleClear()