Game.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef GAME_H
  2. #define GAME_H
  3. #include <array>
  4. #include "String.h"
  5. #include "Types.h"
  6. class Game final {
  7. public:
  8. enum FieldState {
  9. BLACK, WHITE, EMPTY
  10. };
  11. enum State {
  12. SELECTION, MOVE, ANOTHER_MOVE, REMOVE_SELECTION
  13. };
  14. Game();
  15. void reset(String& output);
  16. bool parse(const String& input, String& output);
  17. private:
  18. bool parseLocation(const String& input, int& x, int& y);
  19. void parseSelection(const String& input, String& output);
  20. void parseMove(const String& input, String& output);
  21. void parseAnotherMove(const String& input, String& output);
  22. void parseRemoveSelection(const String& input, String& output);
  23. void move(int fromX, int fromY, int toX, int toY);
  24. bool isDigit(char c) const;
  25. bool isInRange(int x, int y) const;
  26. void reset();
  27. void print(String& s) const;
  28. void printLine(String& s, int index) const;
  29. bool removeLine(int x, int y, int x2, int y2, FieldState remove);
  30. int getRank(int x, int y, int x2, int y2) const;
  31. bool areNeighbours(int x, int y, int x2, int y2) const;
  32. void botMove(String& output);
  33. void addLocation(int x, int y);
  34. bool isInQueue(int x, int y) const;
  35. bool canMoveActiveStoneTo(int dirX, int dirY, FieldState enemy) const;
  36. bool isAnotherTurnPossible(FieldState enemy) const;
  37. bool markHitSides(int x1, int y1, int x2, int y2, FieldState state);
  38. bool shouldEnd() const;
  39. FieldState fields[9][5];
  40. int activeX;
  41. int activeY;
  42. int directionX;
  43. int directionY;
  44. State state;
  45. struct Location {
  46. int x;
  47. int y;
  48. };
  49. std::array<Location, 20> lastLocations;
  50. uint lastLocation;
  51. Location hitA;
  52. Location hitB;
  53. };
  54. #endif