5 const std::int8_t shelterWhenPathBlocked = 12;
6 const std::int8_t shelterWhenAllNodeInitialPositionsIsFromCenter = 12;
7 const std::int8_t goal = 11;
11 auto next = nextBlock;
12 auto start = currentPosition;
13 backsteppingFlag =
false;
14 backsteppingBeforeNextOeperationFlag =
false;
17 if(currentPosition == 8 && nextBlock == 8) {
23 next = shelterWhenPathBlocked;
25 }
else if(explorer.
hasBlock(nextMovedPosition)) {
37 next = nextMovedPosition;
40 }
else if(lastBlock != EMPTY_ID
41 && std::distance(movedBlockPositionList.begin(),
42 std::find(movedBlockPositionList.begin(), movedBlockPositionList.end(),
48 }
else if(!isClearGame) {
50 if(evacuatedSize > 0 && carryingFlag) {
53 }
else if(evacuatedSize > 0 && isCarriedToShelter) {
56 isCarriedToShelter =
false;
64 next = shelterWhenAllNodeInitialPositionsIsFromCenter;
65 lastBlock = shelterWhenAllNodeInitialPositionsIsFromCenter;
66 }
else if(explorer.
hasBlock(nextMovedPosition)) {
70 isCarriedToShelter =
true;
73 start = routeBeforeOne[routeBeforeOne.size() - 2];
74 next = nextMovedPosition;
76 backsteppingBeforeNextOeperationFlag =
true;
80 next = nextMovedPosition;
89 if(evacuatingFlag || carryingFlag) backsteppingFlag =
true;
91 if((evacuatingFlag || carryingFlag) && !backsteppingBeforeNextOeperationFlag)
95 for(
auto position : blockPositionList) explorer.
setHasBlockIn(position);
103 for(
auto itr = routeBeforeOne_.begin(); itr != routeBeforeOne_.end(); itr++) (*itr) = EMPTY_ID;
107 for(
auto node : route) {
108 routeBeforeOne_[count] = node;
120 std::int8_t blockPosition = -1;
123 for(
auto checkedBlock : blockPositionList) {
127 for(
auto position : blockPositionList) explorer.
setHasBlockIn(position);
129 if(checkedBlock == currentPosition) {
131 blockPosition = checkedBlock;
135 auto route = explorer.
searchRoute(currentPosition, checkedBlock);
136 int cost = route.size() - 1 + nodePositionCostList[checkedBlock];
140 blockPosition = checkedBlock;
144 return blockPosition;
149 std::int8_t blockPosition = -1;
151 std::vector<std::int8_t> shelters = { 0, 3, 12, 15 };
153 for(
auto shelter : shelters) {
155 for(
auto position : blockPositionList) explorer.
setHasBlockIn(position);
157 if(explorer.
hasBlock(shelter))
continue;
159 if(shelter == currentPosition) {
161 blockPosition = shelter;
165 auto route = explorer.
searchRoute(currentPosition, shelter);
166 int cost = route.size() - 1;
170 blockPosition = shelter;
174 return blockPosition;
179 auto itr = std::find(movedBlockPositionList.begin(), movedBlockPositionList.end(), position);
180 return itr != movedBlockPositionList.end();
190 auto itr = std::find(blockPositionList.begin(), blockPositionList.end(), beforePosition);
191 auto index = std::distance(blockPositionList.begin(), itr);
193 blockPositionList[index] = afterPosition;
198 for(
unsigned int i = 0; i < blockPositionList.size(); i++) {
199 blockPositionList[i] = list[i];
205 return blockPositionList;
210 movedBlockPositionList[movedCount] = position;
216 evacuatedBlockPositionList[evacuatedSize] = position;
223 return evacuatedBlockPositionList[evacuatedSize];
229 = std::find(evacuatedBlockPositionList.begin(), evacuatedBlockPositionList.end(), position);
230 return itr != evacuatedBlockPositionList.end();
237 for(
auto id : list) {
245 std::vector<int> only{ 1 };
257 evacuatingFlag =
true;
259 carryingFlag =
false;
263 evacuatingFlag =
false;
265 carryingFlag =
false;
269 evacuatingFlag =
false;
281 return evacuatingFlag;
296 return backsteppingFlag;
301 return backsteppingBeforeNextOeperationFlag;
335 std::vector<int> route)
337 for(
auto itr = routeBeforeOne_.begin(); itr != routeBeforeOne_.end(); itr++) (*itr) = EMPTY_ID;
341 for(
auto node : route) {
342 routeBeforeOne_[count] = node;
349 std::vector<int> route(TOTAL_NODE_COUNT, EMPTY_ID);
351 for(
int i = 0; i < TOTAL_NODE_COUNT; i++) {
352 if(routeBeforeOne_[i] == EMPTY_ID)
355 route[i] = routeBeforeOne_[i];
std::int8_t searchMostPoorCostShelter(std::int8_t currentPosition)
void prepareSearching(std::vector< std::int8_t > list)
std::vector< int > searchRoute(std::int8_t start, std::int8_t end)
void updateRoute(std::vector< int > route)
std::vector< std::int8_t > getBlockPositionList()
bool hasBlock(std::int8_t id)
std::int8_t getPositionOfCenterQuadirilateral(BlockColor color)
std::int8_t popEvacuatedBlockPosition()
bool isCarryingWithNext()
void setHasBlockIn(std::int8_t blockID)
bool canFindBlockInEvacuatedList(std::int8_t position)
void setBlockPositionList(std::vector< std::int8_t > list)
bool isEvacuatingWithNext()
bool isAlreadyMovedNode(std::int8_t position)
std::vector< int > extractRoute()
void pushEvacuatedBlockPosition(std::int8_t position)
std::vector< int > exploreNextOperation(std::int8_t currentPosition, BlockColor color)
std::vector< int > searchRoute(std::int8_t start, std::int8_t end)
bool isAlreadyAllBlockMoved()
bool isBacksteppingBeforeNextOperation()
NextOperationOfSearchingRouteIs
void setNext(NextOperationOfSearchingRouteIs next)
void changeBlockPosition(std::int8_t beforePosition, std::int8_t afterPosition)
void addMovedBlockPosition(std::int8_t position)
std::int8_t searchBlockPosition(std::int8_t currentPosition)