Repository navigation
Expand file tree
/
Copy pathcommand.cpp
More file actions
61 lines (55 loc) · 1.33 KB
/
Copy pathcommand.cpp
File metadata and controls
61 lines (55 loc) · 1.33 KB
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
#include "command.h"
namespace Turing {
Command::Command() {
state = 0;
conditions.append(QChar('a'));
destination = -1;
changes.append(QChar('a'));
direction = 0;
}
Command::Command(int tapes) {
state = 0;
for (int i = 0; i < tapes; i++) {
conditions.append(QChar('a'));
changes.append(QChar('a'));
}
destination = -1;
direction = 0;
}
Command::Command(int state, int destination, char direction, QList<QChar> conditions, QList<QChar> changes) {
this->state = state;
this->conditions = conditions;
this->destination = destination;
this->changes = changes;
if (direction >= -1 && direction <= 1)
this->direction = direction;
else
this->direction = 0;
}
QString Command::asString() {
QString str = "Q";
str += QString::number(state) + ',';
for (int i = 0; i < conditions.count() - 1; i++)
str += conditions.at(i) + '/';
if (conditions.count() > 0)
str += conditions.at(conditions.count() - 1);
str += " → Q";
if (destination == -1)
str += 'z';
else
str += QString::number(destination);
str += ',';
for (int i = 0; i < changes.count() - 1; i++)
str += changes.at(i) + '/';
if (changes.count() > 0)
str += changes.at(changes.count() - 1);
str += ',';
if (direction == 0)
str += 'S';
else if (direction > 0)
str += 'R';
else
str += 'L';
return str;
}
}