Ejemplo n.º 1
0
std::vector<Section*> Section::SetGroupId(int const id)
{
	std::queue<Section*> sectionQueue;
	std::vector<Component> visited;
	std::vector<Section*> ret;
	Section* current;
	sectionQueue.push(this);
	ret.push_back(this);

	while (!sectionQueue.empty())
	{
		current = sectionQueue.front();
		visited.push_back(current->GetComponent());
		sectionQueue.pop();

		current->groupId = id;
		for (auto aroundSectionItr = current->roomConnected.begin(); aroundSectionItr != current->roomConnected.end(); ++aroundSectionItr)
		{
			if (std::find(visited.begin(), visited.end(), (*aroundSectionItr)->GetComponent()) == visited.end())
			{
				sectionQueue.push(*aroundSectionItr);
				ret.push_back(*aroundSectionItr);
			}
		}
	}

	return ret;
}
Ejemplo n.º 2
0
void Section::operator=(Section const& section)
{
	delete myComponent;
	delete room;

	myComponent = new Component;
	room = new Rect;
	*myComponent = section.GetComponent();
	*room = section.GetRoom();
	roomConnected = section.GetConnectedRooms();
	groupId = section.groupId;
	hasRoom = section.hasRoom;
	hasPath = section.hasPath;
}
Ejemplo n.º 3
0
std::vector<std::vector<Section*>> MysteryDungeonMaker::ClassifyGroups()
{
	std::vector<std::vector<Section*>> groups;
	int groupId = 0;

	int mapHeight=dungeonSize->DungeonRowNum();
	int sectionColumnNum = dungeonSize->DungeonColumnNum();
	for (int i = 0; i < mapHeight; i++)
	{
		for (int j = 0; j < sectionColumnNum; j++)
		{
			Section* current = &sections[i][j];
			if (current->HasRoom())
			{
				if (groups.empty())
				{
					groups.push_back(current->SetGroupId(groupId++));
				}
				else
				{
					int  notMarked = 0;
					for (size_t i_groups = 0; i_groups < groups.size(); i_groups++)
					{
						if (!DungeonMakerHelper::HasComponent(groups[i_groups], current->GetComponent()))
						{
							notMarked++;
						}
					}
					if (notMarked == groups.size())
						groups.push_back(current->SetGroupId(groupId++));
				}
			}
		}
	}

	return groups;
}
Ejemplo n.º 4
0
bool Section::operator==(Section const& section)
{
	return *myComponent == section.GetComponent();
}
Ejemplo n.º 5
0
bool Section::EqualTo(Section const& section)const
{
	return *myComponent == section.GetComponent();
}
Ejemplo n.º 6
0
std::vector<Component> MysteryDungeonMaker::SearchShortestRoute(const Section& start)
{
	std::queue<const Section*> queue;
	std::vector <Component> visited;
	std::map<Component, Component> routeMap;//<key,back>
	const Section* current;
	const Section* goal = nullptr;
	bool isGoaled = false;

	queue.push(&start);
	visited.push_back(start.GetComponent());

	int mapHeight=dungeonSize->DungeonRowNum();
	int sectionColumnNum = dungeonSize->DungeonColumnNum();
	while (!queue.empty() && !isGoaled)
	{
		current = queue.front();
		queue.pop();

		for (int k = 0; k < 4; k++)
		{
			int i = current->GetComponent().i + up_down[k];
			int j = current->GetComponent().j + right_left[k];
			if ((0 <= i && i < mapHeight) && (0 <= j && j < sectionColumnNum))
			{
				Section* next = &sections[i][j];
				if (next->HasRoom() && next->GetGroupId() != start.GetGroupId())
				{
					goal = next;
					isGoaled = true;
					routeMap.insert(std::make_pair(next->GetComponent(), current->GetComponent()));
					break;
				}

				if (find(visited.begin(), visited.end(), next->GetComponent()) == visited.end() 
					&& !sections[i][j].HasPath()
					&& !sections[i][j].HasRoom())
				{
					queue.push(next);
					routeMap.insert(std::make_pair(next->GetComponent(), current->GetComponent()));
				}

				visited.push_back(next->GetComponent());
			}
		}
	}

	std::vector<Component> route;

	if (isGoaled)
	{
		Component back;
		back = goal->GetComponent();
		route.push_back(goal->GetComponent());
		while (back != start.GetComponent())
		{
			back = routeMap.find(back)->second;
			route.push_back(back);
		}
	}

	reverse(route.begin(), route.end());
	return route;
}