etrobocon2018 feat.KatLab
770af34cce41ae9c30c41303275e1add2daae0c3
(with uncommitted changes)
|
#include <Explorer.h>
公開メンバ関数 | |
Explorer () | |
void | createBlockArea () |
void | resetBlockArea () |
void | setHasBlockIn (std::int8_t blockID) |
bool | hasBlock (std::int8_t id) |
std::vector< int > | searchRoute (std::int8_t start, std::int8_t end) |
Node * | calculateNeighborCost (Node *parent, std::vector< Node * > *around, std::int32_t realCost, std::int8_t end) |
std::vector< Node * > * | getBlockAreaNodeList () |
ルート探索クラス
ETロボコン2018における、ブロック並べエリアのブロック置き場をノードとしたルート探索を行います。 斜め移動は考慮していません。
このクラスを利用して、別のブロック並べエリアを作成する場合は、次の4つの変数値を編集してください。
Example
Explorer explorer;explorer.createBlockArea();explorer.resetBlockArea(); // 内部のフラグを初期化explorer.setHasBlockIn(8);explorer.setHasBlockIn(9);explorer.setHasBlockIn(11);explorer.setHasBlockIn(15);
Explorer.h の 52 行目に定義があります。
|
inline |
デフォルトコンストラクタ
各ブロック置き場における隣接ノードIDのリスト、およびノード位置リストを作成し、そのサイズを元にノードリストを初期化しています。
Explorer.h の 76 行目に定義があります。
Node * Explorer::calculateNeighborCost | ( | Node * | parent, |
std::vector< Node * > * | around, | ||
std::int32_t | realCost, | ||
std::int8_t | end | ||
) |
ブロック置き場における隣接ノードのコストを計算します
これはA*アルゴリズムで用いる再帰的な内部処理です。 searchRoute(std::int8_t, std::int8_t) でのみ利用しています。
parent | 親ノードのポインタ |
around | 周辺ノード |
realCost | 実コスト |
end | 終端ノードのノードID |
Explorer.cpp の 85 行目に定義があります。
void Explorer::createBlockArea | ( | ) |
ブロックエリアのノードリストを作成します
作成方法は、 Node クラスのドキュメントを参考にしました。
Explorer.cpp の 3 行目に定義があります。
std::vector< Node * > * Explorer::getBlockAreaNodeList | ( | ) |
ブロック置き場のノードのポインタのリストのポインタを取得します
Explorer.cpp の 136 行目に定義があります。
bool Explorer::hasBlock | ( | std::int8_t | id | ) |
ブロック置き場のノードがブロックを保持している場合は真を返す真偽値判定を行います
引数でブロックの数以上の数値を入力した場合、何かしらのエラーが発生します。 それに関する責任をこの関数は持ちません。
id | ブロック置き場のノードID |
Explorer.cpp の 50 行目に定義があります。
void Explorer::resetBlockArea | ( | ) |
std::vector< int > Explorer::searchRoute | ( | std::int8_t | start, |
std::int8_t | end | ||
) |
ブロック置き場エリアにおける移動ルートを探索します
スタート位置と向かいたい位置を入力すると、
型のリストを返します。 これは、ブロック置き場の位置コードのリストであり、隣接ノードが連なっています。 たとえば、位置コード8から位置コード10に移動したい場合は、
を返します。 もし位置コード9にブロックが存在している場合は、
を返します。 斜め移動は未対応です。
start | スタート位置の位置コード |
end | 向かいたい位置の位置コード |
Explorer.cpp の 56 行目に定義があります。
void Explorer::setHasBlockIn | ( | std::int8_t | blockID | ) |