60. The Game of Life

The class universe presented below implements the game as described. There are several functions of interest:

  • initialize() generates a starting layout; although the code accompanying the book contains more options, only two are listed here: random, which generates a random layout, and ten_cell_row, which represents a line of 10 cells in the middle of the grid.
  • reset() sets all the cells as dead.
  • count_neighbors() returns the number of alive neighbors. It uses a helper variadic function template count_alive(). Although this could be implemented with fold expressions, this is not yet supported in Visual C++ and therefore I have opted not to use it here.
  • next_generation() produces a new state of the game based on the transition ...

Get Modern C++: Efficient and Scalable Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.