Skip to content

Commit

Permalink
Refactor names
Browse files Browse the repository at this point in the history
  • Loading branch information
eloylp committed Nov 17, 2019
1 parent 4ff9e42 commit 9fb3cfe
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ func (b Board) NextGen() Board {
newBoard := Board{}
for y := 0; y < len(b); y++ {
for x := 0; x < len(b[x]); x++ {
newBoard[y][x] = b.NextCell(x, y)
newBoard[y][x] = b.NextGenCell(x, y)
}
}
return newBoard
}

var offsets = [8][2]int{
var neighbourOffsets = [8][2]int{
{+1, +1},
{+1, 0},
{+1, -1},
Expand All @@ -24,23 +24,27 @@ var offsets = [8][2]int{
{0, +1},
}

func (b Board) NextCell(x, y int) Cell {
c := 0
func (b Board) NextGenCell(x, y int) Cell {
neighbours := 0
currentCell := b[y][x]
for _, o := range offsets {
if CheckNeighbour(b, x, y, o[0], o[1]) {
c++
for _, o := range neighbourOffsets {
if Neighbour(b, x, y, o[0], o[1]) {
neighbours++
}
}
if !currentCell && c == 3 {
if !currentCell && neighbours == 3 {
return true
}
if currentCell && (c == 2 || c == 3) {
if currentCell && (neighbours == 2 || neighbours == 3) {
return true
}
return false
}

func main() {

}

func IsReachableNeighbour(board Board, x, y, ox, oy int) bool {
if y+oy > len(board)-1 || y+oy < 0 {
return false
Expand All @@ -51,12 +55,9 @@ func IsReachableNeighbour(board Board, x, y, ox, oy int) bool {
return true
}

func CheckNeighbour(board Board, x, y, ox, oy int) Cell {
func Neighbour(board Board, x, y, ox, oy int) Cell {
if !IsReachableNeighbour(board, x, y, ox, oy) {
return Cell(false)
}
return board[y+oy][x+ox]
}

func main() {
}

0 comments on commit 9fb3cfe

Please sign in to comment.