January 2019
Intermediate to advanced
236 pages
5h 41m
English
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 |
| | { |
| | public: |
| | 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) |
| | { |
| | if(Alive(x,y)) |
| | throw std::invalid_argument( ... |
Read now
Unlock full access