-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgol.go
55 lines (43 loc) · 784 Bytes
/
gol.go
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
package main
import "math/rand"
type Cell struct{
status bool
}
func (c Cell) IsAlive() bool{
return c.status
}
func (c *Cell) Die(){
c.status = false
}
func (c *Cell) Live(){
c.status = true
}
type Universe struct{
Space [10][10]Cell
}
type Statistics struct{
Alive int
Dead int
}
func (u Universe) Statistics() Statistics{
alive_count := 0
dead_count := 0
for i:=0; i < 10; i++{
for j:=0; j < 10; j++{
if u.Space[i][j].IsAlive() == true{
alive_count++
}else{
dead_count++
}
}
}
var stats = Statistics{ Alive: alive_count, Dead: dead_count }
return stats
}
func (u *Universe) BigBang(amount int){
for i := 1; i < amount; i++{
x := rand.Intn(9)
y := rand.Intn(9)
u.Space[x][y].Live()
}
}