Commit e072300b authored by Anthony Noir's avatar Anthony Noir
Browse files

Automaton

parent b7015db8
/**
\file automaton.hpp
\brief Automaton
Cette classe représente un automate cellulaire.
**/
#ifndef AUTOMATON_HPP
#define AUTOMATON_HPP
#include "neighborhoodrule.hpp"
#include "transitionrule.hpp"
#include "grid.h"
class Automaton {
private:
NeighborhoodRule* neighbourhoodRule;
TransitionRule* transitionRule;
Grid grid;
public:
Automaton(NeighborhoodRule*, TransitionRule*, const Grid& = Grid(0,0));
virtual ~Automaton();
//! \brief Fait avancer l'automate à l'état suivant
void runOnce();
const Grid& getGrid() const {return grid;}
void setGrid(const Grid& g) {grid = g;}
};
#endif // AUTOMATON_HPP
#include "automaton.hpp"
Automaton::Automaton(NeighborhoodRule* n, TransitionRule* t, const Grid& g) : neighbourhoodRule(n), transitionRule(t), grid(Grid(g)) {}
Automaton::~Automaton() {
delete neighbourhoodRule;
delete transitionRule;
}
void Automaton::runOnce() {
Grid tempGrid(grid);
for(int i=0; i<grid.get_rows(); ++i) {
for(int j=0; j<grid.get_col(); ++j) {
tempGrid.set_cell({i, j}, transitionRule->getState(grid.get_state({i,j}),neighbourhoodRule->getNeighborhood(grid, {i, j})));
}
}
neighbourhoodRule->step();
for(int i=0; i<grid.get_rows(); ++i) {
for(int j=0; j<grid.get_col(); ++j) {
grid = tempGrid;
}
}
}
......@@ -14,6 +14,7 @@ INCLUDEPATH += ../include
SOURCES += \
alphabet.cpp \
arbitraryneighborhoodrule.cpp \
automaton.cpp \
gridview.cpp \
main.cpp \
mooreNeighborhoodRule.cpp \
......@@ -29,6 +30,7 @@ SOURCES += \
structurelibraryview.cpp
HEADERS += \
../include/automaton.hpp \
../include/coord.hpp \
../include/neighborhoodrule.hpp \
../include/arbitraryneighborhoodrule.hpp \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment