v1.3.0: adjusted some particulars of seed logic
This commit is contained in:
@@ -28,11 +28,7 @@ import java.util.Locale;
|
||||
//This class defines the parameters for seeds in ShatteredPD and contains a few convenience methods
|
||||
public class DungeonSeed {
|
||||
|
||||
public static long TOTAL_SEEDS = 5429503678976L; //26^9 possible seeds
|
||||
|
||||
public static long randomSeed(){
|
||||
return Random.Long( TOTAL_SEEDS );
|
||||
}
|
||||
public static long TOTAL_SEEDS = 5429503678976L; //larges possible seed has a value of 26^9
|
||||
|
||||
//Seed codes take the form @@@-@@@-@@@ where @ is any letter from A to Z (only uppercase)
|
||||
//This is effectively a base-26 number system, therefore 26^9 unique seeds are possible.
|
||||
@@ -40,11 +36,27 @@ public class DungeonSeed {
|
||||
//Seed codes exist to make sharing and inputting seeds easier
|
||||
//ZZZ-ZZZ-ZZZ is much easier to enter and share than 5,429,503,678,975
|
||||
|
||||
//generates a random seed, omitting seeds that contain vowels (to minimize real words appearing randomly)
|
||||
//This means that there are 21^9 = 794,280,046,581 unique seeds that can be randomly generated
|
||||
public static long randomSeed(){
|
||||
Long seed;
|
||||
String seedText;
|
||||
do {
|
||||
seed = Random.Long(TOTAL_SEEDS);
|
||||
seedText = convertToCode(seed);
|
||||
} while (seedText.contains("A") || seedText.contains("E") || seedText.contains("I") || seedText.contains("O") || seedText.contains("U"));
|
||||
return seed;
|
||||
}
|
||||
|
||||
//Takes a seed code (@@@@@@@@@) and converts it to the equivalent long value
|
||||
public static long convertFromCode( String code ){
|
||||
//if code is formatted properly, force uppercase
|
||||
if (code.length() == 11 && code.charAt(3) == '-' && code.charAt(7) == '-'){
|
||||
code = code.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
//ignore whitespace characters and dashes
|
||||
code = code.replaceAll("[-\\s]", "").toUpperCase(Locale.ROOT);
|
||||
code = code.replaceAll("[-\\s]", "");
|
||||
|
||||
if (code.length() != 9) {
|
||||
throw new IllegalArgumentException("codes must be 9 A-Z characters.");
|
||||
|
||||
Reference in New Issue
Block a user