program.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. size_t x = 0;
  19. size_t y = 0;
  20. Position()
  21. : x(0)
  22. , y(0)
  23. {}
  24. Position(size_t _x, size_t _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. QColor color = Qt::red;
  35. Team(QColor color)
  36. : color(color)
  37. {
  38. }
  39. };
  40. struct Bank {
  41. shared_ptr<Team> team;
  42. vector<Instruction> instructions;
  43. Bank(shared_ptr<Team> team, const vector<Instruction>& instructions)
  44. : team(team)
  45. , instructions(instructions)
  46. {
  47. }
  48. Bank(const Bank& bank)
  49. : team(bank.team)
  50. , instructions(bank.instructions)
  51. {
  52. }
  53. };
  54. using BankIndex = size_t;
  55. using InstIndex = size_t;
  56. using TaskIndex = size_t;
  57. struct Task {
  58. bool paused = false;
  59. Direction direction = Right;
  60. BankIndex bankIndex = 0;
  61. InstIndex instIndex = 0;
  62. int remainingCycles = 0;
  63. shared_ptr<Bank> execBank;
  64. int32_t a = 0;
  65. int32_t b = 0;
  66. int32_t c = 0;
  67. int32_t* var_a = nullptr;
  68. int32_t* var_b = nullptr;
  69. int32_t* var_c = nullptr;
  70. };
  71. struct Program {
  72. int active = 0;
  73. int instructionSet = 0;
  74. int mobile = 0;
  75. int creationCycle = 0;
  76. int generation = 0;
  77. Error error = NoError;
  78. shared_ptr<Team> team;
  79. Position position;
  80. vector<Task> tasks;
  81. TaskIndex taskIndex = 0;
  82. vector<shared_ptr<Bank>> banks;
  83. 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}};
  84. Program(shared_ptr<Team> team, Direction direction, Position position, int32_t instructionSet, int32_t slotCount, int32_t mobile);
  85. };
  86. #endif // CPROGRAM_H