114 lines
1.5 KiB
Go
114 lines
1.5 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
var (
|
|
activeRune = '#'
|
|
inactiveRune = '.'
|
|
)
|
|
|
|
type point3 [3]int
|
|
|
|
func addPoint(p1, p2 point3) point3 {
|
|
p := point3{}
|
|
for i := range p {
|
|
p[i] = p1[i] + p2[i]
|
|
}
|
|
|
|
return p
|
|
}
|
|
|
|
type cube struct {
|
|
loc point3
|
|
active bool
|
|
|
|
tock func() error
|
|
world *grid
|
|
}
|
|
|
|
func (c cube) neighbors() []cube {
|
|
directions := []point3{
|
|
// 1 pt
|
|
point3{0, 0, 1},
|
|
point3{0, 0, -1},
|
|
point3{0, 1, 0},
|
|
point3{0, -1, 0},
|
|
point3{1, 0, 0},
|
|
point3{-1, 0, 0},
|
|
// 2pt
|
|
point3{0, 1, 1},
|
|
point3{0, 1, -1},
|
|
point3{0, -1, 1},
|
|
point3{0, -1, -1},
|
|
point3{1, 1, 0},
|
|
point3{1, -1, 0},
|
|
point3{-1, 1, 0},
|
|
point3{-1, -1, 0},
|
|
point3{1, 0, 1},
|
|
point3{-1, 0, 1},
|
|
point3{1, 0, -1},
|
|
point3{-1, 0, -1},
|
|
// 3pt
|
|
point3{1, 1, 1},
|
|
point3{-1, 1, 1},
|
|
point3{1, -1, 1},
|
|
point3{1, 1, -1},
|
|
point3{-1, -1, 1},
|
|
point3{1, -1, -1},
|
|
point3{-1, 1, -1},
|
|
point3{-1, -1, -1},
|
|
}
|
|
}
|
|
|
|
func (c *cube) tick() error {
|
|
|
|
}
|
|
|
|
type world [][][]*cube
|
|
|
|
func (w world) getCube(p point) *cube {
|
|
x := point[0]
|
|
y := point[1]
|
|
z := point[2]
|
|
|
|
if z >= len(w) {
|
|
return nil
|
|
}
|
|
|
|
slice := world[z]
|
|
|
|
if y >= len(slice) {
|
|
return nil
|
|
}
|
|
|
|
row := slice[y]
|
|
|
|
if x >= len(row) {
|
|
return nil
|
|
}
|
|
|
|
return row[x]
|
|
}
|
|
|
|
func (w *world) tick() error {
|
|
for z, slice := range w {
|
|
for y, row := range slice {
|
|
for x, cube := range row {
|
|
err := cube.tick()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
p := point3{}
|
|
p[0] = 1
|
|
fmt.Println(p)
|
|
|
|
}
|