diff --git a/MultiversalDiplomacy/Model/Map.cs b/MultiversalDiplomacy/Model/Map.cs
index ec96762..db258d6 100644
--- a/MultiversalDiplomacy/Model/Map.cs
+++ b/MultiversalDiplomacy/Model/Map.cs
@@ -37,6 +37,16 @@ public class Map
.ToDictionary(location => location.Key);
}
+ ///
+ /// A regex that matches any of the power names for this variant.
+ ///
+ public string PowerRegex => $"({string.Join("|", Powers)})";
+
+ ///
+ /// A regex that matches any of the province names or abbreviations for this variant.
+ ///
+ public string ProvinceRegex => $"({string.Join("|", Provinces.SelectMany(p => p.AllNames))})";
+
///
/// Get a province by name. Throws if the province is not found.
///
diff --git a/MultiversalDiplomacy/Model/Province.cs b/MultiversalDiplomacy/Model/Province.cs
index ec2da17..ede7b38 100644
--- a/MultiversalDiplomacy/Model/Province.cs
+++ b/MultiversalDiplomacy/Model/Province.cs
@@ -31,6 +31,11 @@ public class Province
public IEnumerable Locations => LocationList;
private List LocationList { get; set; }
+ ///
+ /// The province's name and abbreviations as a single enumeration.
+ ///
+ public IEnumerable AllNames => Abbreviations.Append(Name);
+
public Province(string name, string[] abbreviations, bool isSupply, bool isTime)
{
this.Name = name;
diff --git a/MultiversalDiplomacy/Model/Regex.cs b/MultiversalDiplomacy/Model/Regex.cs
index 081c933..87b3662 100644
--- a/MultiversalDiplomacy/Model/Regex.cs
+++ b/MultiversalDiplomacy/Model/Regex.cs
@@ -4,12 +4,6 @@ namespace MultiversalDiplomacy.Model;
public class OrderRegex(World world)
{
- static IEnumerable AllProvinceNames(Province prov) => prov.Abbreviations.Append(prov.Name);
-
- public string Power = $"({string.Join("|", world.Powers)})";
-
- public string Province = $"({string.Join("|", world.Provinces.SelectMany(AllProvinceNames))})";
-
public const string Type = "(A|F|Army|Fleet)";
public const string Timeline = "([A-Za-z]+)";
@@ -20,9 +14,9 @@ public class OrderRegex(World world)
public const string ParenLocation = "(?:\\(([A-Za-z ]+)\\))";
- public string FullLocation => $"(?:{Timeline}-)?{Province}(?:{SlashLocation}|{ParenLocation})?(?:@{Turn})?";
+ public string FullLocation => $"(?:{Timeline}-)?{world.Map.ProvinceRegex}(?:{SlashLocation}|{ParenLocation})?(?:@{Turn})?";
- public string Unit => $"(?:(?:{Power} )?{Type} )?{FullLocation}";
+ public string Unit => $"(?:(?:{world.Map.PowerRegex} )?{Type} )?{FullLocation}";
public const string HoldVerb = "(h|hold|holds)";
diff --git a/MultiversalDiplomacy/Script/SetupScriptHandler.cs b/MultiversalDiplomacy/Script/SetupScriptHandler.cs
index 03daa6d..9df9917 100644
--- a/MultiversalDiplomacy/Script/SetupScriptHandler.cs
+++ b/MultiversalDiplomacy/Script/SetupScriptHandler.cs
@@ -100,8 +100,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
{
newUnit = null;
- OrderRegex re = new(World);
- Regex reUnit = new($"^{re.Power} {OrderRegex.Type} {re.Province}(?:{SlashLocation}|{ParenLocation})?$");
+ Regex reUnit = new($"^{World.Map.PowerRegex} {OrderRegex.Type} {World.Map.ProvinceRegex}(?:{SlashLocation}|{ParenLocation})?$");
Match match = reUnit.Match(unitSpec);
if (!match.Success) {
Console.WriteLine($"Could not match unit spec \"{unitSpec}\"");