-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugs.ex
97 lines (66 loc) · 2.05 KB
/
bugs.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
include std/math.e
integer days = 60
sequence temperatures = {}
sequence bugsInGround = {}
sequence bugsOutside = {}
main()
function temperatureChange(integer range)
return rand(range)-(trunc(range/2)+1)
end function
function randomBug()
integer outTemp = rand(10)+5
integer hp = rand(4)
return {outTemp, hp}
end function
procedure createBugs(integer n)
for i=1 to n do
bugsInGround = append(bugsInGround,randomBug())
end for
end procedure
function bugTemperature(sequence bug)
return bug[1]
end function
procedure main()
createBugs(1000)
integer averageTemperature = -5
for i=1 to days do
integer temperature = averageTemperature+temperatureChange(5)
sequence newInGround = {}
integer count = 0
-- Robaki w ziemi
for j=1 to length(bugsInGround) do
sequence currentBug = bugsInGround[j]
-- Jeśli temperatura jest odpowiednia i robak ma szczęście
if temperature >= bugTemperature(currentBug) and rand(6) = 6 then
count += 1
bugsOutside = append(bugsOutside,currentBug)
else
newInGround = append(newInGround,currentBug)
end if
end for
bugsInGround = newInGround
integer dead = 0
sequence newOutside = {}
for j=1 to length(bugsOutside) do
if temperature < bugTemperature(bugsOutside[j]) then
bugsOutside[j][2] -= 1
end if
if bugsOutside[j][2] > 0 then
newOutside = append(newOutside,bugsOutside[j])
else
dead += 1
end if
end for
bugsOutside = newOutside
printf(1,"Dzień %d\n",i)
printf(1,"Temperatura %d\n",temperature)
printf(1,"Na zewnątrz wyszło %d robaków\n",count)
printf(1,"Zginęło %d robaków\n",dead)
temperatures = append(temperatures,temperature)
if remainder(i,3) = 0 then
averageTemperature += 1
end if
end for
printf(1,"W ziemi zostało %d robaków\n",length(bugsInGround))
printf(1,"Na zewnątrz jest %d robaków\n",length(bugsOutside))
end procedure