-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanet.elm
More file actions
58 lines (52 loc) · 1.28 KB
/
Copy pathPlanet.elm
File metadata and controls
58 lines (52 loc) · 1.28 KB
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
module Planet exposing (Planet, testPlanet, step)
type alias Planet =
{ resources : Float
, food : Float
, foodGrowth : Float
, population : Float
, technology :
Float
-- Between 0.0 and 1.0
, pollution :
Float
-- Between 0.0 and 1.0
, name : String
, age : Int
}
testPlanet : Planet
testPlanet =
{ resources = 10000
, food = 500
, foodGrowth = 500
, population = 100
, technology = 0
, pollution = 0
, name = "Testopia"
, age = 0
}
step : Planet -> Planet
step planet =
{ planet
| resources =
planet.resources
- (planet.population * (0.1 + planet.technology))
|> max 0
, food =
planet.food
- planet.population
+ (planet.foodGrowth * (1 - planet.pollution))
|> max 0
, population =
planet.population
* 1.01
|> max 0
, technology =
if planet.technology == 0 then
(planet.population / 100000)
else
planet.technology
* (1 + (planet.population / 100000))
, pollution =
planet.technology
, age = planet.age + 1
}