etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
Explorer.h
[詳解]
1 
6 #ifndef __EXPLORER__
7 #define __EXPLORER__
8 
9 #include "Node.h"
10 #include <algorithm>
11 #include <array>
12 #include <cstdlib>
13 #include <vector>
14 
52 class Explorer {
56  struct Position {
60  std::int8_t x;
64  std::int8_t y;
65  Position() : x(0), y(0) {}
66  };
67 
68  public:
77  : blockAreaNodeList(nullptr), neighborPtrs(TOTAL_NODE_COUNT), neighborsIDList(TOTAL_NODE_COUNT)
78  {
79  // 隣接ノードIDのリスト
80  std::vector<std::array<std::int8_t, MAX_NEIGHBOR_COUNT>> neighborsIDList_{
81  { { 1, 4, EMPTY_ID, EMPTY_ID },
82  { 0, 2, 5, EMPTY_ID },
83  { 1, 3, 6, EMPTY_ID },
84  { 2, 7, EMPTY_ID, EMPTY_ID },
85 
86  { 0, 5, 8, EMPTY_ID },
87  { 1, 4, 6, 9 },
88  { 2, 5, 7, 10 },
89  { 3, 6, 11, EMPTY_ID },
90 
91  { 4, 9, 12, EMPTY_ID },
92  { 5, 8, 10, 13 },
93  { 6, 9, 11, 14 },
94  { 7, 10, 15, EMPTY_ID },
95 
96  { 8, 13, EMPTY_ID, EMPTY_ID },
97  { 9, 12, 14, EMPTY_ID },
98  { 10, 13, 15, EMPTY_ID },
99  { 11, 14, EMPTY_ID, EMPTY_ID } }
100  };
101 
102  // 相対的なノード位置のリスト
103  std::vector<std::array<std::int8_t, 2>> currentPosition
104  = { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 },
105 
106  { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 },
107 
108  { 0, 2 }, { 1, 2 }, { 2, 2 }, { 3, 2 },
109 
110  { 0, 3 }, { 1, 3 }, { 2, 3 }, { 3, 3 } };
111 
112  //
113  // 以降は触れなくてよい
114  //
115 
116  for(unsigned int i = 0; i < neighborsIDList_.size(); i++) {
117  neighborsIDList[i] = neighborsIDList_[i];
118  }
119 
120  for(unsigned int i = 0; i < neighborsIDList.size(); i++) {
121  Position position;
122  position.x = currentPosition[i][0];
123  position.y = currentPosition[i][1];
124  positionList.push_back(position);
125  }
126  }
127 
135  void createBlockArea();
136 
140  void resetBlockArea();
141 
147  void setHasBlockIn(std::int8_t blockID);
148 
160  bool hasBlock(std::int8_t id);
161 
177  std::vector<int> searchRoute(std::int8_t start, std::int8_t end);
178 
193  Node* calculateNeighborCost(Node* parent, std::vector<Node*>* around, std::int32_t realCost,
194  std::int8_t end);
195 
201  std::vector<Node*>* getBlockAreaNodeList();
202 
203  private:
207  std::vector<Node*>* blockAreaNodeList;
208 
212  std::vector<Position> positionList;
213 
223  const std::int8_t EMPTY_ID = -1;
224 
228  static const std::int8_t TOTAL_NODE_COUNT = 16;
229 
233  static const std::int8_t MAX_NEIGHBOR_COUNT = 4;
234 
242  std::vector<Node> nodeList;
243 
251  std::vector<Node*> nodePtrs;
252 
260  std::vector<std::vector<Node*>> neighborPtrs;
261 
282  std::vector<std::array<std::int8_t, MAX_NEIGHBOR_COUNT>> neighborsIDList;
283 };
284 
285 #endif // EXPLORER
Definition: Node.h:142
void createBlockArea()
Definition: Explorer.cpp:3
std::vector< Node * > * getBlockAreaNodeList()
Definition: Explorer.cpp:136
Explorer()
Definition: Explorer.h:76
bool hasBlock(std::int8_t id)
Definition: Explorer.cpp:50
Node * calculateNeighborCost(Node *parent, std::vector< Node * > *around, std::int32_t realCost, std::int8_t end)
Definition: Explorer.cpp:85
void setHasBlockIn(std::int8_t blockID)
Definition: Explorer.cpp:44
A*アルゴリズムにおけるノードクラス
std::vector< int > searchRoute(std::int8_t start, std::int8_t end)
Definition: Explorer.cpp:56
void resetBlockArea()
Definition: Explorer.cpp:33