2024-08-20 14:39:49 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacy.Model;
|
|
|
|
|
|
|
|
public class OrderRegex(World world)
|
|
|
|
{
|
|
|
|
static IEnumerable<string> 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]+)";
|
|
|
|
|
|
|
|
public const string Turn = "([0-9]+)";
|
|
|
|
|
|
|
|
public const string SlashLocation = "(?:/([A-Za-z]+))";
|
|
|
|
|
|
|
|
public const string ParenLocation = "(?:\\(([A-Za-z ]+)\\))";
|
|
|
|
|
|
|
|
public string FullLocation => $"(?:{Timeline}-)?{Province}(?:{SlashLocation}|{ParenLocation})?(?:@{Turn})?";
|
|
|
|
|
|
|
|
public string Unit => $"(?:(?:{Power} )?{Type} )?{FullLocation}";
|
|
|
|
|
|
|
|
public const string HoldVerb = "(h|hold|holds)";
|
|
|
|
|
|
|
|
public const string MoveVerb = "(-|(?:->)|(?:=>)|(?:attack(?:s)?)|(?:move(?:s)?(?: to)?))";
|
|
|
|
|
2024-08-21 13:35:28 +00:00
|
|
|
public const string ViaConvoy = "(convoy|via convoy|by convoy)";
|
|
|
|
|
2024-08-20 14:39:49 +00:00
|
|
|
public Regex Hold => new($"^{Unit} {HoldVerb}$");
|
|
|
|
|
|
|
|
public static (
|
|
|
|
string power,
|
|
|
|
string type,
|
|
|
|
string timeline,
|
|
|
|
string province,
|
|
|
|
string location,
|
|
|
|
string turn,
|
|
|
|
string verb)
|
|
|
|
ParseHold(Match match)
|
|
|
|
=> (match.Groups[1].Value,
|
|
|
|
match.Groups[2].Value,
|
|
|
|
match.Groups[3].Value,
|
|
|
|
match.Groups[4].Value,
|
|
|
|
match.Groups[5].Length > 0
|
|
|
|
? match.Groups[5].Value
|
|
|
|
: match.Groups[6].Value,
|
|
|
|
match.Groups[7].Value,
|
|
|
|
match.Groups[8].Value);
|
|
|
|
|
2024-08-21 13:35:28 +00:00
|
|
|
public Regex Move => new($"^{Unit} {MoveVerb} {FullLocation}$(?: {ViaConvoy})?");
|
2024-08-20 14:39:49 +00:00
|
|
|
|
|
|
|
public static (
|
|
|
|
string power,
|
|
|
|
string type,
|
|
|
|
string timeline,
|
|
|
|
string province,
|
|
|
|
string location,
|
|
|
|
string turn,
|
|
|
|
string verb,
|
|
|
|
string timeline2,
|
|
|
|
string province2,
|
|
|
|
string location2,
|
2024-08-21 13:35:28 +00:00
|
|
|
string turn2,
|
|
|
|
string viaConvoy)
|
2024-08-20 14:39:49 +00:00
|
|
|
ParseMove(Match match)
|
|
|
|
=> (match.Groups[1].Value,
|
|
|
|
match.Groups[2].Value,
|
|
|
|
match.Groups[3].Value,
|
|
|
|
match.Groups[4].Value,
|
|
|
|
match.Groups[5].Length > 0
|
|
|
|
? match.Groups[5].Value
|
|
|
|
: match.Groups[6].Value,
|
|
|
|
match.Groups[7].Value,
|
|
|
|
match.Groups[8].Value,
|
|
|
|
match.Groups[9].Value,
|
|
|
|
match.Groups[10].Value,
|
|
|
|
match.Groups[11].Length > 1
|
|
|
|
? match.Groups[11].Value
|
|
|
|
: match.Groups[12].Value,
|
2024-08-21 13:35:28 +00:00
|
|
|
match.Groups[13].Value,
|
|
|
|
match.Groups[14].Value);
|
2024-08-20 14:39:49 +00:00
|
|
|
}
|