adapting to IntGrids
This commit is contained in:
parent
9e7e470498
commit
7d03482c4a
15
day18/day.go
15
day18/day.go
@ -4,20 +4,15 @@ import (
|
||||
"tools"
|
||||
)
|
||||
|
||||
type coord struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func play(grid tools.ToggleGrid, stuckCorners bool) {
|
||||
neighbours := make(map[coord]int)
|
||||
for thisCoord := range grid.GetOnCoordinates() {
|
||||
neighbours := tools.NewIntGrid()
|
||||
for thisCoord := range grid.GetCoordinates() {
|
||||
for cx := thisCoord.X - 1; cx <= thisCoord.X+1; cx++ {
|
||||
for cy := thisCoord.Y - 1; cy <= thisCoord.Y+1; cy++ {
|
||||
if cy == thisCoord.Y && cx == thisCoord.X {
|
||||
continue
|
||||
}
|
||||
neighbours[coord{cx, cy}]++
|
||||
neighbours.Add(cx, cy, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,12 +20,12 @@ func play(grid tools.ToggleGrid, stuckCorners bool) {
|
||||
for x := 0; x <= grid.MaxX; x++ {
|
||||
for y := 0; y <= grid.MaxY; y++ {
|
||||
if grid.State(x, y) {
|
||||
if neighbours[coord{x, y}] != 2 && neighbours[coord{x, y}] != 3 {
|
||||
if neighbours.Value(x, y) != 2 && neighbours.Value(x, y) != 3 {
|
||||
if !stuckCorners || !grid.IsCorner(x, y) {
|
||||
grid.Set(x, y, tools.Off)
|
||||
}
|
||||
}
|
||||
} else if neighbours[coord{x, y}] == 3 {
|
||||
} else if neighbours.Value(x, y) == 3 {
|
||||
grid.Set(x, y, tools.On)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user