def main(): values=easygui.multenterbox("Display settings: ","",["Width","Height","Fullscreen","Sandbox","Tutorial"],["1366","766","Yes","No","No"]) consts.screenwidth=int(values[0]) consts.screenheight=int(values[1]) consts.Center.location=consts.Location1(consts.screenwidth,consts.screenheight) if values[3]!="No": consts.sandbox=True if values[4]!="No": if(easygui.msgbox("Tutorial starting", ok_button="Press 'p' to continiue with the tutorial")): pass consts.tutorial=True if values[2]!="Yes": screen = pygame.display.set_mode((consts.screenwidth, consts.screenheight)) else: screen = pygame.display.set_mode((consts.screenwidth, consts.screenheight),pygame.FULLSCREEN) consts.fs=True running = True #hi text="Empty" pygame.init() graphics.screen=screen graphics.clock = pygame.time.Clock() if consts.tutorial: graphics.tut() if not consts.sandbox: graphics.askBoard("menu") algoModule = algorithm.pyAlgorithm(consts.screenwidth,consts.screenheight,consts.lvl) else: graphics.sandbox() while running: algoModule.nextStep(text) running,text = graphics.drawBoard(algoModule.myCell, algoModule.cellList, algoModule.foodList,[algoModule.myEggs, algoModule.cellEggs])
def LoadSaveMenu(self): choice=None while choice not in ["Save and Quit","Resume"]: choice=graphics.askBoard("manual","Game Paused","Save and Quit","Resume") if choice=="Save and Quit": save_rawtext=save(self.myCell,self.cellList,self.foodList,self.myEggs,self.cellEggs) pygame.quit() filename=easygui.enterbox("Enter save name: ","","Save001") file_path = path.relpath("src/SAV/"+filename+".sav") file = open(file_path,"wb") file.write(save_rawtext) file.close() exit()
def chooseCell(self,newCell): newtext="new\n" oldtext="old\n" newatt,oldatt=newCell.getOldNewAtts(),self.father.getOldNewAtts() for i in range(0,len(newatt)): newtext+=newatt[i]+"\n" for i in range(0,len(oldatt)): oldtext+=oldatt[i]+"\n" choice=None while choice not in ["Old","New"]: choice=graphics.askBoard("manualAuto",newtext,"Old","New",oldtext) if choice=="Old": return False return True
def nextStep(self,text): if consts.godmode: self.myCell.lifeTimeLeft=self.myCell.lifeTime self.myCell.foodLeft=self.myCell.food if text!="Empty": consts.askingQuestion=False ##parse input self._counter+=1 ##change season if not consts.recording: if self._counter%(consts.framerate*60)==0: consts.season=(consts.season+1)%4 ##handle input inputlist=self.getInput() for item in inputlist: if (item=="Left" or item=="Right") and (("Left" in self.__kinput) or ("Right" in self.__kinput)): continue elif (item=="c" and ("c" in self.__kinput)): continue elif (item=="m" and ("m" in self.__kinput)): continue else: self.__kinput.append(item) for item in self.__kinput: if not consts.mouse_control: if item=="Left" or item=="OLeft": self.myCell.changeAngle(-1) if item=="Right" or item=="ORight": self.myCell.changeAngle(1) self.myCell.changeAngle(0) if "Up" in self.__kinput: self.myCell.move() ##handle food and life self.myCell.checkTarget() self.myCell.checkEat(self.foodList) self.myCell.consumeFood(self._counter) self.myCell.consumeLife(self._counter) self.myCell.consumeEggTime(self._counter) self.myCell.checkRIP() if self.myCell.timeToHurt!=0: self.myCell.timeToHurt-=1 input=[] for cell in self.cellList: input=AI.nextStep(self.myCell,self.cellList,self.foodList,cell) for item in input: if item=="OLeft": cell.changeAngle(-1) if item=="ORight": cell.changeAngle(1) if "Up" == item: cell.move() if "a" == item: if cell.timeToLayLeft==0 and cell.lastMother!=None: self.cellEggs.append(cell.layEgg()) cell.lastMother=None cell.target=None if "c" ==item: if cell.mode=="m": cell.mode="c" else: cell.mode="m" cell.checkEat(self.foodList) cell.consumeFood(self._counter) cell.consumeLife(self._counter) cell.consumeEggTime(self._counter) cell.checkTarget() cell.checkRIP() if cell.timeToHurt!=0: cell.timeToHurt-=1 if cell.dead: self.cellList.remove(cell) if "a" in inputlist: if self.myCell.timeToLayLeft==0 and self.myCell.lastMother!=None: self.myEggs.append(self.myCell.layEgg(True)) self.myCell.lastMother=None if "c" in inputlist: ##carnivore or mating if self.myCell.mode=='m': self.myCell.mode='c' else: self.myCell.mode='m' if "m" in inputlist: ##load/save menu self.LoadSaveMenu() ##check egg hatching for egg in self.cellEggs: egg.consumeHatch(self._counter) for egg in self.myEggs: egg.consumeHatch(self._counter) self.growCellEggs() self.growPlayerEggs() ##check for carnivore eating and mating allCells=[] noCollision=True for cell in self.cellList: allCells.append(cell) allCells.append(self.myCell) for cell in allCells: for otherCell in allCells: collision=math.sqrt(((cell.location.x-otherCell.location.x)**2)+((cell.location.y-otherCell.location.y)**2))<cell.rad+otherCell.rad if (cell.ID!=otherCell.ID) and (collision): ##not the same cell noCollision=False if cell.mode=='c': ##carnivore if otherCell.timeToHurt<=0: otherCell.timeToHurt=consts.framerate otherCell.lifeTimeLeft-=cell.strength if otherCell.lifeTimeLeft<=0: ##only eat if you killed him cell.foodLeft+=otherCell.foodLeft otherCell.lifeTimeLeft=0 otherCell.dead=True print str(cell.ID), "Ate", str(otherCell.ID) else: ##cant eat print str(cell.ID), "hurt", str(otherCell.ID), "but did not kill him." ##cell eat practicle if cell.lastCollision!=otherCell and otherCell.lastCollision!=cell: ##only if its not a false collision graphics.practicleList.append(classes.practicle(cell.location,(240,165,36),practicle_radius)) cell.lastCollision=otherCell if cell.mode=='m': ##mate if otherCell.mode=='m': ##mate too cell.lastMother=otherCell otherCell.lastMother=cell ##cell eat practicle if cell.lastCollision!=otherCell and otherCell.lastCollision!=cell: ##only if its not a false collision graphics.practicleList.append(classes.practicle(cell.location,(240,36,131),practicle_radius)) cell.lastCollision=otherCell if noCollision: ##the cell has not colided, reset the last collision cell.lastCollision=cell.ID+self._counter ##check if its phase 2 if consts.counter/consts.framerate>consts.timeUntilPhase2 and self.p2spaceLimiter.active==False: self.p2spaceLimiter.activate() self.p2spaceLimiter.grow() if self.p2spaceLimiter.active: completeCellList=[] for cell in self.cellList: completeCellList.append(cell) completeCellList.append(self.myCell) for cell in completeCellList: if not math.sqrt(((cell.location.x-self.p2spaceLimiter.loc.x)**2)+((cell.location.y-self.p2spaceLimiter.loc.y)**2))<cell.rad+self.p2spaceLimiter.radius: cell.lifeTimeLeft-=self.p2spaceLimiter.hurt graphics.practicleList.append(classes.practicle(cell.location,(255,0,0),7)) #grow more food """ 0-Summer 75% 1-Autumn 50% 2-winter 25% 3-spring 100% """ if consts.season==0: if self._counter%(consts.framerate/6)==0: self.putFood() elif consts.season==1: if self._counter%(consts.framerate/4)==0: self.putFood() elif consts.season==2: if self._counter%(consts.framerate/2)==0: self.putFood() elif consts.season==3: if self._counter%(consts.framerate/8)==0: self.putFood() consts.counter=self._counter self.__kinput=[] if self.myCell.dead: choice=None while choice!="Okay": choice = graphics.askBoard("Prompt","You have died :(\n\nYou lived " + str(consts.counter/consts.framerate)+" seconds.") pygame.event.post(pygame.event.Event(pygame.QUIT)) ##deduct practicle time if (self._counter%(consts.framerate*0.125)): for practicle in graphics.practicleList: if practicle.radius==1: graphics.practicleList.remove(practicle) else: practicle.radius-=1 import requests testdata="" if self._counter%30==0: for cell in self.cellList: #print cell.location.x #print cell.location.y testdata+=str(cell.location.x/float(consts.screenwidth)*100)+"@"+str(cell.location.y/float(consts.screenheight)*100)+"|"; r = requests.post("http://www.avuka.net/P_live.php", data={"cells":testdata})
def mutateCell(self,cell,Player=False): text="" # Lay,eggW,car,foodW,life,lifeW,speed,AI,vision,eggH,strength mutationscale=[5,10,1,10,10,10,1,1,50,1,5] mutchance=[40,50,25,50,50,50,40,30,50,50,50] mutgoodbad=[50,50,60,50,40,50,50,60,30,50,50] for i in xrange(0,len(cell.getOldNewAtts())-1): randchance=randint(0,100) if randchance<mutchance[i]: ##mutate attribute if randint(0,100)<mutgoodbad[i]: #bad or good mutation mutationscale[i]*=-1 if i==0: ##timeToLay+left cell.timeToLay+=mutationscale[i] if cell.timeToLay<=0: cell.timeToLay=5 if mutationscale[i]<0: text+=str(cell.ID)+" mutated Timetolay by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated Timetolay by "+str(mutationscale[i])+"\n" elif i==1: ##eggWithdraw cell.eggwithdraw+=mutationscale[i] if cell.eggwithdraw<=0: cell.eggwithdraw=10 if mutationscale[i]<0: text+=str(cell.ID)+" mutated eggWithdraw by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated eggWithdraw by "+str(mutationscale[i])+"\n" elif i==2: ##carnivore if mutationscale[i]<0: cell.carnivore=0 text+=str(cell.ID)+" mutated carnivore negative\n" else: cell.carnivore=1 text+=str(cell.ID)+" mutated carnivore positive\n" elif i==3: ##foodWithdraw cell.foodWithdraw+=mutationscale[i] if cell.foodWithdraw<=0: cell.foodWithdraw=10 if mutationscale[i]<0: text+=str(cell.ID)+" mutated foodWithdraw by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated foodWithdraw by "+str(mutationscale[i])+"\n" elif i==4: ##lifetime cell.lifeTime+=mutationscale[i] if cell.lifeTime<=0: cell.lifeTime=5 if mutationscale[i]<0: text+=str(cell.ID)+" mutated lifeTime by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated lifeTime by "+str(mutationscale[i])+"\n" elif i==5: ##lifetimeWithdraw cell.lifewithdraw+=mutationscale[i] if cell.lifewithdraw<=0: cell.lifewithdraw=10 if mutationscale[i]<0: text+=str(cell.ID)+" mutated lifetimeWithdraw by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated lifetimeWithdraw by "+str(mutationscale[i])+"\n" elif i==6: ##speed cell.speed += mutationscale[i] if cell.speed==5: cell.speed=4 if cell.speed== 0: cell.speed = 1 if mutationscale[i]<0: text+=str(cell.ID)+" mutated speed by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated speed by "+str(mutationscale[i])+"\n" elif i==7: ##AI cell.AI += mutationscale[i] if cell.AI == 5: cell.AI = 4 if cell.AI == -1: cell.AI = 0 if mutationscale[i]<0: text+=str(cell.ID)+" mutated AI by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated AI by "+str(mutationscale[i])+"\n" elif i==8: ##vision cell.vision+=mutationscale[i]%consts.bigger(consts.screenwidth,consts.screenheight) if cell.vision<=0: cell.vision=50 if mutationscale[i]<0: text+=str(cell.ID)+" mutated vision by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated vision by "+str(mutationscale[i])+"\n" elif i==9: ##eggHatchTime cell.eggHatchTime+=mutationscale[i] if cell.eggHatchTime<=0: cell.eggHatchTime=1 if mutationscale[i]<0: text+=str(cell.ID)+" mutated eggHatchTime by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated eggHatchTime by "+str(mutationscale[i])+"\n" elif i==10: ##strength cell.strength+=mutationscale[i] if cell.strength<=0: cell.strength=5 if mutationscale[i]<0: text+=str(cell.ID)+" mutated strength by "+str(mutationscale[i])+"\n" else: text+=str(cell.ID)+" mutated strength by "+str(mutationscale[i])+"\n" if Player: choice=None while choice!="Okay": choice=graphics.askBoard("Prompt",text) else: print text return cell
def mixPlayerCells(self,mother,father): choice=None while choice not in ["Manual","Auto"]: choice=graphics.askBoard("manual","Manual or Auto?","Manual","Auto") if choice=="Auto": return self.mixNormalCells(mother,father) else: ## manual mode attIgnoreList=[0,4,7,11,12,16,17,18,19] print "\n\n" print "mixing cells manual" newCell=baseCell(father) for i in xrange(0,len(father.getAtts())): if i in attIgnoreList: continue ##print colored("(1)","blue"), colored(father.getAtts()[i].ljust(25),"magenta"), ##print colored("(2)","blue"), colored(mother.getAtts()[i],"magenta") ##choice=raw_input() if i!=6: fathertext=father.getAtts()[i] mothertext=mother.getAtts()[i] choice=None while choice not in [fathertext,mothertext]: choice=graphics.askBoard("manual","choose attribute",fathertext,mothertext) if i==1: ##timeToLay+left if choice==fathertext: newCell.timeToLay=father.timeToLay else: newCell.timeToLay=mother.timeToLay if i==2: ##eggWithdraw if choice==fathertext: newCell.eggwithdraw=father.eggwithdraw else: newCell.eggwithdraw=mother.eggwithdraw if i==3: ##carnivore if choice==fathertext: newCell.carnivore=father.carnivore else: newCell.carnivore=mother.carnivore if i==5: ##foodWithdraw if choice==fathertext: newCell.foodWithdraw=father.foodWithdraw else: newCell.foodWithdraw=mother.foodWithdraw if i==6: ##ID newCell.ID=algorithm.getNextID() if i==8: ##lifetime if choice==fathertext: newCell.lifeTime=father.lifeTime else: newCell.lifeTime=mother.lifeTime if i==9: ##lifetimeWithdraw if choice==fathertext: newCell.lifewithdraw=father.lifewithdraw else: newCell.lifewithdraw=mother.lifewithdraw if i==10: ##speed if choice==fathertext: newCell.speed=father.speed else: newCell.speed=mother.speed if i==13: ##ai if choice==fathertext: newCell.AI=father.AI else: newCell.AI=mother.AI if i==14: ##vision if choice==fathertext: newCell.vision=father.vision else: newCell.vision=mother.vision if i==15: ##eggHatchTime if choice==fathertext: newCell.eggHatchTime=father.eggHatchTime else: newCell.eggHatchTime=mother.eggHatchTime if i==20: ##strength if choice==fathertext: newCell.strength=father.strength else: newCell.strength=mother.strength return newCell