Benutzer-Werkzeuge

Webseiten-Werkzeuge


ws2021:code

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
ws2021:code [2020/12/17 15:51]
n.gujejiani
ws2021:code [2021/02/03 18:32] (aktuell)
sarah-j-28
Zeile 2: Zeile 2:
 #Bouncing Vall Simulator #Bouncing Vall Simulator
 import turtle import turtle
-import random  +import random 
-from erste_klasse ​import Agent+from klasse_agenten ​import Agent
  
-#ag1 = Agent() ​+#ag1 = Agent()
 #print(ag1) #print(ag1)
  
Zeile 28: Zeile 28:
  
  
-#balls = [] 
 agents = [] agents = []
  
 for _ in range(50): #​range(anzahl der bälle) for _ in range(50): #​range(anzahl der bälle)
     agents.append(Agent(_)) #create balls     agents.append(Agent(_)) #create balls
- 
-#colors = ["​red","​green","​black"​] 
  
  
Zeile 58: Zeile 55:
         agent.ball.dx = random.randint(-1,​1)         agent.ball.dx = random.randint(-1,​1)
  
-    #ball.da = 1 
  
 agents[1].anstecken() #first ball will be colored red agents[1].anstecken() #first ball will be colored red
-ball_no ​=  [1] #numbers as the positions in the list of balls, which are colored red+infizierten ​=  [1] #numbers as the positions in the list of balls, which are colored red 
 +recovered = []
  
 while True: while True:
Zeile 95: Zeile 92:
             #check for a collision             #check for a collision
             if agents[i].ball.distance(agents[j].ball) < 20: # because each ball has 20 pixels width             if agents[i].ball.distance(agents[j].ball) < 20: # because each ball has 20 pixels width
 +
 +
  
                 #switch the behaviours of these two balls                 #switch the behaviours of these two balls
Zeile 101: Zeile 100:
  
  
-                #hier fehlt eine Bedingung, um das ineinanderstecken zu vermeiden?​ +                # 0.Wahrscheinlichkeit einer Infektion
-                ##neu random dx und dy definieren ? +
-                if agents[i].ball.dx ​== agents[j].ball.dx:​ +
-                    if agents[i].ball.dy == agents[j].ball.dy:​ +
-                        agents[i].ball.dx == random.randint(-1,​1) +
-                        agents[i].ball.dy == random.randint(-1,​1) +
-                        agents[j].ball.dx == random.randint(-1,​1) +
-                        agents[j].ball.dy == random.randint(-1,​1)+
  
 +                if i in infizierten and j not in recovered and random.random()<​0.9:​
 +                    agents[j].anstecken()
 +                    if j not in infizierten:​
 +                        infizierten.append(j)
  
-                if i in ball_no: 
-                    agents[j].ball.color("​red"​) 
-                    if j not in ball_no: 
-                        ball_no.append(j) 
-                if j in ball_no: 
-                    agents[i].ball.color("​red"​) 
-                    if i not in ball_no: 
-                        ball_no.append(i) 
  
 +                if j in infizierten and i not in recovered and random.random()<​0.9:​
 +                    agents[i].anstecken()
 +                    if i not in infizierten:​
 +                        infizierten.append(i)
  
 +                for k in range(0,​len(agents)):​
 +                    if agents[k].tage >= 1 and agents[k].tage < 1000:
 +                        agents[k].tage += 1
 +                    if agents[k].tage == 1000:
 +                        agents[k].recovered()
 +                        recovered.append(k)
 +                        infizierten.remove(k)
 wn.mainloop() wn.mainloop()
  
 # To fix: they get stuck together, maybe because they have similar behaviurs and go to the direction of each other over and over # To fix: they get stuck together, maybe because they have similar behaviurs and go to the direction of each other over and over
  
-<\code>+ 
 +</code>
ws2021/code.1608216707.txt.gz · Zuletzt geändert: 2020/12/17 15:51 von n.gujejiani