-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/2020/dec17 #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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++ { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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++ { |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

No description provided.