-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomaton.h
executable file
·56 lines (44 loc) · 1.49 KB
/
Automaton.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
//
// Automaton.h
// Automata_1D
//
// Created by Anand Venkataraman on 12/30/18.
// Copyright © 2018 Anand Venkataraman. All rights reserved.
//
#ifndef Automaton_h
#define Automaton_h
// ZyLab - Bitwise ops - 1D Cellular Automata
// Original - Prof. Loceff, Updates, Edits, Annotations: &
//
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
// This is a 1D automaton in which each child has three parent bits
// (8 possibilities). The rule can be any 8-bit number (0-255), in which
// each bit position n holds the value of the child whose parents have values
// given by the 3 bits of the binary rep of n.
//
// For extra credit, you can discuss in the forums how you might generalize
// this class to be agnostic to the number of bits in the parent (aka
// number of parents).
class Automaton {
private:
bool rules[8];
vector<int> thisGen;
int extremeBit; // implied everywhere "outside the interesting region"
int displayWidth; // an odd number so it can be perfectly centered
public:
static const int MAX_DISPLAY_WIDTH = 121;
static const int DEFAULT_DISPLAY_WIDTH = 79;
static const int MIN_RULE = 0;
static const int MAX_RULE = 255; // 2^(2^n)-1 where n = num parents.
Automaton(int rule);
bool setRule(int rule);
bool setDisplayWidth(int width);
void resetToFirstGen();
void propagateNewGen();
string toStringCurrentGen(char charFor0, char charFor1) const;
};
#endif /* Automaton_h */