-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.go
76 lines (71 loc) · 1.23 KB
/
board.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
type Scale struct {
B int
tileSize int
tileMargin int
}
var scales = map[string]Scale{
"macro": {
B: 50,
tileSize: 35,
tileMargin: 5,
},
"large": {
B: 100,
tileSize: 15,
tileMargin: 5,
},
"default": {
B: 200,
tileSize: 7,
tileMargin: 3,
},
"small": {
B: 333,
tileSize: 5,
tileMargin: 1,
},
"micro": {
B: 500,
tileSize: 3,
tileMargin: 1,
},
}
func initBoard() [][]int {
b := make([][]int, B)
for i := range b {
b[i] = make([]int, B)
for j := range b[i] {
b[i][j] = 0
}
}
return b
}
func getNeighbors(y int, x int) int {
neighbors := 0
for i := y - 1; i <= y+1; i++ {
for j := x - 1; j <= x+1; j++ {
neighbors += board[i][j]
}
}
neighbors -= board[y][x]
return neighbors
}
func evolve() [][]int {
nextGen := initBoard()
for i := 1; i < (B - 1); i++ {
for j := 1; j < (B - 1); j++ {
n := getNeighbors(i, j)
if (board[i][j] == 1) && (n < minNeighbors) {
nextGen[i][j] = 0
} else if (board[i][j] == 1) && (n > maxNeighbors) {
nextGen[i][j] = 0
} else if (board[i][j] == 0) && (n == spawnsNew) {
nextGen[i][j] = 1
} else {
nextGen[i][j] = board[i][j]
}
}
}
return nextGen
}