removed checked flag from Map::Cell

This commit is contained in:
devZoGok
2024-01-06 14:09:33 +02:00
parent b3ea94629d
commit 0a552d24b6
3 changed files with 10 additions and 14 deletions
-2
View File
@@ -31,7 +31,6 @@ namespace battleship{
struct Cell{
enum Type{LAND, WATER};
bool checked = false;
Type type;
vb01::Vector3 pos;
std::vector<Edge> edges;
@@ -39,7 +38,6 @@ namespace battleship{
Cell(){}
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}, std::vector<int> uc = std::vector<int>{}): pos(p), type(t), edges(e), underWaterCellIds(uc){}
//int getEdgeWeight(int);
};
static Map* getSingleton();
+9 -11
View File
@@ -16,17 +16,17 @@ namespace battleship{
return pathfinder;
}
int Pathfinder::findMinDistVert(vector<Map::Cell> &cells, u32 distances[]){
int Pathfinder::findMinDistVert(vector<pair<int, bool>> &cells, u32 distances[]){
int numCells = cells.size(), minDistVert;
for(int i = 0; i < numCells; i++)
if(!cells[i].checked){
if(!cells[i].second){
minDistVert = i;
break;
}
for(int i = 0; i < numCells; i++){
bool checked = cells[i].checked;
bool checked = cells[i].second;
if(!checked && distances[i] < distances[minDistVert])
minDistVert = i;
@@ -40,15 +40,16 @@ namespace battleship{
u32 distances[size];
vector<int> paths[size];
paths[source].push_back(source);
vector<pair<int, bool>> cellsByCheck;
for(int i = 0; i < size; i++){
cells[i].checked = false;
cellsByCheck.push_back(pair(i, false));
distances[i] = (i == source ? 0 : impassibleNodeVal);
}
while(!cells[dest].checked){
int vertStrich = findMinDistVert(cells, distances);
cells[vertStrich].checked = true;
while(!cellsByCheck[dest].second){
int vertStrich = findMinDistVert(cellsByCheck, distances);
cellsByCheck[vertStrich].second = true;
int numEdges = cells[vertStrich].edges.size();
@@ -61,7 +62,7 @@ namespace battleship{
if(canMoveToStrichCell){
int edgeNode = cells[vertStrich].edges[i].destCellId;
bool isChecked = cells[edgeNode].checked;
bool isChecked = cellsByCheck[edgeNode].second;
if(!isChecked && (distances[vertStrich] + cells[vertStrich].edges[i].weight < distances[edgeNode])){
distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight;
@@ -72,9 +73,6 @@ namespace battleship{
}
}
for(int i = 0; i < size; i++)
cells[i].checked = false;
return paths[dest];
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace battleship{
inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;}
private:
Pathfinder(){}
int findMinDistVert(std::vector<Map::Cell>&, vb01::u32[]);
int findMinDistVert(std::vector<std::pair<int, bool>>&, vb01::u32[]);
vb01::u32 impassibleNodeVal;
};