Skip to content

Conversation

@alienorlatour
Copy link
Owner

No description provided.

// 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++ {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting looks weird

c := coord3D{x, y, z}
active := s.nextCellState(c)
if active {
next.Activate(x, y, z)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link

@floppyzedolfin floppyzedolfin Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically could be

Suggested change
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
Copy link

@floppyzedolfin floppyzedolfin Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++ {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}{
"one": {
activeCells: []coord3D{{1, 2, 3}},
min: coord3D{0, 0, 0},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. Technically not, but hey.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++ {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants