int PuzzleExplorer::getNearestBlockPosition()

in str/apps/explorer/PuzzleExplorer.cpp [112:144]


int PuzzleExplorer::getNearestBlockPosition()
{	
	Node node = nodeList[myPosition];
	queue<Node> que;
	
	// ブロックを持つノードが見つかるまで幅優先探索
	while(!node.getHasBlock())
	{
		Node** nodes = node.getNeighbor();
		
		// 隣接ノードをキューに格納 
		for(int i=0; i<5; i++){
			
			// 隣接ノードがnullの時は飛ばす
			if(nodes[i] == nullptr)continue;
			
			que.push(*nodes[i]);
		}
		
		node = que.front();
		
		// キューの先頭がブロックを持っていたら終了
		if(que.front().getHasBlock())
		{
			break;
		}
		
		// 先頭要素の削除
		que.pop();
	}
	
	return node.getNum();
}