-
Notifications
You must be signed in to change notification settings - Fork 0
/
automate.cpp
83 lines (65 loc) · 1.49 KB
/
automate.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "automate.h"
#include<cmath>
unsigned short Automate::getNumero() const
{
return numero;
}
std::string Automate::getNumeroBit() const
{
return numeroBit;
}
void Automate::appliquerTransition(const Etat &dep, Etat &dest) const
{
for(unsigned int i = 0; i < dep.getDimension(); i++){
int config_init = 0;
if(i != 0)
config_init += 4 * dep.getCellule(i-1);
config_init += 2 * dep.getCellule(i);
if(i < dep.getDimension() - 1)
config_init += 1 * dep.getCellule(i+1);
switch(config_init){
case 0:
dest.setCellule(i,(numero & 0b00000001) == 0b00000001);
break;
case 1:
dest.setCellule(i,(numero & 0b00000010) == 0b00000010);
break;
case 2:
dest.setCellule(i,(numero & 0b00000100) == 0b00000100);
break;
case 3:
dest.setCellule(i,(numero & 0b00001000) == 0b00001000);
break;
case 4:
dest.setCellule(i,(numero & 0b00010000) == 0b00010000);
break;
default:
dest.setCellule(i,(numero & 0b00100000) == 0b00100000);
break;
}
}
}
Automate::Automate()
{
}
Automate::Automate(unsigned short num) : numero(num)
{
numeroBit = std::bitset< 8 >( num ).to_string();
cout << numeroBit << endl;
}
Automate::Automate(string s) : numeroBit(s)
{
numero = 0;
numeroBit.at(0);
for(int i = 7, j = 0; i >= 0; i--, j++){
if(numeroBit.at(i)==49){
numero+=pow(2,j);
}
}
cout << "Automate : \n string : " << numeroBit << "\n numero : " << numero << endl;
}
ostream &operator<<(ostream &flux, Automate a)
{
flux << a.getNumeroBit();
return flux;
}