|
@@ -95,6 +95,21 @@ enum Params : uint16_t {
|
|
|
VV = VVV,
|
|
VV = VVV,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+enum Error {
|
|
|
|
|
+ NoError, // No error
|
|
|
|
|
+ EliminationTrigger, // Elimination Trigger released
|
|
|
|
|
+ DataHunger, // Data Hunger (Bank 1 empty and executed)
|
|
|
|
|
+ DivisionByZero, // Division by zero
|
|
|
|
|
+ InvalidBankNumber, // Invalid bank number (e.g. in TRANS or BJUMP)
|
|
|
|
|
+ HigherInstructionSetRequired, // Higher Instruction Set required
|
|
|
|
|
+ MobilityRequired, // Mobility required
|
|
|
|
|
+ DieExecuted, // DIE executed
|
|
|
|
|
+ InvalidParameter , // Invalid parameter (e.g. CREATE x, -1, x)
|
|
|
|
|
+ Unemployment, // No more tasks left in a robot (Unemployment)
|
|
|
|
|
+ InstructionDurationTooHigh, // Instruction duration too high (i.e. > MaxInstrDur)
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
using Parameter = int32_t;
|
|
using Parameter = int32_t;
|
|
|
|
|
|
|
|
struct Instruction {
|
|
struct Instruction {
|
|
@@ -128,6 +143,7 @@ struct Task {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct Program {
|
|
struct Program {
|
|
|
|
|
+ Error error = NoError;
|
|
|
QColor color;
|
|
QColor color;
|
|
|
Position position;
|
|
Position position;
|
|
|
vector<Task> tasks;
|
|
vector<Task> tasks;
|
|
@@ -148,7 +164,7 @@ struct Field {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct Simulator {
|
|
struct Simulator {
|
|
|
- size_t cylcle = 0;
|
|
|
|
|
|
|
+ size_t cycle = 0;
|
|
|
vector<Program> programs;
|
|
vector<Program> programs;
|
|
|
size_t size = 0;
|
|
size_t size = 0;
|
|
|
|
|
|
|
@@ -186,6 +202,9 @@ struct Simulator {
|
|
|
bank->push_back(Instruction(TRANS, LL, 1, 1));
|
|
bank->push_back(Instruction(TRANS, LL, 1, 1));
|
|
|
bank->push_back(Instruction(RANDOM, VLL, 5, -5, 5));
|
|
bank->push_back(Instruction(RANDOM, VLL, 5, -5, 5));
|
|
|
bank->push_back(Instruction(TURN, V, 5));
|
|
bank->push_back(Instruction(TURN, V, 5));
|
|
|
|
|
+ bank->push_back(Instruction(ADD, VL, 6, 1));
|
|
|
|
|
+// bank->push_back(Instruction(IFG, VL, 6, 5));
|
|
|
|
|
+// bank->push_back(Instruction(DIE));
|
|
|
bank->push_back(Instruction(AJUMP, L, 0));
|
|
bank->push_back(Instruction(AJUMP, L, 0));
|
|
|
programs.back().banks[1] = bank;
|
|
programs.back().banks[1] = bank;
|
|
|
}
|
|
}
|
|
@@ -193,7 +212,7 @@ struct Simulator {
|
|
|
|
|
|
|
|
Program* findProgram(Position position) {
|
|
Program* findProgram(Position position) {
|
|
|
for(auto& program : programs) {
|
|
for(auto& program : programs) {
|
|
|
- if(program.position.x == position.x && program.position.y == position.y) {
|
|
|
|
|
|
|
+ if(program.position.x == position.x && program.position.y == position.y && program.error == NoError) {
|
|
|
return &program;
|
|
return &program;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -204,6 +223,10 @@ struct Simulator {
|
|
|
for (auto& program : programs) {
|
|
for (auto& program : programs) {
|
|
|
auto& taskIndex = program.taskIndex;
|
|
auto& taskIndex = program.taskIndex;
|
|
|
|
|
|
|
|
|
|
+ if(program.error != NoError) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(program.tasks.empty()) {
|
|
if(program.tasks.empty()) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -280,6 +303,12 @@ struct Simulator {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ case DIE: {
|
|
|
|
|
+ program.error = DieExecuted;
|
|
|
|
|
+ task.instIndex += 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case TRANS: {
|
|
case TRANS: {
|
|
|
auto remotePosition = calcPosition(program.position, task.direction, 1);
|
|
auto remotePosition = calcPosition(program.position, task.direction, 1);
|
|
|
auto remoteProgram = findProgram(remotePosition);
|
|
auto remoteProgram = findProgram(remotePosition);
|
|
@@ -433,7 +462,7 @@ struct Simulator {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- ++cylcle;
|
|
|
|
|
|
|
+ ++cycle;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|