示例#1
0
    def init_training_set(self):
        file = open("./resources/list.txt",'r')
        for linea in file.readlines():
            newCell=Cell(0,0,0,0,"TrainCell", linea)
            newCell.width=20
            newCell.height=20
            newCell.velX=random.randint(1,5)/5.0
            newCell.velY=random.random()
            type=None

            if linea[1]=="0":
                type="Target"
            elif linea[1]=="1":
                type="Enemy"
            elif linea[1]=="2":
                type="Food"

            if type=="Target":
                newCell.posX=random.randint(0,WINDOW_SIZE/3-newCell.width)
            elif type=="Enemy":
                newCell.posX=random.randint(WINDOW_SIZE/3,(WINDOW_SIZE/3)*2-newCell.width)
            elif type=="Food":
                newCell.posX=random.randint((WINDOW_SIZE/3)*2,WINDOW_SIZE-newCell.width)
            newCell.posY=random.randint(self.trainingZoneLimit,WINDOW_SIZE-newCell.height)

            self.trainingSet.append((newCell,type))
            
        file.close()
示例#2
0
文件: main.py 项目: tucif/BiokteriID3
    def update(self):
        self.queue_draw()
        
        cellsToPop=[]
        for cell in self.cells:
            cell.update(self.currentState)
            if cell.type=="NormalCell":
                if cell.posX+cell.width<0 or (cell.status=="Dead" and len(cell.dyingParticles)<=0):
                    cellsToPop.append(cell)
        for cell in cellsToPop:
            self.cells.pop(indexOf(self.cells,cell))
            if cell==self.virus[0].targetCell:
                self.virus[0].targetCell=None

        if self.currentState=="Running":
            self.ticksToNextCell-=1
            if self.ticksToNextCell<=0:
                self.ticksToNextCell=random.randint(self.minTimeToNextCell,self.maxTimeToNextCell)
                newCell=Cell(WINDOW_SIZE,
                    random.randint(0,TRAINING_ZONE_LIMIT-CELL_HEIGHT))
                newCell.velX=-random.random()*2
                newCell.type="NormalCell"
                self.cells.append(newCell)

            #update virus
            for virus in self.virus:
                if not virus.isDead:
                    virus.update(self.currentState)
                    if len(self.cells)>0 and virus.targetCell==None:
                        virus.targetCell=self.cells[len(self.cells)-1]
                        #This is a temprorary decision function
                        #Actual classification should do this
                        self.classify_cell(widget=None)
                        
                        

                if virus.is_colliding_with(virus.targetCell):
                    if not virus.targetCell.status:
                        if virus.status=="Attacking":
                            virus.targetCell.status="Dying"
                        if virus.status=="Eating":
                            virus.targetCell.status="BeingEaten"

                    if virus.targetCell.status=="Dead":
                        virus.targetCell=None

            for (cell,type) in self.trainingSet:
                for i in xrange(len(self.classificationList)):
                    if type==self.classificationList[i]:
                        rightLimit=self.divisionPoints[i]
                        if i==0:
                            leftLimit=0
                        else:
                            leftLimit=self.divisionPoints[i-1]
                        break
                            
                cell.update(self.currentState,[leftLimit,rightLimit-cell.width,TRAINING_ZONE_LIMIT,WINDOW_SIZE-cell.height])
