Let’s Make Cellular Automata

Your cells live on a grid with a fixed Height and Width. You’ll need to know which cells are Alive, and you’ll want to Update them together, so make a World class to hold your grid and Update your cells:

 class​ World
  World(​size_t​ max_x, ​size_t​ max_y, ​bool​ wrap);
  World(​size_t​ max_x, ​size_t​ max_y, ​bool​ wrap,
 size_t​ start_width, ​size_t​ start_height,
 size_t​ number);
 size_t​ Width() ​const​ { ​return​ max_x; }
 size_t​ Height() ​const​ { ​return​ max_y; }
 size_t​ Alive() ​const​;
 bool​ Alive(​size_t​ x, ​size_t​ y) ​const
 return​ state[y*max_x + x];
 void​ Spark(​size_t​ x, ​size_t​ y)
 throw​ std::invalid_argument(​ ...

Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.