Conversation
| // iterate once and return a new State | ||
| func (s *State) iterate() *State { | ||
| next := New() | ||
| for z := s.min.z - 1; z <= s.max.z+1; z++ { |
| c := coord3D{x, y, z} | ||
| active := s.nextCellState(c) | ||
| if active { | ||
| next.Activate(x, y, z) |
There was a problem hiding this comment.
I find it awkward to sometimes need a coord3D object and sometimes need 3 coordinates.
Also, I'm not sure you'd lose the reader by getting rid of the active variable
| } | ||
|
|
||
| // nextCellState returns the activation (or dis- thereof) of a cell: it returns the next state of this cell | ||
| func (s *State) nextCellState(c coord3D) bool { |
There was a problem hiding this comment.
technically could be
| func (s *State) nextCellState(c coord3D) bool { | |
| func (s State) nextCellState(c coord3D) bool { |
I need to work on these more.
| return true | ||
| } | ||
| // If a cube is inactive but exactly 3 of its neighbours are active, the cube becomes active. Otherwise, the cube remains inactive. | ||
| return !isActive && activeNeighbours == 3 |
There was a problem hiding this comment.
my biased opinion is that these iffy ifs are a good case for a switch to a switch.
| // countNeighbours simply returns the number of active neighbours for a given cell | ||
| func (s *State) countNeighbours(c coord3D) int { | ||
| var activeNeighbours int | ||
| for x := c.x - 1; x <= c.x+1; x++ { |
There was a problem hiding this comment.
iterate loops the other way around
|
|
||
| // Activate sets the given cell to Active | ||
| func (s *State) Activate(x, y, z int) { | ||
| c := coord3D{x: x, y: y, z: z} |
There was a problem hiding this comment.
it's sad to see this object has already been created right before the call to this func in iterate()
| func (s *State) String() string { | ||
| str := "==== state ====" | ||
| for z := s.min.z - 1; z <= s.max.z+1; z++ { | ||
| str += fmt.Sprintln("\nz = ", z) |
| }{ | ||
| "one": { | ||
| activeCells: []coord3D{{1, 2, 3}}, | ||
| min: coord3D{0, 0, 0}, |
There was a problem hiding this comment.
Well. Technically not, but hey.
There was a problem hiding this comment.
you can turn them to pointers that get initialised on the first entry
| // iterate once and return a new State | ||
| func (s *State) iterate() *State { | ||
| next := New() | ||
| for w := s.min.w - 1; w <= s.max.w+1; w++ { |

No description provided.