Re-spec validation handler for all adjudication steps

This commit is contained in:
Tim Van Baak 2024-08-21 09:11:39 -07:00
parent 32a7ddd3b5
commit e9c4d3d2d3
4 changed files with 29 additions and 10 deletions

View File

@ -4,7 +4,7 @@ using MultiversalDiplomacy.Model;
namespace MultiversalDiplomacy.Script; namespace MultiversalDiplomacy.Script;
public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IScriptHandler public class AdjudicationQueryScriptHandler(World world, bool strict = false) : IScriptHandler
{ {
public string Prompt => "valid> "; public string Prompt => "valid> ";
@ -26,6 +26,10 @@ public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IS
var command = args[0]; var command = args[0];
switch (command) switch (command)
{ {
case "---":
Console.WriteLine("Ready for orders");
return new GameScriptHandler(World, Strict);
case "assert" when args.Length == 1: case "assert" when args.Length == 1:
Console.WriteLine("Usage:"); Console.WriteLine("Usage:");
break; break;
@ -36,17 +40,20 @@ public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IS
Regex prov = new($"{re.Province} (.*)"); Regex prov = new($"{re.Province} (.*)");
Match match = prov.Match(assertion); Match match = prov.Match(assertion);
if (!match.Success) { if (!match.Success) {
Console.WriteLine($"Could not parse province from {assertion}"); Console.WriteLine($"Could not parse province from \"{assertion}\"");
return Strict ? null : this; return Strict ? null : this;
} }
// TODO look up order once orders are validated and adjudicated // TODO look up order once orders are validated and adjudicated
Console.WriteLine("Order lookup not implemented yet"); Console.WriteLine("Order lookup not implemented yet");
return null; return null;
case "status":
throw new NotImplementedException();
default: default:
// noop on comments that begin with # // noop on comments that begin with #
if (command.StartsWith('#')) break; if (command.StartsWith('#')) break;
Console.WriteLine($"Unrecognized command: {command}"); Console.WriteLine($"Unrecognized command: \"{command}\"");
if (Strict) return null; if (Strict) return null;
break; break;
} }

View File

@ -25,11 +25,22 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
return this; return this;
} }
// "---" submits the orders for validation to allow for assertions about it // "---" submits the orders and allows queries about the outcome
if (input == "---") { if (input == "---") {
Console.WriteLine("Submitting orders for validation"); Console.WriteLine("Submitting orders for adjudication");
// TODO submit orders // TODO submit, validate, and adjudicate orders
return new ValidatedOrdersScriptHandler(World, Strict); // TODO pass validation, adjudication, and prev/next World to next handler
return new AdjudicationQueryScriptHandler(World, Strict);
}
// "===" submits the orders and moves immediately to taking the next set of orders
// i.e. it's "---" twice
if (input == "===") {
Console.WriteLine("Submitting orders for adjudication");
// TODO submit, validate, and adjudicate orders
// TODO replace World with updated world and return a new handler
Console.WriteLine("Ready for orders");
return new GameScriptHandler(World, Strict);
} }
// A block of orders for a single power beginning with "{name}:" // A block of orders for a single power beginning with "{name}:"

View File

@ -42,7 +42,7 @@ public class ReplScriptHandler : IScriptHandler
case "map" when args.Length > 1: case "map" when args.Length > 1:
string mapType = args[1].Trim(); string mapType = args[1].Trim();
if (!Enum.TryParse(mapType, ignoreCase: true, out MapType map)) { if (!Enum.TryParse(mapType, ignoreCase: true, out MapType map)) {
Console.WriteLine($"Unknown variant {mapType}"); Console.WriteLine($"Unknown variant \"{mapType}\"");
Console.WriteLine("Available variants:"); Console.WriteLine("Available variants:");
Console.WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}"); Console.WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
break; break;
@ -54,7 +54,7 @@ public class ReplScriptHandler : IScriptHandler
default: default:
// noop on comments that begin with # // noop on comments that begin with #
if (!command.StartsWith('#')) { if (!command.StartsWith('#')) {
Console.WriteLine($"Unrecognized command: {command}"); Console.WriteLine($"Unrecognized command: \"{command}\"");
} }
break; break;
} }

View File

@ -45,6 +45,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
case "begin": case "begin":
case "---": case "---":
Console.WriteLine("Starting game"); Console.WriteLine("Starting game");
Console.WriteLine("Ready for orders");
return new GameScriptHandler(World, Strict); return new GameScriptHandler(World, Strict);
case "list" when args.Length == 1: case "list" when args.Length == 1:
@ -89,7 +90,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
default: default:
// noop on comments that begin with # // noop on comments that begin with #
if (command.StartsWith('#')) break; if (command.StartsWith('#')) break;
Console.WriteLine($"Unrecognized command: {command}"); Console.WriteLine($"Unrecognized command: \"{command}\"");
if (Strict) return null; if (Strict) return null;
break; break;
} }