MicroMouse Maze Library  3703225
Maze.h
[詳解]
1 
8 #pragma once
9 
10 #include <array>
11 #include <bitset>
12 #include <cmath> //< for std::log2
13 #include <cstdint> //< for uint8_t
14 #include <fstream> //< for std::ifstream
15 #include <iostream> //< for std::cout
16 #include <string>
17 #include <vector>
18 
19 /* debug profiling option */
20 #define MAZE_DEBUG_PROFILING 0
21 #if MAZE_DEBUG_PROFILING
22 #warning "this is debug mode!"
23 #include <chrono>
24 static int microseconds() {
25  return std::chrono::duration_cast<std::chrono::microseconds>(
26  std::chrono::steady_clock::now().time_since_epoch())
27  .count();
28 }
29 static int microseconds() __attribute__((unused));
30 #define MAZE_DEBUG_PROFILING_START(id) const auto t0_##id = microseconds();
31 #define MAZE_DEBUG_PROFILING_END(id) \
32  { \
33  const auto t1_##id = microseconds(); \
34  const auto dur = t1_##id - t0_##id; \
35  static auto dur_max = 0; \
36  if (dur > dur_max) { \
37  dur_max = dur; \
38  MAZE_LOGD << __func__ << "(" << #id << ")\t" << dur << " [us]" \
39  << std::endl; \
40  } \
41  }
42 #else
43 #define MAZE_DEBUG_PROFILING_START(id)
44 #define MAZE_DEBUG_PROFILING_END(id)
45 #endif
46 
47 /*
48  * 迷路のカラー表示切替
49  */
50 #ifdef MAZE_COLOR_DISABLED
51 #define C_RE ""
52 #define C_GR ""
53 #define C_YE ""
54 #define C_BL ""
55 #define C_MA ""
56 #define C_CY ""
57 #define C_NO ""
58 #else
59 #define C_RE "\e[31m"
60 #define C_GR "\e[32m"
61 #define C_YE "\e[33m"
62 #define C_BL "\e[34m"
63 #define C_MA "\e[35m"
64 #define C_CY "\e[36m"
65 #define C_NO "\e[0m"
66 #endif
67 
72 #ifndef MAZE_LOG_LEVEL
73 #define MAZE_LOG_LEVEL 4
74 #endif
75 #define MAZE_LOG_STREAM_BASE(s, l, c) \
76  (s << c "[" l "][" __FILE__ ":" << __LINE__ << "]" C_NO "\t")
77 #if MAZE_LOG_LEVEL >= 1
78 #define MAZE_LOGE MAZE_LOG_STREAM_BASE(std::cout, "E", C_RE)
79 #else
80 #define MAZE_LOGE std::ostream(0)
81 #endif
82 #if MAZE_LOG_LEVEL >= 2
83 #define MAZE_LOGW MAZE_LOG_STREAM_BASE(std::cout, "W", C_YE)
84 #else
85 #define MAZE_LOGW std::ostream(0)
86 #endif
87 #if MAZE_LOG_LEVEL >= 3
88 #define MAZE_LOGI MAZE_LOG_STREAM_BASE(std::cout, "I", C_GR)
89 #else
90 #define MAZE_LOGI std::ostream(0)
91 #endif
92 #if MAZE_LOG_LEVEL >= 4
93 #define MAZE_LOGD MAZE_LOG_STREAM_BASE(std::cout, "D", C_BL)
94 #else
95 #define MAZE_LOGD std::ostream(0)
96 #endif
97 
101 namespace MazeLib {
102 
106 static constexpr int MAZE_SIZE = 16;
110 static constexpr int MAZE_SIZE_BIT = std::ceil(std::log2(MAZE_SIZE));
114 static constexpr int MAZE_SIZE_MAX = std::pow(2, MAZE_SIZE_BIT);
115 
145 class Direction {
146  public:
150  enum AbsoluteDirection : int8_t {
159  };
163  enum RelativeDirection : int8_t {
172  };
178  static constexpr const int8_t Max = 8;
179 
180  public:
184  constexpr Direction(const AbsoluteDirection d = East) : d(d) {}
190  constexpr Direction(const int8_t d) : d(d & 7) {}
194  constexpr operator int8_t() const { return d; }
198  bool isAlong() const { return !(d & 1); }
202  bool isDiag() const { return (d & 1); }
206  char toChar() const { return ">'^`<,v.X"[d]; }
210  friend std::ostream& operator<<(std::ostream& os, const Direction d) {
211  return os << d.toChar();
212  }
216  static constexpr const std::array<Direction, 4> Along4() {
217  return {
222  };
223  }
227  static constexpr const std::array<Direction, 4> Diag4() {
228  return {
233  };
234  }
235 
236  private:
241  int8_t d;
242 };
243 static_assert(sizeof(Direction) == 1, "size error");
244 
248 using Directions = std::vector<Direction>;
253 std::ostream& operator<<(std::ostream& os, const Directions& obj);
254 
268 struct Position {
269  public:
271  static constexpr int SIZE = MAZE_SIZE_MAX * MAZE_SIZE_MAX;
272 
273  public:
274  union {
275  struct {
276  int8_t x;
277  int8_t y;
278  };
279  uint16_t data;
280  };
281 
282  public:
286  constexpr Position() : data(0) {}
291  constexpr Position(const int8_t x, const int8_t y) : x(x), y(y) {}
298  uint16_t getIndex() const { return (x << MAZE_SIZE_BIT) | y; }
303  static Position getPositionFromIndex(const uint16_t index) {
304  return {int8_t(index >> MAZE_SIZE_BIT),
305  int8_t(index & (MAZE_SIZE_MAX - 1))};
306  }
308  Position operator+(const Position p) const {
309  return Position(x + p.x, y + p.y);
310  }
312  Position operator-(const Position p) const {
313  return Position(x - p.x, y - p.y);
314  }
316  bool operator==(const Position p) const {
317  // return x == p.x && y == p.y;
318  return data == p.data; //< 高速化
319  }
321  bool operator!=(const Position p) const {
322  // return x != p.x || y != p.y;
323  return data != p.data; //< 高速化
324  }
330  Position next(const Direction d) const;
336  bool isInsideOfField() const {
337  // return x >= 0 && x < MAZE_SIZE && y >= 0 && y < MAZE_SIZE;
338  /* 高速化 */
339  return (static_cast<uint8_t>(x) < MAZE_SIZE) &&
340  (static_cast<uint8_t>(y) < MAZE_SIZE);
341  }
347  Position rotate(const Direction d) const;
354  Position rotate(const Direction d, const Position center) const {
355  return center + (*this - center).rotate(d);
356  }
360  friend std::ostream& operator<<(std::ostream& os, const Position p);
364  const char* toString() const {
365  static char str[32];
366  snprintf(str, sizeof(str), "(%02d, %02d)", x, y);
367  return str;
368  }
369 };
370 static_assert(sizeof(Position) == 2, "size error");
371 
375 using Positions = std::vector<Position>;
376 
393 struct Pose {
394  public:
398  public:
399  Pose() {}
400  Pose(const Position p, const Direction d) : p(p), d(d) {}
406  Pose next(const Direction nextDirection) const {
407  return Pose(p.next(nextDirection), nextDirection);
408  }
412  friend std::ostream& operator<<(std::ostream& os, const Pose& pose);
416  const char* toString() const {
417  static char str[32];
418  snprintf(str, sizeof(str), "(%02d, %02d, %c)", p.x, p.y, d.toChar());
419  return str;
420  }
421 };
422 static_assert(sizeof(Pose) == 4, "size error");
423 
455 struct WallIndex {
460  static constexpr int SIZE = MAZE_SIZE_MAX * MAZE_SIZE_MAX * 2;
461 
462  public:
463  union {
464  struct {
465  int8_t x;
466  int8_t y : 7;
467  uint8_t z : 1;
468  };
469  uint16_t data;
470  };
471  static_assert(MAZE_SIZE < std::pow(2, 6), "MAZE_SIZE is too large!");
472 
473  public:
477  constexpr WallIndex() : data(0) {}
481  constexpr WallIndex(const int8_t x, const int8_t y, const uint8_t z)
482  : x(x), y(y), z(z) {}
488  constexpr WallIndex(const Position p, const Direction d) : x(p.x), y(p.y) {
489  uniquify(d);
490  }
496  constexpr WallIndex(const uint16_t i)
497  : x(i & (MAZE_SIZE_MAX - 1)),
498  y((i >> MAZE_SIZE_BIT) & (MAZE_SIZE_MAX - 1)),
499  z(i >> (2 * MAZE_SIZE_BIT)) {}
501  bool operator==(const WallIndex i) const {
502  // return x == i.x && y == i.y && z == i.z;
503  return data == i.data; //< 高速化
504  }
506  bool operator!=(const WallIndex i) const {
507  // return x != i.x || y != i.y || z != i.z;
508  return data != i.data; //< 高速化
509  }
516  uint16_t getIndex() const {
517  // return (z << (2 * MAZE_SIZE_BIT)) | (y << MAZE_SIZE_BIT) | x;
518  return (z << (MAZE_SIZE_BIT << 1)) | (y << MAZE_SIZE_BIT) | x; //< 高速化
519  }
521  Position getPosition() const { return Position(x, y); }
524  // return z == 0 ? Direction::East : Direction::North;
525  return z << 1; //< 高速化
526  }
530  friend std::ostream& operator<<(std::ostream& os, const WallIndex i);
538  bool isInsideOfField() const {
539  /* x,y が フィールド内かつ、外周上にいない */
540  // return !(x < 0 || y < 0 || x >= MAZE_SIZE || y >= MAZE_SIZE ||
541  // (z == 0 && (x == MAZE_SIZE - 1)) ||
542  // (z == 1 && (y == MAZE_SIZE - 1)));
543  /* 高速化 */
544  return (static_cast<uint8_t>(x) < MAZE_SIZE - 1 + z) &&
545  (static_cast<uint8_t>(y) < MAZE_SIZE - z);
546  }
552  WallIndex next(const Direction d) const;
557  std::array<Direction, 6> getNextDirection6() const {
558  const auto d = getDirection();
559  return {{
561  d + Direction::Back,
566  }};
567  }
568 
569  private:
575  constexpr void uniquify(const Direction d) {
576  z = (d >> 1) & 1; //< {East,West} => 0, {North,South} => 1
577  switch (d) {
578  case Direction::West:
579  x--;
580  break;
581  case Direction::South:
582  y--;
583  break;
584  }
585  }
586 };
587 static_assert(sizeof(WallIndex) == 2, "size error");
588 
592 using WallIndexes = std::vector<WallIndex>;
593 
601 struct WallRecord {
605  union {
606  struct {
607  int x : 6;
608  int y : 6;
609  unsigned int d : 3;
610  unsigned int b : 1;
611  } __attribute__((__packed__));
612  uint16_t data;
613  };
614  static_assert(MAZE_SIZE < std::pow(2, 6), "MAZE_SIZE is too large!");
619  WallRecord(const int8_t x, const int8_t y, const Direction d, const bool b)
620  : x(x), y(y), d(d), b(b) {}
621  WallRecord(const Position p, const Direction d, const bool b)
622  : x(p.x), y(p.y), d(d), b(b) {}
624  const Position getPosition() const { return Position(x, y); }
626  const Direction getDirection() const { return d; }
628  friend std::ostream& operator<<(std::ostream& os, const WallRecord& obj);
629 };
630 static_assert(sizeof(WallRecord) == 2, "size error");
631 
635 using WallRecords = std::vector<WallRecord>;
636 
646 class Maze {
647  public:
654  const Position start = Position(0, 0))
655  : goals(goals), start(start) {
656  reset();
657  }
663  void reset(const bool set_start_wall = true,
664  const bool set_range_full = false);
669  bool isWall(const WallIndex i) const { return isWallBase(wall, i); }
670  bool isWall(const Position p, const Direction d) const {
671  return isWallBase(wall, WallIndex(p, d));
672  }
673  bool isWall(const int8_t x, const int8_t y, const Direction d) const {
674  return isWallBase(wall, WallIndex(Position(x, y), d));
675  }
681  void setWall(const WallIndex i, const bool b) {
682  return setWallBase(wall, i, b);
683  }
684  void setWall(const Position p, const Direction d, const bool b) {
685  return setWallBase(wall, WallIndex(p, d), b);
686  }
687  void setWall(const int8_t x, const int8_t y, const Direction d,
688  const bool b) {
689  return setWallBase(wall, WallIndex(Position(x, y), d), b);
690  }
695  bool isKnown(const WallIndex i) const { return isWallBase(known, i); }
696  bool isKnown(const Position p, const Direction d) const {
697  return isWallBase(known, WallIndex(p, d));
698  }
699  bool isKnown(const int8_t x, const int8_t y, const Direction d) const {
700  return isWallBase(known, WallIndex(Position(x, y), d));
701  }
707  void setKnown(const WallIndex i, const bool b) {
708  return setWallBase(known, i, b);
709  }
710  void setKnown(const Position p, const Direction d, const bool b) {
711  return setWallBase(known, WallIndex(p, d), b);
712  }
713  void setKnown(const int8_t x, const int8_t y, const Direction d,
714  const bool b) {
715  return setWallBase(known, WallIndex(Position(x, y), d), b);
716  }
722  bool canGo(const WallIndex i) const { return !isWall(i) && isKnown(i); }
723  bool canGo(const Position p, const Direction d) const {
724  return canGo(WallIndex(p, d));
725  }
726  bool canGo(const WallIndex& i, bool knownOnly) const {
727  return !isWall(i) && (isKnown(i) || !knownOnly);
728  }
739  bool updateWall(const Position p, const Direction d, const bool b,
740  const bool pushRecords = true);
746  void resetLastWalls(const int num, const bool set_start_wall = true);
752  int8_t wallCount(const Position p) const;
758  int8_t unknownCount(const Position p) const;
762  void print(std::ostream& os = std::cout,
763  const int mazeSize = MAZE_SIZE) const;
771  void print(const Directions& dirs, const Position start = Position(0, 0),
772  std::ostream& os = std::cout,
773  const int mazeSize = MAZE_SIZE) const;
780  void print(const Positions& positions, std::ostream& os = std::cout,
781  const int mazeSize = MAZE_SIZE) const;
796  bool parse(std::istream& is);
797  bool parse(const std::string& filepath) {
798  std::ifstream ifs(filepath);
799  return ifs ? parse(ifs) : false;
800  }
808  friend std::istream& operator>>(std::istream& is, Maze& maze) {
809  maze.parse(is);
810  return is;
811  }
818  bool parse(const std::vector<std::string>& data, const int mazeSize);
822  void setGoals(const Positions& goals) { this->goals = goals; }
826  void setStart(const Position start) { this->start = start; }
830  const Positions& getGoals() const { return goals; }
834  const Position& getStart() const { return start; }
838  const WallRecords& getWallRecords() const { return wallRecords; }
842  int8_t getMinX() const { return min_x; }
843  int8_t getMinY() const { return min_y; }
844  int8_t getMaxX() const { return max_x; }
845  int8_t getMaxY() const { return max_y; }
849  bool backupWallRecordsToFile(const std::string& filepath,
850  const bool clear = false);
854  bool restoreWallRecordsFromFile(const std::string& filepath);
855 
856  protected:
857  std::bitset<WallIndex::SIZE> wall;
858  std::bitset<WallIndex::SIZE> known;
862  int8_t min_x;
863  int8_t min_y;
864  int8_t max_x;
865  int8_t max_y;
871  bool isWallBase(const std::bitset<WallIndex::SIZE>& wall,
872  const WallIndex i) const {
873  return !i.isInsideOfField() || wall[i.getIndex()]; //< 範囲外は壁ありに
874  }
878  void setWallBase(std::bitset<WallIndex::SIZE>& wall, const WallIndex i,
879  const bool b) const {
880  if (i.isInsideOfField()) //< 範囲外アクセスの防止
881  wall[i.getIndex()] = b;
882  }
883 };
884 
885 } // namespace MazeLib
int y
区画のy座標
Definition: Maze.h:608
unsigned int d
壁の方向
Definition: Maze.h:609
int x
区画のx座標
Definition: Maze.h:607
unsigned int b
壁の有無
Definition: Maze.h:610
迷路上の方向を表す。
Definition: Maze.h:145
static constexpr const std::array< Direction, 4 > Along4()
斜めではない4方向の配列 (for文などで使用)
Definition: Maze.h:216
static constexpr const std::array< Direction, 4 > Diag4()
斜めの4方向の配列 (for文などで使用)
Definition: Maze.h:227
AbsoluteDirection
絶対方向の列挙型。 0-7 の整数
Definition: Maze.h:150
@ SouthEast
Definition: Maze.h:158
@ North
Definition: Maze.h:153
@ South
Definition: Maze.h:157
@ NorthWest
Definition: Maze.h:154
@ NorthEast
Definition: Maze.h:152
@ East
Definition: Maze.h:151
@ West
Definition: Maze.h:155
@ SouthWest
Definition: Maze.h:156
bool isAlong() const
壁沿い方向かどうかの判定
Definition: Maze.h:198
RelativeDirection
相対方向の列挙型。 0-7 の整数
Definition: Maze.h:163
@ Back
Definition: Maze.h:168
@ Left45
Definition: Maze.h:165
@ Right45
Definition: Maze.h:171
@ Right135
Definition: Maze.h:169
@ Right
Definition: Maze.h:170
@ Left
Definition: Maze.h:166
@ Front
Definition: Maze.h:164
@ Left135
Definition: Maze.h:167
constexpr Direction(const int8_t d)
整数を引数としたコンストラクタ。
Definition: Maze.h:190
constexpr Direction(const AbsoluteDirection d=East)
デフォルトコンストラクタ。絶対方向をそのまま格納。
Definition: Maze.h:184
char toChar() const
表示用char型へのキャスト
Definition: Maze.h:206
bool isDiag() const
斜め方向かどうかの判定
Definition: Maze.h:202
friend std::ostream & operator<<(std::ostream &os, const Direction d)
stream 表示
Definition: Maze.h:210
static constexpr const int8_t Max
方向の総数。for文などで使える。
Definition: Maze.h:178
迷路の壁情報を管理するクラス
Definition: Maze.h:646
void setKnown(const Position p, const Direction d, const bool b)
Definition: Maze.h:710
bool isWall(const Position p, const Direction d) const
Definition: Maze.h:670
bool isWallBase(const std::bitset< WallIndex::SIZE > &wall, const WallIndex i) const
壁の確認のベース関数。迷路外を参照すると壁ありと返す。
Definition: Maze.h:871
friend std::istream & operator>>(std::istream &is, Maze &maze)
入力ストリームの迷路データをパースする
Definition: Maze.h:808
bool isKnown(const WallIndex i) const
壁が探索済みかを返す
Definition: Maze.h:695
int8_t min_y
既知壁の最小区画
Definition: Maze.h:863
int8_t getMinX() const
既知部分の迷路サイズを返す。計算量を減らすために使用。
Definition: Maze.h:842
void setWall(const Position p, const Direction d, const bool b)
Definition: Maze.h:684
int8_t max_x
既知壁の最大区画
Definition: Maze.h:864
const Position & getStart() const
スタート区画を取得
Definition: Maze.h:834
void setGoals(const Positions &goals)
ゴール区画の集合を更新
Definition: Maze.h:822
void setWall(const int8_t x, const int8_t y, const Direction d, const bool b)
Definition: Maze.h:687
const Positions & getGoals() const
ゴール区画の集合を取得
Definition: Maze.h:830
void setKnown(const int8_t x, const int8_t y, const Direction d, const bool b)
Definition: Maze.h:713
int8_t max_y
既知壁の最大区画
Definition: Maze.h:865
bool canGo(const WallIndex &i, bool knownOnly) const
Definition: Maze.h:726
Position start
スタート区画
Definition: Maze.h:860
bool canGo(const WallIndex i) const
通過可能かどうかを返す
Definition: Maze.h:722
int8_t wallCount(const Position p) const
引数区画の壁の数を返す
Definition: Maze.cpp:120
bool isWall(const int8_t x, const int8_t y, const Direction d) const
Definition: Maze.h:673
Positions goals
ゴール区画の集合
Definition: Maze.h:859
bool canGo(const Position p, const Direction d) const
Definition: Maze.h:723
bool isKnown(const Position p, const Direction d) const
Definition: Maze.h:696
bool isKnown(const int8_t x, const int8_t y, const Direction d) const
Definition: Maze.h:699
std::bitset< WallIndex::SIZE > known
壁の既知未知情報
Definition: Maze.h:858
Maze(const Positions &goals=Positions(), const Position start=Position(0, 0))
デフォルトコンストラクタ
Definition: Maze.h:653
int8_t min_x
既知壁の最小区画
Definition: Maze.h:862
bool updateWall(const Position p, const Direction d, const bool b, const bool pushRecords=true)
既知の壁情報と照らしあわせながら、壁を更新する関数
Definition: Maze.cpp:130
void setWallBase(std::bitset< WallIndex::SIZE > &wall, const WallIndex i, const bool b) const
壁の更新のベース関数。迷路外を参照すると無視される。
Definition: Maze.h:878
int8_t unknownCount(const Position p) const
引数区画に隣接する未知壁の数を返す
Definition: Maze.cpp:125
WallRecords wallRecords
更新した壁のログ
Definition: Maze.h:861
const WallRecords & getWallRecords() const
壁ログを取得
Definition: Maze.h:838
void print(std::ostream &os=std::cout, const int mazeSize=MAZE_SIZE) const
迷路の表示
Definition: Maze.cpp:261
void setKnown(const WallIndex i, const bool b)
壁の既知を更新する
Definition: Maze.h:707
int wallRecordsBackupCounter
壁ログバックアップのカウンタ
Definition: Maze.h:866
bool backupWallRecordsToFile(const std::string &filepath, const bool clear=false)
壁ログをファイルに追記保存する関数
Definition: Maze.cpp:389
void setWall(const WallIndex i, const bool b)
壁を更新をする
Definition: Maze.h:681
int8_t getMinY() const
Definition: Maze.h:843
bool parse(const std::string &filepath)
Definition: Maze.h:797
int8_t getMaxX() const
Definition: Maze.h:844
void resetLastWalls(const int num, const bool set_start_wall=true)
直前に更新した壁を見探索状態にリセットする
Definition: Maze.cpp:154
std::bitset< WallIndex::SIZE > wall
壁情報
Definition: Maze.h:857
void reset(const bool set_start_wall=true, const bool set_range_full=false)
迷路の初期化。壁を削除し、スタート区画を既知に
Definition: Maze.cpp:108
bool parse(std::istream &is)
特定の迷路の文字列(*.maze ファイル)から壁をパースする
Definition: Maze.cpp:165
bool isWall(const WallIndex i) const
壁の有無を返す
Definition: Maze.h:669
bool restoreWallRecordsFromFile(const std::string &filepath)
壁ログファイルから壁情報を復元する関数
Definition: Maze.cpp:416
void setStart(const Position start)
スタート区画を更新
Definition: Maze.h:826
int8_t getMaxY() const
Definition: Maze.h:845
迷路探索ライブラリはすべてこの名前空間に格納されている。
Definition: Maze.h:101
static constexpr int MAZE_SIZE_MAX
迷路の1辺の区画数の最大値。2のbit数乗の値。
Definition: Maze.h:114
std::vector< Position > Positions
Position 構造体の動的配列、集合
Definition: Maze.h:375
std::ostream & operator<<(std::ostream &os, const Directions &obj)
Directions の stream 表示
Definition: Maze.cpp:16
std::vector< Direction > Directions
Direction 構造体の動的配列、集合
Definition: Maze.h:248
std::vector< WallRecord > WallRecords
WallRecord 構造体の動的配列の定義
Definition: Maze.h:635
static constexpr int MAZE_SIZE_BIT
迷路の1辺の区画数の bit 数。bit shift などに用いる。
Definition: Maze.h:110
static constexpr int MAZE_SIZE
迷路の1辺の区画数の定数。
Definition: Maze.h:106
std::vector< WallIndex > WallIndexes
WallIndex の動的配列、集合
Definition: Maze.h:592
Position と Direction をまとめた型。位置姿勢。
Definition: Maze.h:393
Position p
位置
Definition: Maze.h:395
Pose()
Definition: Maze.h:399
friend std::ostream & operator<<(std::ostream &os, const Pose &pose)
ostream での表示
Definition: Maze.cpp:66
Direction d
姿勢
Definition: Maze.h:396
const char * toString() const
表示用文字列に変換する
Definition: Maze.h:416
Pose(const Position p, const Direction d)
Definition: Maze.h:400
Pose next(const Direction nextDirection) const
隣接姿勢の取得
Definition: Maze.h:406
迷路の区画の位置(座標)を定義。
Definition: Maze.h:268
constexpr Position(const int8_t x, const int8_t y)
コンストラクタ
Definition: Maze.h:291
Position operator+(const Position p) const
加法
Definition: Maze.h:308
bool operator!=(const Position p) const
等号否定
Definition: Maze.h:321
Position rotate(const Direction d) const
座標を回転変換する
Definition: Maze.cpp:45
bool isInsideOfField() const
フィールド内かどうかを判定する関数
Definition: Maze.h:336
int8_t x
迷路区画のx座標成分
Definition: Maze.h:276
const char * toString() const
表示用文字列に変換する
Definition: Maze.h:364
Position next(const Direction d) const
自分の引数方向に隣接した区画の Position を返す
Definition: Maze.cpp:22
uint16_t getIndex() const
迷路内の区画の一意な通し番号となるIDを取得する
Definition: Maze.h:298
static constexpr int SIZE
フィールドの区画数。配列確保などで使える。
Definition: Maze.h:271
constexpr Position()
ゼロ初期化のデフォルトコンストラクタ
Definition: Maze.h:286
Position operator-(const Position p) const
減法
Definition: Maze.h:312
uint16_t data
データ全体へのアクセス用
Definition: Maze.h:279
static Position getPositionFromIndex(const uint16_t index)
IDからPositionを作成する関数
Definition: Maze.h:303
int8_t y
迷路区画のy座標成分
Definition: Maze.h:277
friend std::ostream & operator<<(std::ostream &os, const Position p)
output-stream の表示関数。 ( x, y) の形式
Definition: Maze.cpp:60
bool operator==(const Position p) const
等号
Definition: Maze.h:316
Position rotate(const Direction d, const Position center) const
座標を回転変換する
Definition: Maze.h:354
区画ベースではなく、壁ベースの管理ID
Definition: Maze.h:455
Direction getDirection() const
方向の取得
Definition: Maze.h:523
constexpr WallIndex(const int8_t x, const int8_t y, const uint8_t z)
成分を受け取ってそのまま格納するコンストラクタ
Definition: Maze.h:481
constexpr WallIndex(const Position p, const Direction d)
表現の冗長性を除去して格納するコンストラクタ
Definition: Maze.h:488
uint16_t getIndex() const
迷路内の壁を一意な通し番号として表現したIDを返す。
Definition: Maze.h:516
int8_t y
区画座標のy成分
Definition: Maze.h:466
bool operator==(const WallIndex i) const
等号
Definition: Maze.h:501
WallIndex next(const Direction d) const
引数方向の WallIndex を取得する関数
Definition: Maze.cpp:72
int8_t x
区画座標のx成分
Definition: Maze.h:465
Position getPosition() const
位置の取得
Definition: Maze.h:521
static constexpr int SIZE
壁を unique な通し番号として表現したときの総数。 配列の確保などで使用できる。
Definition: Maze.h:460
constexpr WallIndex()
デフォルトコンストラク
Definition: Maze.h:477
bool operator!=(const WallIndex i) const
等号否定
Definition: Maze.h:506
uint16_t data
データ全体へのアクセス用
Definition: Maze.h:469
std::array< Direction, 6 > getNextDirection6() const
現在壁に隣接する、柱ではない6方向を取得
Definition: Maze.h:557
bool isInsideOfField() const
壁がフィールド内か判定する関数
Definition: Maze.h:538
constexpr WallIndex(const uint16_t i)
IDを使って初期化するコンストラクタ
Definition: Maze.h:496
uint8_t z
区画内の壁の位置。0:East, 1:North
Definition: Maze.h:467
friend std::ostream & operator<<(std::ostream &os, const WallIndex i)
表示用演算子のオーバーロード。 ( x, y, d) の形式
Definition: Maze.cpp:95
区画位置、方向、壁の有無を保持する構造体。
Definition: Maze.h:601
int y
区画のy座標
Definition: Maze.h:608
int x
区画のx座標
Definition: Maze.h:607
const Direction getDirection() const
方向の取得
Definition: Maze.h:626
WallRecord(const Position p, const Direction d, const bool b)
Definition: Maze.h:621
unsigned int b
壁の有無
Definition: Maze.h:610
friend std::ostream & operator<<(std::ostream &os, const WallRecord &obj)
表示
Definition: Maze.cpp:101
WallRecord()
コンストラクタ
Definition: Maze.h:618
WallRecord(const int8_t x, const int8_t y, const Direction d, const bool b)
Definition: Maze.h:619
struct MazeLib::WallRecord::@8::@10 uint16_t data
データ全体へのアクセス用
Definition: Maze.h:606
const Position getPosition() const
区画の取得
Definition: Maze.h:624
unsigned int d
壁の方向
Definition: Maze.h:609