-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
49 lines (41 loc) · 999 Bytes
/
model.go
File metadata and controls
49 lines (41 loc) · 999 Bytes
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
package main
import (
"time"
"github.com/google/uuid"
)
type Cell struct {
X, Y int
ID uuid.UUID
Value int
}
type Config struct {
Width, Height int
Sleep time.Duration
NumberOfGenerations int
}
//IsAlive returns true for active cell
func (c *Cell) IsAlive() bool {
return c.Value != 0
}
//NewNeighbourCell - returns new dummy cell to the given coordinates
func NewNeighbourCell(x int, y int) *Cell {
return &Cell{x, y, uuid.Nil, 0}
}
//NewCell - returns set of neighbouring cells to the given cell
func NewCell(x int, y int, active int) *Cell {
return &Cell{x, y, uuid.New(), active}
}
//DefineNeighbours -- returns []Cell definitions of locations of neighbours for the given cell
func (c *Cell) DefineNeighbours() []*Cell {
var neighbours []*Cell
for j := -1; j < 2; j++ {
for i := -1; i < 2; i++ {
if j == 0 && i == 0 {
//Exclude myself
continue
}
neighbours = append(neighbours, NewNeighbourCell(i, j))
}
}
return neighbours
}