58 lines
1.1 KiB
C++
58 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "./Instruction.h"
|
|
#include "../Cell.h"
|
|
#include "../CelularEncoding.h"
|
|
|
|
namespace NeuralNetworks {
|
|
namespace ConstructiveAlgorithms {
|
|
namespace CelularEncoding {
|
|
namespace Instruction{
|
|
class End : public Instruction{
|
|
public:
|
|
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
|
cell.die();
|
|
}
|
|
|
|
virtual std::size_t numberOfNodes() const override {
|
|
return 0;
|
|
}
|
|
|
|
virtual std::string toString() const override {
|
|
return "End";
|
|
}
|
|
protected:
|
|
private:
|
|
};
|
|
|
|
class Rec : public Instruction{
|
|
public:
|
|
Rec(bool terminal = true) : _nodes(terminal ? 0 : 1) {
|
|
|
|
}
|
|
|
|
virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector<double> &) override {
|
|
if(cell.getLife()<=1) {
|
|
cell.setCodePointer(cell.getCodePointer()->c1);
|
|
cell.die();
|
|
}else {
|
|
cell.setLife(cell.getLife()-1);
|
|
cell.setCodePointer(encoding.getCodeStart());
|
|
}
|
|
}
|
|
|
|
virtual std::size_t numberOfNodes() const override {
|
|
return _nodes;
|
|
}
|
|
|
|
virtual std::string toString() const override {
|
|
return "Rec";
|
|
}
|
|
protected:
|
|
std::size_t _nodes;
|
|
private:
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} |