-
Notifications
You must be signed in to change notification settings - Fork 0
/
blinker_oscillator.cpp
61 lines (50 loc) · 1.3 KB
/
blinker_oscillator.cpp
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
// Implements a blinker oscillator and steps 4 times
// blinker oscillators have a period of 2
#include "../single_include/gol/gol.hpp"
#include <iostream>
gol::Board board(10, 10);
// Prints the board and then updates with next step
void printAndStep() {
std::cout << "\n";
for(int i = 0; i < board.height(); i++) {
for(int j = 0; j < board.width(); j++) {
std::cout << board[i][j] << " ";
}
std::cout << "\n";
}
board.nextStep(); // Update with next step with rule_string B3/S23
}
int main() {
for(int i = 0; i < board.height(); i++) {
for(int j = 0; j < board.width(); j++) {
board[i][j] = false;
}
}
// Make blinker oscillator
board[2][2] = true;
board[2][3] = true;
board[2][4] = true;
for(int i = 0; i < 4; i++) {
printAndStep();
}
}
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 1 1 1 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 1 0 0 0 0 0 0
// 0 0 0 1 0 0 0 0 0 0
// 0 0 0 1 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0