lifegametransition.cpp 801 Bytes
Newer Older
1
#include "lifegametransition.hpp"
Anthony Noir's avatar
Anthony Noir committed
2
3
#include "neighborhoodrule.hpp"

4
5
REGISTER_FACTORY_ENTRY(TransitionRule, LifeGameTransition, "Game of Life");

Anthony Noir's avatar
Anthony Noir committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
LifeGameTransition::LifeGameTransition()
{

}

bool LifeGameTransition::acceptFormat(const std::vector<NeighborhoodFormat>& formats) const {
    for(auto format = formats.begin(); format != formats.end(); ++format) {
        if(format->positions.size() != 8) {
            return false;
        }
    }
    return true;
}

20
21
22
23
24
25
26
27
28
29
30
31
32
unsigned int LifeGameTransition::getState(unsigned int state, const Neighborhood & neighborhood) const {
    unsigned int live = neighborhood.getNb(1);
    if (state == 0)
    {
        return live == 3 ? 1 : 0;
    }
    else
    {
        if (live == 2 || live == 3)
            return 1;
        else
            return 0;
    }
Anthony Noir's avatar
Anthony Noir committed
33
}