-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameoflife.h
90 lines (74 loc) · 2.34 KB
/
gameoflife.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef GAMEOFLIFE_H
#define GAMEOFLIFE_H
#include "cell.h"
#include <iostream>
#include <fstream>
#include <random>
using namespace std;
class GameOfLife
{
/*!
* @brief Allocates space for nextGeneration and currentGeneration
* @param dimensions: number of rows and columns
* @returns pointer to array of Cells
*/
Cell **get_dynamic_array(const pair<int, int> dimensions);
/*!
* @brief Copies nextGeneration to currentGeneration after evolution has finished
*/
void set_current();
/*!
* @brief Extracts field dimensions from first to lines of import file
* @param filename: input file that contains the state to import
* @returns number of rows and columns
*/
pair<int,int> get_dimensions(const string filename);
/*!
* @brief Convert field to string for printing/writing to file
* @returns String representation of field in rows and columns (Matrix)
*/
string current_to_string();
/*!
* @brief Count living neighbors of a particular cell on the field
* @param cell: the cell of interest
* @returns number of living neighbors
*/
int count_living(Cell cell);
Cell **nextGeneration; // container for evolved cells
public:
// Constructor
GameOfLife();
bool is_running;
int nrows, ncols; // field dimensions
Cell **currentGeneration; // container for current state
/*!
* @brief Fill currentGeneration with random cells
*/
void get_random_field();
/*!
* @brief Change nrows and ncols and re-allocate space for currentGeneration and nextGeneration
*/
void change_dimensions(const pair<int, int> dimensions);
/*!
* @brief State import and export
* @param filename: file that contains state to import
* @param outfile: file to export current state to
*/
void import_state(const string filename);
void write_to_file(string outfile);
/*!
* @brief Print string representation of field to console
* @see GameOfLife::current_to_string()
*/
void print_current();
/*!
* @brief Generate the next generation of the field by evolving each cell
* @see Cell::evolve()
*/
void evolve();
/*!
* @brief Utility function to safely convert user input to integer
*/
static int to_stoi(string input);
};
#endif // GAMEOFLIFE_H