示例#3
0
    def update(self):
        self.queue_draw()
        
        cellsToPop=[]
        for cell in self.cells:
            cell.update(self.currentState)
            if cell.posX+cell.width<0 or cell.isDead==True:
                cellsToPop.append(cell)
        for cell in cellsToPop:
            self.cells.pop(indexOf(self.cells,cell))
            for virus in self.virus:
                if cell==virus.targetCell:
                    virus.targetCell=None
                    break

        if self.currentState=="Running":
            if self.ticksToNextCell<=0:
                if len(self.cells)<MAX_CELLS:
                    self.ticksToNextCell=random.randint(self.minTimeToNextCell,self.maxTimeToNextCell)
                    newCell=Cell(WINDOW_SIZE,
                        random.randint(0,TRAINING_ZONE_LIMIT-CELL_HEIGHT))
                    newCell.velX=-(random.random()+3)
                    newCell.type="NormalCell"
                    self.cells.append(newCell)
            else:
                self.ticksToNextCell-=1

            #update virus
            for virus in self.virus:
                if not virus.isDead:
                    virus.update(self.currentState)
                    if len(self.cells)>0 and virus.targetCell==None and virus.status=="Waiting1":
                        for cell in self.cells:
                            if cell.isAvailable:
                                virus.targetCell=cell
                                cell.isAvailable=False
                                break
示例#4
0
    def update(self):
        self.queue_draw()
        
        cellsToPop=[]
        for cell in self.cells:
            cell.update(self.currentState)
            if cell.type=="NormalCell":                
                if(cell.status=="Dead" and len(cell.dyingParticles)<=0):
                    cellsToPop.append(cell)
        for cell in cellsToPop:
            self.cells.pop(indexOf(self.cells,cell))
            if cell==self.virus[0].targetCell:
                self.virus[0].targetCell=None

        if self.currentState=="Running":
            
            if self.ticksToNextCell<=0:                
                if len(self.cells)< MAX_CELLS:#self.currentCell < self.numCells:
                    
                    self.ticksToNextCell=random.randint(self.minTimeToNextCell,self.maxTimeToNextCell)

                    #print "NumCells", self.numCells
                    #print self.apareciendo
    #                print self.apareciendo[self.currentCell]
                    #print self.currentCell
                    
                    newCell=Cell(WINDOW_SIZE - CELL_WIDTH*2,
                        random.randint(0,self.trainingZoneLimit-CELL_HEIGHT), 0,0,"TrainCell", self.apareciendo[self.currentCell])
                    newCell.velX=-random.random()*2
                    newCell.type="NormalCell"
                    self.cells.append(newCell)
                    self.currentCell=(self.currentCell+1)%self.numCells
            else:
                self.ticksToNextCell-=1

            #update virus
            for virus in self.virus:
                if not virus.isDead:
                    virus.update(self.currentState)
                    if len(self.cells)>0 and virus.targetCell==None:
                        #virus.targetCell=self.cells[len(self.cells)-1]
                        for i in xrange(len(self.cells)):
                            idx = random.randint(0,len(self.cells)-1)
                            if self.cells[idx].hp > 0:
                                virus.targetCell = self.cells[idx]
                                break
                        if virus.targetCell:
                            current_state = self.qagent.update(virus.targetCell)
                            print "Current Action: ",
                            if current_state == "A":
                                virus.status="Attacking"
                            if current_state =="C":
                                virus.status="Eating"
                            if current_state =="D":
                                virus.status="Defending"
                                virus.targetCell.status = "defended"
                            if current_state =="X":
                                virus.isDead = True

                            print virus.status
                            print '-'*20

                            #virus.status="Defending"
                            #virus.targetCell.status = "defended"
                            #Hacer accion random
                            #aqui clasifica###################################################################
                        
                        
                

                if virus.is_colliding_with(virus.targetCell):
                    if not virus.targetCell.status:
                        if virus.status=="Attacking":
                            virus.targetCell.status="Dying"
                        if virus.status=="Eating":
                            virus.targetCell.status="BeingEaten"
                    if virus.targetCell.status=="Dead":
                        virus.targetCell=None
            leftLimit=0
            rightLimit=0
            for (cell,type) in self.trainingSet:
                for i in xrange(len(self.classificationList)):
                    if type==self.classificationList[i]:
                        rightLimit=self.divisionPoints[i]
                        if i==0:
                            leftLimit=0
                        else:
                            leftLimit=self.divisionPoints[i-1]
                        break
                            
                cell.update(self.currentState,[leftLimit,rightLimit-cell.width,600,WINDOW_SIZE-cell.height])