Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws2021:code3
import numpy as np
import random
import turtle
 
# zustände:
# S - susceptible - ansteckungsfähig - grün
# I - infected - angesteckt - orange
# C - contagious - ansteckend - rot
# R - recovered - genesen - blau
 
 
class Agent(): # erstellt die KLasse fuer die Agenten
 
    def __init__(self, id, days = 0, condition = 'S', position = np.zeros(2)): # S = Susceptible (Anfangscondition)
        self.condition = condition
        self.days = days
        #self.position = position
        #self.speed = np.zeros(2)
        self.id = id
        self.ball = turtle.Turtle()
 
    #susceptible
    def isSusceptible(self):
        return self.condition == 'S'
 
    '''
    def walk(self, dt):
        self.speed += np.random.uniform(-1,1) # speedsvektor: Agent geht in zufällige Richtung
        self.position += self.speed*dt # ein Schritt im Zeitabschnitt dt '''
 
    # infected
    def setInfected(self):
        self.ball.color("orange")
        self.condition = "I"
        self.days = 1
 
    def isInfected(self):
        return self.condition == 'I'
 
    # contagious
    def setContagious(self):
        self.ball.color("red")
        self.condition = 'C'
        self.days = 800
 
    def isContagious(self):
        return self.condition == 'C'
 
 
    def setRecovered(self):
        self.ball.color("blue")
        self.condition = 'R'
        self.days = 0
 
    def isRecovered(self):
        return self.condition == 'R'
 
 
    def str(self):
        return("Agent Position: " + str(self.position) + ", Condition: " + str(self.condition))
ws2021/code3.txt · Zuletzt geändert: 2021/01/21 16:48 von n.gujejiani