Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<iostream>
- #include<unistd.h>
- #include"twodboolarray.hh"
- // Basisklassen
- class Regel
- {
- public:
- typedef TwoDBoolArray Daten;
- virtual void anwenden(Daten& daten) = 0;
- };
- class BoundaryCondition
- {
- public:
- typedef TwoDBoolArray Daten;
- virtual bool boundary(Daten& daten, int i, int j) = 0;
- };
- class TorusCondition : public BoundaryCondition
- {
- // Implementieren Sie hier eine Randbedingung, welche das
- // Gebiet als doppelt periodisch annimmt.
- };
- class AliveCondition : public BoundaryCondition
- {
- // Implementieren Sie hier eine Randbedingung welche annimmt,
- // dass rund um das Rechengebiet lebende Zellen sitzen.
- };
- class DeadCondition : public BoundaryCondition
- {
- // Implementieren Sie hier eine Randbedingung welche annimmt,
- // dass rund um das Rechengebiet tote Zellen sitzen.
- };
- class GameOfLifeRules : public Regel
- {
- public:
- typedef TwoDBoolArray Daten;
- GameOfLifeRules(BoundaryCondition& _bc) : bc(_bc) {}
- // Implementieren Sie hier die Regeln des Game of Life
- private:
- BoundaryCondition& bc;
- };
- // Ein zellulärer Automat, der Regeln und Datenstrukturen von außen bekommt
- class Automat
- {
- public:
- typedef TwoDBoolArray Daten;
- Automat(Daten& daten, Regel& regel) : _daten(daten), _regel(regel)
- {}
- // mache n Schritte
- void step(int n=1)
- {
- for (int i=0; i<n; ++i)
- {
- // Linux-spezifische Art und Weise den Inhalt der Konsole zu löschen
- // und den Cursor nach oben links zu setzen.
- std::cout << "\x1B[2J\x1B[H" << "Step " << i << std::endl << _daten;
- // Das Wiedergeben der Lösung soll immer 10 Sekunden (=1e7 Mikrosekunden)
- // dauern. Sie können diesen Wert auch ändern.
- usleep(1.e7/n);
- _regel.anwenden(_daten);
- }
- }
- private:
- Daten& _daten;
- Regel& _regel;
- };
- int main(int argc, char** argv)
- {
- if (argc != 2)
- {
- std::cout << "Usage: ./<progname> <txt-file>" << std::endl;
- return 1;
- }
- // Initialisiere die Datenstruktur
- TwoDBoolArray a;
- std::ifstream file;
- file.open(argv[1]);
- if (file.good())
- file >> a;
- else
- {
- std::cout << "Cannot read file" << std::endl;
- return 1;
- }
- // Wähle Randbedingung
- TorusCondition bc;
- // Wähle ein Regelsystem
- GameOfLifeRules rules(bc);
- // Initialisiere den zellulären Automaten
- Automat automat(a,rules);
- // Experimentieren Sie hier mit Ihrem Automaten.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement