1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-28 19:10:35 +00:00

refactored whirlline loop detection

This commit is contained in:
Zeno Rogue 2021-08-08 19:13:09 +02:00
parent 025893e946
commit a6151f185f
3 changed files with 24 additions and 9 deletions

View File

@ -102,6 +102,7 @@ EX namespace whirlwind {
again:
cell *at = whirlline[isize(whirlline)-1];
cell *prev = whirlline[isize(whirlline)-2];
if(looped(whirlline)) return;
for(int i=0; i<at->type; i++)
if(at->move(i) && (euclid || at->move(i)->master->alt) && celldistAlt(at->move(i)) == d && at->move(i) != prev) {
whirlline.push_back(at->move(i));
@ -1062,10 +1063,9 @@ EX namespace whirlpool {
again:
cell *at = whirlline[isize(whirlline)-1];
cell *prev = whirlline[isize(whirlline)-2];
if(looped(whirlline)) return;
for(int i=0; i<at->type; i++)
if(at->move(i) && (eubinary || at->move(i)->master->alt) && celldistAlt(at->move(i)) == d && at->move(i) != prev) {
if(at->move(i) == whirlline[0]) return; // loops in weird geometries?
if(at->move(i) == whirlline[isize(whirlline)/2]) return; // even weirder geometry?
whirlline.push_back(at->move(i));
goto again;
}

View File

@ -225,13 +225,7 @@ EX namespace westwall {
again:
cell *at = whirlline[isize(whirlline)-1];
cell *prev = whirlline[isize(whirlline)-2];
if(isize(whirlline) > 2 && at == whirlline[isize(whirlline)/2]) {
/* something weird must have happened... */
static bool once = true;
if(once) addMessage("warning: a bug in building a whirl line");
once = false;
return;
}
if(looped(whirlline)) return;
for(int i=0; i<at->type; i++)
if(at->move(i) && coastvalEdge1(at->move(i)) == d && at->move(i) != prev) {
whirlline.push_back(at->move(i));

View File

@ -865,4 +865,25 @@ EX void monstersTurn() {
#endif
}
/** check if whirlline is looped, if yes, remove the repeat; may not detect loops immediately */
EX bool looped(vector<cell*>& whirlline) {
if(isize(whirlline) == 1)
return false;
if(whirlline.back() == whirlline.front()) {
whirlline.pop_back();
return true;
}
int pos = isize(whirlline)/2;
if(isize(whirlline) > 2 && whirlline.back() == whirlline[pos]) {
while(pos && whirlline.back() == whirlline[pos])
whirlline.pop_back();
/* something weird must have happened... */
static bool once = true;
if(once) addMessage("warning: a looped line");
once = false;
return true;
}
return false;
}
}