Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws2021:klasse_agenten
import random
 
temp = 0.1
height = 100
width = 100
days = 5
 
class Agent():
 
    radius = 2
 
    def __init__(self, color = 'cornflowerblue'):
        '''
        sets color, position and speed of the Agent
        '''
        self.color = color
        self.day = 0
        self.xstartpos = random.uniform(0,width)
        self.ystartpos = random.uniform(0,height)
        self.xpos = self.xstartpos
        self.ypos = self.ystartpos
        self.xspeed = temp*random.uniform(-10,10)
        self.yspeed = temp*random.uniform(-10,10)
        self.xpos_list = []
        self.ypos_list = []
 
 
    def isSusceptible(self):
        '''
        check if the Agent is susceptible
        '''
        return self.color == 'cornflowerblue'
 
    def isInfected(self):
        '''
        check if the Agent is infected
        '''
        return self.color == 'red'
 
    def setExposed(self):
        '''
        update the condition of the Agent to exposed
        '''
        self.color = 'pink'
        self.day = 1
 
    def setInfected(self):
        '''
        update the condition of the Agent to infected
        '''
        self.color = 'red'
        self.day = 5 * days
 
    def setRecovered(self):
        '''
        update the condition of the Agent to recovered
        '''
        self.color = 'gray'
        self.day = 15 * days
 
 
    def move(self):
        '''
         move the Agent and check if position of the Agent is out of the frame, if so change the direction
        '''
        self.ypos += self.yspeed
        self.xpos += self.xspeed
 
        if self.xpos >= width or self.xpos <= 0:
            self.xspeed *= -1
        if self.ypos >= height or self.ypos <= 0:
            self.yspeed *= -1
ws2021/klasse_agenten.txt · Zuletzt geändert: 2021/04/13 11:23 von n.gujejiani