etrobocon2018 feat.KatLab
770af34cce41ae9c30c41303275e1add2daae0c3
(with uncommitted changes)
|
ブロック選択クラス [詳解]
#include <Selector.h>
公開型 | |
enum | NextOperationOfSearchingRouteIs { Evacuating, Moving, Carrying } |
enum | BlockColor { Blue, Red, Yellow, Green, Undefined } |
公開メンバ関数 | |
Selector () | |
std::vector< int > | exploreNextOperation (std::int8_t currentPosition, BlockColor color) |
std::int8_t | searchBlockPosition (std::int8_t currentPosition) |
std::int8_t | searchMostPoorCostShelter (std::int8_t currentPosition) |
bool | isAlreadyMovedNode (std::int8_t position) |
bool | isAlreadyAllBlockMoved () |
void | changeBlockPosition (std::int8_t beforePosition, std::int8_t afterPosition) |
void | setBlockPositionList (std::vector< std::int8_t > list) |
std::vector< std::int8_t > | getBlockPositionList () |
void | addMovedBlockPosition (std::int8_t position) |
void | pushEvacuatedBlockPosition (std::int8_t position) |
std::int8_t | popEvacuatedBlockPosition () |
bool | canFindBlockInEvacuatedList (std::int8_t position) |
void | prepareSearching (std::vector< std::int8_t > list) |
std::vector< int > | searchRoute (std::int8_t start, std::int8_t end) |
void | setNext (NextOperationOfSearchingRouteIs next) |
bool | isEvacuatingWithNext () |
bool | isMovingWithNext () |
bool | isCarryingWithNext () |
bool | isBacksteppingBeforeNextOperation () |
bool | isBackstepping () |
std::int8_t | getPositionOfCenterQuadirilateral (BlockColor color) |
void | updateRoute (std::vector< int > route) |
std::vector< int > | extractRoute () |
ブロック選択クラス
ETロボコン2018における、ブロック並べエリアにおけるルート探索、および次の動作の確認を行います。 Explorer クラス同様、斜め移動は考慮していません。
このクラスのインスタンス保持者 (以下ユーザ) は、最初に setBlockPositionList(std::vector<std::int8_t>) を実行して、このクラスにブロックの位置を設定してください。
ユーザは、次の7つのメンバ関数を随時呼出す必要があります。 1つのルート取得関数でルートを取得し、残りの6つの真偽値判定関数で移動前後の振舞いを判定してください。
Example1: when you get some values
Selector selector;std::vector<std::int8_t> initializedBlockPositionList = {0, 2, 10, 14};selector.setBlockPositionList(initializedBlockPositionList);std::int8_t currentPosition = 8;Selector::BlockColor color = Selector::Undefined;auto route = obj.exploreNextOperation(currentPosition, color);bool isEvacuating = selector.isEvacuatingWithNext();bool isMoving = selector.isMovingWithNext();bool isCarrying = selector.isCarryingWithNext();bool isClearGame = selector.isAlreadyAllBlockMoved();
Example2: when you use it while you solve puzzle
Selector selector;std::vector<std::int8_t> initializedBlockPositionList = {0, 2, 10, 14};selector.setBlockPositionList(initializedBlockPositionList);std::int8_t currentPosition;Selector::BlockColor color;while (!selector.isAlreadyAllBlockMoved()){currentPosition = this->getCurrent();color = this->getColor();if (selector.isBacksteppingBeforeNextOperation()) this->backstep();this->run(obj.exploreNextOperation(currentPosition, color));if (selector.isEvacuatingWithNext()) this->evacuate();if (selector.isBackstepping()) this->backstep();}this->lookPerpendicularParkingArea();
Selector.h の 113 行目に定義があります。
enum Selector::BlockColor |
列挙値 | |
---|---|
Blue | |
Red | |
Yellow | |
Green | |
Undefined |
Selector.h の 140 行目に定義があります。
列挙値 | |
---|---|
Evacuating | |
Moving | |
Carrying |
Selector.h の 138 行目に定義があります。
|
inline |
デフォルトコンストラクタ
各ブロック置き場における位置コストのリストを作成し、そのサイズを元にノードリストを初期化しています。
Selector.h の 122 行目に定義があります。
void Selector::addMovedBlockPosition | ( | std::int8_t | position | ) |
bool Selector::canFindBlockInEvacuatedList | ( | std::int8_t | position | ) |
void Selector::changeBlockPosition | ( | std::int8_t | beforePosition, |
std::int8_t | afterPosition | ||
) |
std::vector< int > Selector::exploreNextOperation | ( | std::int8_t | currentPosition, |
BlockColor | color | ||
) |
目的地までのルート探索および動作判定を行います。
現在地とブロックの色を選択すると、次に移動すべきブロック置き場 (目的地) までのルートを取得します。 また、内部変数の真偽値に、次の動作を設定します。
この関数を利用する場合は、内部変数の真偽値も参照してください。 詳細は Selector クラスの説明を参照してください。
currentPosition | 現在地 |
color | 取得したブロックの色 取得していない場合は Selector::Undefined を設定する必要があります。 |
Selector.cpp の 3 行目に定義があります。
std::vector< int > Selector::extractRoute | ( | ) |
std::vector< std::int8_t > Selector::getBlockPositionList | ( | ) |
std::int8_t Selector::getPositionOfCenterQuadirilateral | ( | BlockColor | color | ) |
Selector.cpp の 304 行目に定義があります。
bool Selector::isAlreadyAllBlockMoved | ( | ) |
bool Selector::isAlreadyMovedNode | ( | std::int8_t | position | ) |
bool Selector::isBackstepping | ( | ) |
bool Selector::isBacksteppingBeforeNextOperation | ( | ) |
bool Selector::isCarryingWithNext | ( | ) |
bool Selector::isEvacuatingWithNext | ( | ) |
bool Selector::isMovingWithNext | ( | ) |
std::int8_t Selector::popEvacuatedBlockPosition | ( | ) |
void Selector::prepareSearching | ( | std::vector< std::int8_t > | list | ) |
void Selector::pushEvacuatedBlockPosition | ( | std::int8_t | position | ) |
std::int8_t Selector::searchBlockPosition | ( | std::int8_t | currentPosition | ) |
Selector.cpp の 118 行目に定義があります。
std::int8_t Selector::searchMostPoorCostShelter | ( | std::int8_t | currentPosition | ) |
Selector.cpp の 147 行目に定義があります。
std::vector< int > Selector::searchRoute | ( | std::int8_t | start, |
std::int8_t | end | ||
) |
Selector.cpp の 242 行目に定義があります。
void Selector::setBlockPositionList | ( | std::vector< std::int8_t > | list | ) |
void Selector::setNext | ( | NextOperationOfSearchingRouteIs | next | ) |
Selector.cpp の 253 行目に定義があります。
void Selector::updateRoute | ( | std::vector< int > | route | ) |