Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws2021:code [2020/12/17 15:45] livia.mai angelegt |
ws2021:code [2021/02/03 18:32] (aktuell) sarah-j-28 |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | + | <code Python> | |
#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 29: | 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 59: | 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 96: | 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 102: | Zeile 100: | ||
- | #hier fehlt eine Bedingung, um das ineinanderstecken zu vermeiden? | + | # 0.9 = 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> |