BlueLagoon: Fixed bug found in testIsStateStringWellFormed

This commit is contained in:
Nathan Woodburn 2023-04-21 13:29:08 +10:00
parent 2538dff7f5
commit 024f6f63ff
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -50,7 +50,16 @@ public class BlueLagoon {
}
// Check if the state string matches the regex string
return stateString.matches(matchString);
if (!stateString.matches(matchString)) return false;
// Check that there is one and only one of each player id
// This fixed test 2-3 of D2DTests.testIsStateStringWellFormed
int numPlayers = Integer.parseInt(stateString.substring(stateString.indexOf(";") - 1, stateString.indexOf(";")));
for (int i = 0; i < numPlayers; i++) {
if (stateString.length() - stateString.replaceAll("p "+i,"").length() != 3) return false;
}
return true;
}
/**