-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.h
79 lines (69 loc) · 2.42 KB
/
core.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
// © Copyright (c) 2018 SqYtCO
#ifndef CORE_H
#define CORE_H
#include "configuration.h"
#include "basesystem.h"
#include <memory>
// singleton class: to get the instance call Core::get_instance()
// this core contains all non-graphic and basic operations and manage cells
// the class is completely written in standard C++ (filesystem support required) and can also be used in a GUI-less application
class Core
{
// contain all non-graphic configurations
static Configuration config;
static std::unique_ptr<Base_System> system_;
static std::size_t generation;
public:
// create new game with set configuration
// if Configuration::start_random is true, the game board will be filled with random cells; the ratio is given by Configuration::relation_dead/Configuration::relation_alive
static void new_system();
// save current game to file
static bool save(const std::string& file);
// load given file; the file must contain a valid format (0=dead, 1=alive, \n=next_row, space=ignored); file must end on ".gol", otherwise false will be returned
static bool load(const std::string& file);
// update to next generation and calculate next states
static std::size_t next_generation(std::size_t generations = 1);
// calculate next states without updating cells
static void calc_next_generation(std::size_t generations = 1);
static std::size_t get_num_of_alive_cells();
static bool expand();
// set member
public:
// set one cell at given position to given state; the next state is not calculated; to do this call calc_next_generation()
static inline void set_cell_state(std::size_t x, std::size_t y, Cell_State state)
{
system_->set_cell(x, y, state);
}
// set all cells to given state; the next state is already calculated, no call of calc_next_generation() required
static inline void reset_cells(Cell_State state = Dead)
{
system_->set_all(state); generation = 0;
}
// get member
public:
static inline Configuration* get_config()
{
return &config;
}
static inline Cell_State get_cell_state(std::size_t x, std::size_t y)
{
return system_->get_cell_state(x, y);
}
static inline Cell_State get_next_cell_state(std::size_t x, std::size_t y)
{
return system_->get_next_cell_state(x, y);
}
static inline std::size_t get_size_x()
{
return system_->get_size_x();
}
static inline std::size_t get_size_y()
{
return system_->get_size_y();
}
static inline std::size_t get_generation()
{
return generation;
}
};
#endif // CORE_H