1
1

program.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef CPROGRAM_H
  2. #define CPROGRAM_H
  3. #include <array>
  4. #include <vector>
  5. #include <memory>
  6. #include <climits>
  7. #include <stdint.h>
  8. #include <QColor>
  9. using namespace std;
  10. #include "instruction.h"
  11. enum Direction {
  12. Right,
  13. Down,
  14. Left,
  15. Up,
  16. };
  17. struct Position {
  18. int x = 0;
  19. int y = 0;
  20. Position()
  21. : x(0)
  22. , y(0)
  23. {}
  24. Position(int _x, int _y)
  25. : x(_x)
  26. , y(_y)
  27. {}
  28. Position(const Position& _pos)
  29. : x(_pos.x)
  30. , y(_pos.y)
  31. {}
  32. };
  33. struct Team {
  34. int32_t programCount = 0;
  35. int32_t id = 0;
  36. int32_t var = 0;
  37. QColor color = Qt::red;
  38. Team(QColor color)
  39. : programCount(0)
  40. , id(rand())
  41. , var(0)
  42. , color(color)
  43. {
  44. }
  45. };
  46. struct Bank {
  47. shared_ptr<Team> team;
  48. vector<Instruction> instructions;
  49. Bank(shared_ptr<Team> team, const vector<Instruction>& instructions)
  50. : team(team)
  51. , instructions(instructions)
  52. {
  53. }
  54. Bank(const Bank& bank)
  55. : team(bank.team)
  56. , instructions(bank.instructions)
  57. {
  58. }
  59. };
  60. using BankIndex = size_t;
  61. using InstIndex = size_t;
  62. using TaskIndex = size_t;
  63. struct Task {
  64. bool paused = false;
  65. Direction direction = Right;
  66. BankIndex bankIndex = 0;
  67. InstIndex instIndex = 0;
  68. int remainingCycles = 0;
  69. shared_ptr<Bank> execBank;
  70. int32_t a = 0;
  71. int32_t b = 0;
  72. int32_t c = 0;
  73. int32_t* var_a = nullptr;
  74. int32_t* var_b = nullptr;
  75. int32_t* var_c = nullptr;
  76. };
  77. struct Program {
  78. int active = 0;
  79. int instructionSet = 0;
  80. int mobile = 0;
  81. int creationCycle = 0;
  82. int generation = 0;
  83. Error error = NoError;
  84. shared_ptr<Team> team;
  85. Position position;
  86. vector<Task> tasks;
  87. TaskIndex taskIndex = 0;
  88. vector<shared_ptr<Bank>> banks;
  89. array<int32_t, 20> vars{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  90. Program(shared_ptr<Team> team, Direction direction, Position position, int32_t instructionSet, int32_t slotCount, int32_t mobile);
  91. };
  92. #endif // CPROGRAM_H