Compare commits
No commits in common. "4fee854c4c6aeafd01db485fd4d16b6cc799ef3e" and "7b890046b69b9b1156a81d869862e2fc9edf0aaf" have entirely different histories.
4fee854c4c
...
7b890046b6
|
@ -54,7 +54,7 @@ public class ReplOptions
|
|||
// The last null is returned because an EOF means we should quit the repl.
|
||||
}
|
||||
|
||||
IScriptHandler? handler = new ReplScriptHandler(Console.WriteLine);
|
||||
IScriptHandler? handler = new ReplScriptHandler();
|
||||
|
||||
Console.Write(handler.Prompt);
|
||||
foreach (string? nextInput in GetInputs())
|
||||
|
@ -69,21 +69,13 @@ public class ReplOptions
|
|||
outputWriter?.Flush();
|
||||
|
||||
// Delegate all other command parsing to the handler.
|
||||
var result = handler.HandleInput(input);
|
||||
handler = handler.HandleInput(input);
|
||||
|
||||
// Report errors if they occured.
|
||||
if (!result.Success)
|
||||
{
|
||||
Console.WriteLine($"Error: {result.Message}");
|
||||
}
|
||||
|
||||
// Quit if the handler didn't continue processing.
|
||||
if (result.NextHandler is null)
|
||||
// Quit if the handler ends processing, otherwise prompt for the next command.
|
||||
if (handler is null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Otherwise prompt for the next command.
|
||||
Console.Write(handler.Prompt);
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ public class OrderParser(World world)
|
|||
} else if (re.SupportMove.Match(command) is Match smoveMatch && smoveMatch.Success) {
|
||||
return TryParseSupportMoveOrder(world, power, smoveMatch, out order);
|
||||
} else {
|
||||
return false;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,104 +1,72 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Model;
|
||||
using MultiversalDiplomacy.Orders;
|
||||
|
||||
namespace MultiversalDiplomacy.Script;
|
||||
|
||||
public class AdjudicationQueryScriptHandler(
|
||||
Action<string> WriteLine,
|
||||
List<OrderValidation> validations,
|
||||
World world,
|
||||
IPhaseAdjudicator adjudicator)
|
||||
: IScriptHandler
|
||||
public class AdjudicationQueryScriptHandler(World world, bool strict = false) : IScriptHandler
|
||||
{
|
||||
public string Prompt => "valid> ";
|
||||
|
||||
public List<OrderValidation> Validations { get; } = validations;
|
||||
|
||||
public World World { get; private set; } = world;
|
||||
|
||||
public ScriptResult HandleInput(string input)
|
||||
/// <summary>
|
||||
/// Whether unsuccessful commands should terminate the script.
|
||||
/// </summary>
|
||||
public bool Strict { get; } = strict;
|
||||
|
||||
public IScriptHandler? HandleInput(string input)
|
||||
{
|
||||
var args = input.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (args.Length == 0 || input.StartsWith('#'))
|
||||
{
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
var command = args[0];
|
||||
switch (command)
|
||||
{
|
||||
case "---":
|
||||
WriteLine("Ready for orders");
|
||||
return ScriptResult.Succeed(new GameScriptHandler(WriteLine, World, adjudicator));
|
||||
Console.WriteLine("Ready for orders");
|
||||
return new GameScriptHandler(World, Strict);
|
||||
|
||||
case "assert" when args.Length == 1:
|
||||
WriteLine("Usage:");
|
||||
Console.WriteLine("Usage:");
|
||||
break;
|
||||
|
||||
case "assert":
|
||||
return EvaluateAssertion(args[1]);
|
||||
if (!EvaluateAssertion(args[1])) return Strict ? null : this;
|
||||
break;
|
||||
|
||||
case "status":
|
||||
throw new NotImplementedException();
|
||||
|
||||
default:
|
||||
return ScriptResult.Fail($"Unrecognized command: \"{command}\"", this);
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
}
|
||||
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
private ScriptResult EvaluateAssertion(string assertion)
|
||||
private bool EvaluateAssertion(string assertion)
|
||||
{
|
||||
var args = assertion.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "true":
|
||||
return ScriptResult.Succeed(this);
|
||||
return true;
|
||||
|
||||
case "false":
|
||||
return ScriptResult.Fail("assert false", this);
|
||||
return false;
|
||||
|
||||
case "order-valid":
|
||||
// Assert order was valid
|
||||
|
||||
case "order-invalid":
|
||||
OrderParser re = new(World);
|
||||
Regex prov = new($"^{re.FullLocation}$", RegexOptions.IgnoreCase);
|
||||
Match match = prov.Match(args[1]);
|
||||
if (!match.Success) return ScriptResult.Fail($"Could not parse province from \"{args[1]}\"", this);
|
||||
|
||||
string timeline = match.Groups[1].Length > 0
|
||||
? match.Groups[1].Value
|
||||
: Season.First.Timeline;
|
||||
var seasonsInTimeline = World.Timelines.Seasons.Where(season => season.Timeline == timeline);
|
||||
if (!seasonsInTimeline.Any()) return ScriptResult.Fail($"No seasons in timeline {timeline}", this);
|
||||
|
||||
int turn = match.Groups[4].Length > 0
|
||||
? int.Parse(match.Groups[4].Value)
|
||||
// If turn is unspecified, use the second-latest turn in the timeline,
|
||||
// since we want to assert against the subjects of the orders just adjudicated,
|
||||
// and adjudication created a new set of seasons.
|
||||
: seasonsInTimeline.Max(season => season.Turn) - 1;
|
||||
Season season = new(timeline, turn);
|
||||
|
||||
Province province = World.Map.Provinces.Single(province => province.Is(match.Groups[2].Value));
|
||||
|
||||
var matching = Validations.Where(val
|
||||
=> val.Order is UnitOrder order
|
||||
&& order.Unit.Season == season
|
||||
&& World.Map.GetLocation(order.Unit.Location).ProvinceName == province.Name);
|
||||
if (!matching.Any()) return ScriptResult.Fail("No matching validations");
|
||||
|
||||
if (args[0] == "order-valid" && !matching.First().Valid) {
|
||||
return ScriptResult.Fail($"Order \"{matching.First().Order} is invalid");
|
||||
}
|
||||
if (args[0] == "order-invalid" && matching.First().Valid) {
|
||||
return ScriptResult.Fail($"Order \"{matching.First().Order} is valid");
|
||||
}
|
||||
return ScriptResult.Succeed(this);
|
||||
// Assert order was invalid
|
||||
|
||||
case "has-past":
|
||||
// Assert a timeline's past
|
||||
|
@ -122,7 +90,8 @@ public class AdjudicationQueryScriptHandler(
|
|||
// Assert a unit's support was cut
|
||||
|
||||
default:
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
Console.WriteLine($"Unknown assertion \"{args[0]}\"");
|
||||
return !Strict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,31 +6,33 @@ using MultiversalDiplomacy.Orders;
|
|||
|
||||
namespace MultiversalDiplomacy.Script;
|
||||
|
||||
public class GameScriptHandler(
|
||||
Action<string> WriteLine,
|
||||
World world,
|
||||
IPhaseAdjudicator adjudicator)
|
||||
: IScriptHandler
|
||||
public class GameScriptHandler(World world, bool strict = false) : IScriptHandler
|
||||
{
|
||||
public string Prompt => "orders> ";
|
||||
|
||||
public World World { get; private set; } = world;
|
||||
|
||||
/// <summary>
|
||||
/// Whether unsuccessful commands should terminate the script.
|
||||
/// </summary>
|
||||
public bool Strict { get; } = strict;
|
||||
|
||||
private string? CurrentPower { get; set; } = null;
|
||||
|
||||
public List<Order> Orders { get; } = [];
|
||||
|
||||
public ScriptResult HandleInput(string input)
|
||||
public IScriptHandler? HandleInput(string input)
|
||||
{
|
||||
if (input == "") {
|
||||
CurrentPower = null;
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
if (input.StartsWith('#')) return ScriptResult.Succeed(this);
|
||||
if (input.StartsWith('#')) return this;
|
||||
|
||||
// "---" submits the orders and allows queries about the outcome
|
||||
if (input == "---") {
|
||||
WriteLine("Submitting orders for adjudication");
|
||||
Console.WriteLine("Submitting orders for adjudication");
|
||||
var adjudicator = MovementPhaseAdjudicator.Instance;
|
||||
var validation = adjudicator.ValidateOrders(World, Orders);
|
||||
var validOrders = validation
|
||||
.Where(v => v.Valid)
|
||||
|
@ -38,14 +40,14 @@ public class GameScriptHandler(
|
|||
.ToList();
|
||||
var adjudication = adjudicator.AdjudicateOrders(World, validOrders);
|
||||
var newWorld = adjudicator.UpdateWorld(World, adjudication);
|
||||
return ScriptResult.Succeed(new AdjudicationQueryScriptHandler(
|
||||
WriteLine, validation, newWorld, adjudicator));
|
||||
return new AdjudicationQueryScriptHandler(newWorld, Strict);
|
||||
}
|
||||
|
||||
// "===" submits the orders and moves immediately to taking the next set of orders
|
||||
// i.e. it's "---" twice
|
||||
if (input == "===") {
|
||||
WriteLine("Submitting orders for adjudication");
|
||||
Console.WriteLine("Submitting orders for adjudication");
|
||||
var adjudicator = MovementPhaseAdjudicator.Instance;
|
||||
var validation = adjudicator.ValidateOrders(World, Orders);
|
||||
var validOrders = validation
|
||||
.Where(v => v.Valid)
|
||||
|
@ -53,14 +55,14 @@ public class GameScriptHandler(
|
|||
.ToList();
|
||||
var adjudication = adjudicator.AdjudicateOrders(World, validOrders);
|
||||
World = adjudicator.UpdateWorld(World, adjudication);
|
||||
WriteLine("Ready for orders");
|
||||
return ScriptResult.Succeed(this);
|
||||
Console.WriteLine("Ready for orders");
|
||||
return this;
|
||||
}
|
||||
|
||||
// A block of orders for a single power beginning with "{name}:"
|
||||
if (World.Powers.FirstOrDefault(p => input.EqualsAnyCase($"{p}:"), null) is string power) {
|
||||
CurrentPower = power;
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// If it's not a comment, submit, or order block, assume it's an order.
|
||||
|
@ -74,17 +76,21 @@ public class GameScriptHandler(
|
|||
// Outside a power block, the power is prefixed to each order.
|
||||
Regex re = new($"^{World.Map.PowerRegex}(?:[:])? (.*)$", RegexOptions.IgnoreCase);
|
||||
var match = re.Match(input);
|
||||
if (!match.Success) return ScriptResult.Fail($"Could not determine ordering power in \"{input}\"", this);
|
||||
if (!match.Success) {
|
||||
Console.WriteLine($"Could not determine ordering power in \"{input}\"");
|
||||
return Strict ? null : this;
|
||||
}
|
||||
orderPower = match.Groups[1].Value;
|
||||
orderText = match.Groups[2].Value;
|
||||
}
|
||||
|
||||
if (OrderParser.TryParseOrder(World, orderPower, orderText, out Order? order)) {
|
||||
WriteLine($"Parsed {orderPower} order: {order}");
|
||||
Console.WriteLine($"Parsed {orderPower} order: {order}");
|
||||
Orders.Add(order);
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
return ScriptResult.Fail($"Failed to parse \"{orderText}\"", this);
|
||||
Console.WriteLine($"Failed to parse \"{orderText}\"");
|
||||
return Strict ? null : this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,8 @@ public interface IScriptHandler
|
|||
/// <summary>
|
||||
/// Process a line of input.
|
||||
/// </summary>
|
||||
public ScriptResult HandleInput(string input);
|
||||
/// <returns>
|
||||
/// The handler that should handle the next line of input, or null if script handling should end.
|
||||
/// </returns>
|
||||
public IScriptHandler? HandleInput(string input);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
namespace MultiversalDiplomacy.Script;
|
||||
|
@ -6,16 +5,16 @@ namespace MultiversalDiplomacy.Script;
|
|||
/// <summary>
|
||||
/// A script handler for the interactive repl.
|
||||
/// </summary>
|
||||
public class ReplScriptHandler(Action<string> WriteLine) : IScriptHandler
|
||||
public class ReplScriptHandler : IScriptHandler
|
||||
{
|
||||
public string Prompt => "5dp> ";
|
||||
|
||||
public ScriptResult HandleInput(string input)
|
||||
public IScriptHandler? HandleInput(string input)
|
||||
{
|
||||
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (args.Length == 0 || input.StartsWith('#'))
|
||||
{
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
var command = args[0];
|
||||
|
@ -23,42 +22,40 @@ public class ReplScriptHandler(Action<string> WriteLine) : IScriptHandler
|
|||
{
|
||||
case "help":
|
||||
case "?":
|
||||
WriteLine("Commands:");
|
||||
WriteLine(" help, ?: print this message");
|
||||
WriteLine(" map <variant>: start a new game of the given variant");
|
||||
WriteLine(" stab: stab");
|
||||
Console.WriteLine("Commands:");
|
||||
Console.WriteLine(" help, ?: print this message");
|
||||
Console.WriteLine(" map <variant>: start a new game of the given variant");
|
||||
Console.WriteLine(" stab: stab");
|
||||
break;
|
||||
|
||||
case "stab":
|
||||
WriteLine("stab");
|
||||
Console.WriteLine("stab");
|
||||
break;
|
||||
|
||||
case "map" when args.Length == 1:
|
||||
WriteLine("Usage:");
|
||||
WriteLine(" map <variant>");
|
||||
WriteLine("Available variants:");
|
||||
WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
|
||||
Console.WriteLine("Usage:");
|
||||
Console.WriteLine(" map <variant>");
|
||||
Console.WriteLine("Available variants:");
|
||||
Console.WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
|
||||
break;
|
||||
|
||||
case "map" when args.Length > 1:
|
||||
string mapType = args[1].Trim();
|
||||
if (!Enum.TryParse(mapType, ignoreCase: true, out MapType map)) {
|
||||
WriteLine($"Unknown variant \"{mapType}\"");
|
||||
WriteLine("Available variants:");
|
||||
WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
|
||||
Console.WriteLine($"Unknown variant \"{mapType}\"");
|
||||
Console.WriteLine("Available variants:");
|
||||
Console.WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
|
||||
break;
|
||||
}
|
||||
World world = World.WithMap(Map.FromType(map));
|
||||
WriteLine($"Created a new {map} game");
|
||||
return ScriptResult.Succeed(new SetupScriptHandler(
|
||||
WriteLine,
|
||||
world,
|
||||
MovementPhaseAdjudicator.Instance));
|
||||
Console.WriteLine($"Created a new {map} game");
|
||||
return new SetupScriptHandler(world);
|
||||
|
||||
default:
|
||||
return ScriptResult.Fail($"Unrecognized command: \"{command}\"", this);
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
break;
|
||||
}
|
||||
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
namespace MultiversalDiplomacy.Script;
|
||||
|
||||
/// <summary>
|
||||
/// The result of an <see cref="IScriptHandler"/> processing a line of input.
|
||||
/// </summary>
|
||||
/// <param name="success">Whether processing was successful.</param>
|
||||
/// <param name="next">The handler to continue script processing with.</param>
|
||||
/// <param name="message">If processing failed, the error message.</param>
|
||||
public class ScriptResult(bool success, IScriptHandler? next, string message)
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether processing was successful.
|
||||
/// </summary>
|
||||
public bool Success { get; } = success;
|
||||
|
||||
/// <summary>
|
||||
/// The handler to continue script processing with.
|
||||
/// </summary>
|
||||
public IScriptHandler? NextHandler { get; } = next;
|
||||
|
||||
/// <summary>
|
||||
/// If processing failed, the error message.
|
||||
/// </summary>
|
||||
public string Message { get; } = message;
|
||||
|
||||
/// <summary>
|
||||
/// Mark the processing as successful and continue processing with the next handler.
|
||||
/// </summary>
|
||||
public static ScriptResult Succeed(IScriptHandler next) => new(true, next, "");
|
||||
|
||||
/// <summary>
|
||||
/// Mark the processing as a failure and optionally continue with the next handler.
|
||||
/// </summary>
|
||||
/// <param name="message">The reason for the processing failure.</param>
|
||||
public static ScriptResult Fail(string message, IScriptHandler? next = null) => new(false, next, message);
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
namespace MultiversalDiplomacy.Script;
|
||||
|
@ -6,22 +5,23 @@ namespace MultiversalDiplomacy.Script;
|
|||
/// <summary>
|
||||
/// A script handler for modifying a game before it begins.
|
||||
/// </summary>
|
||||
public class SetupScriptHandler(
|
||||
Action<string> WriteLine,
|
||||
World world,
|
||||
IPhaseAdjudicator adjudicator)
|
||||
: IScriptHandler
|
||||
public class SetupScriptHandler(World world, bool strict = false) : IScriptHandler
|
||||
{
|
||||
public string Prompt => "setup> ";
|
||||
|
||||
public World World { get; private set; } = world;
|
||||
|
||||
public ScriptResult HandleInput(string input)
|
||||
/// <summary>
|
||||
/// Whether unsuccessful commands should terminate the script.
|
||||
/// </summary>
|
||||
public bool Strict { get; } = strict;
|
||||
|
||||
public IScriptHandler? HandleInput(string input)
|
||||
{
|
||||
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (args.Length == 0 || input.StartsWith('#'))
|
||||
{
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
var command = args[0];
|
||||
|
@ -29,39 +29,39 @@ public class SetupScriptHandler(
|
|||
{
|
||||
case "help":
|
||||
case "?":
|
||||
WriteLine("commands:");
|
||||
WriteLine(" begin: complete setup and start the game (alias: ---)");
|
||||
WriteLine(" list <type>: list things in a game category");
|
||||
WriteLine(" option <name> <value>: set a game option");
|
||||
WriteLine(" unit <power> <type> <province> [location]: add a unit to the game");
|
||||
WriteLine(" <province> may be \"province/location\"");
|
||||
Console.WriteLine("commands:");
|
||||
Console.WriteLine(" begin: complete setup and start the game (alias: ---)");
|
||||
Console.WriteLine(" list <type>: list things in a game category");
|
||||
Console.WriteLine(" option <name> <value>: set a game option");
|
||||
Console.WriteLine(" unit <power> <type> <province> [location]: add a unit to the game");
|
||||
Console.WriteLine(" <province> may be \"province/location\"");
|
||||
break;
|
||||
|
||||
case "begin":
|
||||
case "---":
|
||||
WriteLine("Starting game");
|
||||
WriteLine("Ready for orders");
|
||||
return ScriptResult.Succeed(new GameScriptHandler(WriteLine, World, adjudicator));
|
||||
Console.WriteLine("Starting game");
|
||||
Console.WriteLine("Ready for orders");
|
||||
return new GameScriptHandler(World, Strict);
|
||||
|
||||
case "list" when args.Length == 1:
|
||||
WriteLine("usage:");
|
||||
WriteLine(" list powers: the powers in the game");
|
||||
WriteLine(" list units: units created so far");
|
||||
Console.WriteLine("usage:");
|
||||
Console.WriteLine(" list powers: the powers in the game");
|
||||
Console.WriteLine(" list units: units created so far");
|
||||
break;
|
||||
|
||||
case "list" when args[1] == "powers":
|
||||
WriteLine("Powers:");
|
||||
Console.WriteLine("Powers:");
|
||||
foreach (string powerName in World.Powers)
|
||||
{
|
||||
WriteLine($" {powerName}");
|
||||
Console.WriteLine($" {powerName}");
|
||||
}
|
||||
break;
|
||||
|
||||
case "list" when args[1] == "units":
|
||||
WriteLine("Units:");
|
||||
Console.WriteLine("Units:");
|
||||
foreach (Unit unit in World.Units)
|
||||
{
|
||||
WriteLine($" {unit}");
|
||||
Console.WriteLine($" {unit}");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -69,23 +69,26 @@ public class SetupScriptHandler(
|
|||
throw new NotImplementedException("There are no supported options yet");
|
||||
|
||||
case "unit" when args.Length < 2:
|
||||
WriteLine("usage: unit [power] [type] [province]</location>");
|
||||
Console.WriteLine("usage: unit [power] [type] [province]</location>");
|
||||
break;
|
||||
|
||||
case "unit":
|
||||
string unitSpec = input["unit ".Length..];
|
||||
if (OrderParser.TryParseUnit(World, unitSpec, out Unit? newUnit)) {
|
||||
World = World.Update(units: World.Units.Append(newUnit));
|
||||
WriteLine($"Created {newUnit}");
|
||||
return ScriptResult.Succeed(this);
|
||||
Console.WriteLine($"Created {newUnit}");
|
||||
return this;
|
||||
}
|
||||
return ScriptResult.Fail($"Could not match unit spec \"{unitSpec}\"", this);
|
||||
Console.WriteLine($"Could not match unit spec \"{unitSpec}\"");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
|
||||
default:
|
||||
ScriptResult.Fail($"Unrecognized command: \"{command}\"", this);
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
}
|
||||
|
||||
return ScriptResult.Succeed(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
using MultiversalDiplomacy.Adjudicate;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
||||
public static class Adjudicator
|
||||
{
|
||||
public static MovementPhaseAdjudicator MovementPhase { get; } = new MovementPhaseAdjudicator(NullLogger.Instance);
|
||||
}
|
|
@ -3,8 +3,6 @@ using MultiversalDiplomacy.Model;
|
|||
using MultiversalDiplomacy.Orders;
|
||||
using NUnit.Framework;
|
||||
|
||||
using static MultiversalDiplomacyTests.Adjudicator;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
||||
public class DATC_A
|
||||
|
@ -19,7 +17,7 @@ public class DATC_A
|
|||
.Fleet("North Sea").MovesTo("Picardy").GetReference(out var order);
|
||||
|
||||
// Order should fail.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(order, Is.Invalid(ValidationReason.UnreachableDestination));
|
||||
}
|
||||
|
||||
|
@ -61,7 +59,7 @@ public class DATC_A
|
|||
.Fleet("Kiel").MovesTo("Kiel").GetReference(out var order);
|
||||
|
||||
// Program should not crash.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(order, Is.Invalid(ValidationReason.DestinationMatchesOrigin));
|
||||
}
|
||||
|
||||
|
@ -79,14 +77,14 @@ public class DATC_A
|
|||
.Army("Wales").Supports.Fleet("London").MoveTo("Yorkshire");
|
||||
|
||||
// The move of the army in Yorkshire is illegal. This makes the support of Liverpool also illegal.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderLon, Is.Valid);
|
||||
Assert.That(orderNth, Is.Invalid(ValidationReason.DestinationMatchesOrigin));
|
||||
Assert.That(orderYor, Is.Invalid(ValidationReason.DestinationMatchesOrigin));
|
||||
var orderYorRepl = orderYor.GetReplacementReference<HoldOrder>();
|
||||
|
||||
// Without the support, the Germans have a stronger force. The army in London dislodges the army in Yorkshire.
|
||||
setup.AdjudicateOrders(MovementPhase);
|
||||
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderLon, Is.Victorious);
|
||||
Assert.That(orderYorRepl, Is.Dislodged);
|
||||
}
|
||||
|
@ -100,7 +98,7 @@ public class DATC_A
|
|||
.Fleet("London", powerName: "England").MovesTo("North Sea").GetReference(out var order);
|
||||
|
||||
// Order should fail.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(order, Is.Invalid(ValidationReason.InvalidUnitForPower));
|
||||
}
|
||||
|
||||
|
@ -114,7 +112,7 @@ public class DATC_A
|
|||
.Fleet("North Sea").Convoys.Army("London").To("Belgium").GetReference(out var order);
|
||||
|
||||
// Move from London to Belgium should fail.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(order, Is.Invalid(ValidationReason.InvalidOrderTypeForUnit));
|
||||
}
|
||||
|
||||
|
@ -129,12 +127,12 @@ public class DATC_A
|
|||
["Austria"]
|
||||
.Fleet("Trieste").Supports.Fleet("Trieste").Hold().GetReference(out var orderTri);
|
||||
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderTri, Is.Invalid(ValidationReason.NoSelfSupport));
|
||||
var orderTriRepl = orderTri.GetReplacementReference<HoldOrder>();
|
||||
|
||||
// The army in Trieste should be dislodged.
|
||||
setup.AdjudicateOrders(MovementPhase);
|
||||
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderTriRepl, Is.Dislodged);
|
||||
}
|
||||
|
||||
|
@ -147,7 +145,7 @@ public class DATC_A
|
|||
.Fleet("Rome").MovesTo("Venice").GetReference(out var order);
|
||||
|
||||
// Move fails. An army can go from Rome to Venice, but a fleet can not.
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(order, Is.Invalid(ValidationReason.UnreachableDestination));
|
||||
}
|
||||
|
||||
|
@ -162,13 +160,13 @@ public class DATC_A
|
|||
.Army("Apulia").MovesTo("Venice")
|
||||
.Fleet("Rome").Supports.Army("Apulia").MoveTo("Venice").GetReference(out var orderRom);
|
||||
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// The support of Rome is illegal, because Venice can not be reached from Rome by a fleet.
|
||||
Assert.That(orderRom, Is.Invalid(ValidationReason.UnreachableSupport));
|
||||
|
||||
// Venice is not dislodged.
|
||||
setup.AdjudicateOrders(MovementPhase);
|
||||
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderVen, Is.NotDislodged);
|
||||
}
|
||||
|
||||
|
@ -182,12 +180,12 @@ public class DATC_A
|
|||
["Italy"]
|
||||
.Army("Venice").MovesTo("Tyrolia").GetReference(out var orderVen);
|
||||
|
||||
setup.ValidateOrders(MovementPhase);
|
||||
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderVie, Is.Valid);
|
||||
Assert.That(orderVen, Is.Valid);
|
||||
|
||||
// The two units bounce.
|
||||
var adjudications = setup.AdjudicateOrders(MovementPhase);
|
||||
var adjudications = setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderVie, Is.Repelled);
|
||||
Assert.That(orderVie, Is.NotDislodged);
|
||||
Assert.That(orderVen, Is.Repelled);
|
||||
|
@ -206,12 +204,12 @@ public class DATC_A
|
|||
["Italy"]
|
||||
.Army("Venice").MovesTo("Tyrolia").GetReference(out var orderVen);
|
||||
|
||||
var validations = setup.ValidateOrders(MovementPhase);
|
||||
var validations = setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
|
||||
Assert.That(orderVie, Is.Valid);
|
||||
Assert.That(orderMun, Is.Valid);
|
||||
Assert.That(orderVen, Is.Valid);
|
||||
|
||||
var adjudications = setup.AdjudicateOrders(MovementPhase);
|
||||
var adjudications = setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
// The three units bounce.
|
||||
Assert.That(orderVie, Is.Repelled);
|
||||
Assert.That(orderVie, Is.NotDislodged);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Adjudicate.Decision;
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
using static MultiversalDiplomacyTests.Adjudicator;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
@ -12,7 +11,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_1_MoveIntoOwnPastForksTimeline()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// Hold to move into the future, then move back into the past.
|
||||
setup[("a", 0)]
|
||||
|
@ -58,7 +57,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_2_SupportToRepelledPastMoveForksTimeline()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// Fail to dislodge on the first turn, then support the move so it succeeds.
|
||||
setup[("a", 0)]
|
||||
|
@ -108,7 +107,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_3_FailedMoveDoesNotForkTimeline()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// Hold to create a future, then attempt to attack in the past.
|
||||
setup[("a", 0)]
|
||||
|
@ -148,7 +147,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_4_SuperfluousSupportDoesNotForkTimeline()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// Move, then support the past move even though it succeeded already.
|
||||
setup[("a", 0)]
|
||||
|
@ -190,7 +189,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_5_CrossTimelineSupportDoesNotForkHead()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// London creates two timelines by moving into the past.
|
||||
setup[("a", 0)]
|
||||
|
@ -243,7 +242,7 @@ public class TimeTravelTest
|
|||
[Test]
|
||||
public void MDATC_3_A_6_CuttingCrossTimelineSupportDoesNotFork()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
|
||||
// As above, only now London creates three timelines.
|
||||
setup[("a", 0)]
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Adjudicate.Decision;
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using static MultiversalDiplomacyTests.Adjudicator;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
||||
public class MovementAdjudicatorTest
|
||||
|
@ -12,7 +11,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Validation_ValidHold()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").Holds().GetReference(out var order);
|
||||
|
||||
|
@ -25,7 +24,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Validation_ValidMove()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").MovesTo("Tyr").GetReference(out var order);
|
||||
|
||||
|
@ -38,7 +37,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Validation_ValidConvoy()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Fleet("Nth").Convoys.Army("Hol").To("Lon").GetReference(out var order);
|
||||
|
||||
|
@ -51,7 +50,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Validation_ValidSupportHold()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").Supports.Army("Kie").Hold().GetReference(out var order);
|
||||
|
||||
|
@ -64,7 +63,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Validation_ValidSupportMove()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").Supports.Army("Kie").MoveTo("Ber").GetReference(out var order);
|
||||
|
||||
|
@ -77,12 +76,12 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Adjudication_Hold()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").Holds().GetReference(out var order);
|
||||
|
||||
setup.ValidateOrders();
|
||||
setup.AdjudicateOrders(MovementPhase);
|
||||
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
|
||||
|
||||
var adjMun = order.Adjudications;
|
||||
Assert.That(adjMun.All(adj => adj.Resolved), Is.True);
|
||||
|
@ -97,7 +96,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Adjudication_Move()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").MovesTo("Tyr").GetReference(out var order);
|
||||
|
||||
|
@ -123,7 +122,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Adjudication_Support()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").MovesTo("Tyr").GetReference(out var move)
|
||||
.Army("Boh").Supports.Army("Mun").MoveTo("Tyr").GetReference(out var support);
|
||||
|
@ -157,7 +156,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Update_SingleHold()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup["Germany"]
|
||||
.Army("Mun").Holds().GetReference(out var mun);
|
||||
|
||||
|
@ -184,7 +183,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Update_DoubleHold()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup[("a", 0)]
|
||||
.GetReference(out Season s1)
|
||||
["Germany"]
|
||||
|
@ -234,7 +233,7 @@ public class MovementAdjudicatorTest
|
|||
[Test]
|
||||
public void Update_DoubleMove()
|
||||
{
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup[("a", 0)]
|
||||
.GetReference(out Season s1)
|
||||
["Germany"]
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
using MultiversalDiplomacy.Adjudicate.Logging;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
||||
public class NullLogger : IAdjudicatorLogger
|
||||
{
|
||||
public static NullLogger Instance { get; } = new();
|
||||
|
||||
public void Log(int contextLevel, string message, params object[] args) {}
|
||||
}
|
|
@ -15,6 +15,12 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
|||
/// </summary>
|
||||
bool Echo { get; } = echo;
|
||||
|
||||
/// <summary>
|
||||
/// Input a multiline string into the repl. Call <see cref="AssertReady"/> or <see cref="AssertClosed"/> at the end so the
|
||||
/// statement is valid.
|
||||
/// </summary>
|
||||
public ReplDriver this[string input] => ExecuteAll(input);
|
||||
|
||||
public ReplDriver ExecuteAll(string multiline)
|
||||
{
|
||||
var lines = multiline.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
@ -27,22 +33,19 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
|||
$"Cannot execute \"{inputLine}\", handler quit. Last input was \"{LastInput}\"");
|
||||
if (Echo) Console.WriteLine($"{Handler.Prompt}{inputLine}");
|
||||
|
||||
var result = Handler.HandleInput(inputLine);
|
||||
if (!result.Success) Assert.Fail($"Script failed at \"{inputLine}\": {result.Message}");
|
||||
|
||||
Handler = result.NextHandler;
|
||||
Handler = Handler.HandleInput(inputLine);
|
||||
LastInput = inputLine;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void AssertFails(string inputLine)
|
||||
public void AssertReady()
|
||||
{
|
||||
if (Handler is null) throw new AssertionException(
|
||||
$"Cannot execute \"{inputLine}\", handler quit. Last input was \"{LastInput}\"");
|
||||
if (Echo) Console.WriteLine($"{Handler.Prompt}{inputLine}");
|
||||
if (Handler is null) Assert.Fail($"Handler terminated after \"{LastInput}\"");
|
||||
}
|
||||
|
||||
var result = Handler.HandleInput(inputLine);
|
||||
if (result.Success) Assert.Fail($"Expected \"{inputLine}\" to fail, but it succeeded.");
|
||||
public void AssertClosed()
|
||||
{
|
||||
if (Handler is not null) Assert.Fail($"Handler did not terminate after \"{LastInput}\"");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,21 +9,18 @@ namespace MultiversalDiplomacyTests;
|
|||
public class ReplTest
|
||||
{
|
||||
private static ReplDriver StandardRepl() => new(
|
||||
new SetupScriptHandler(
|
||||
(msg) => {/* discard */},
|
||||
World.WithStandardMap(),
|
||||
Adjudicator.MovementPhase));
|
||||
new SetupScriptHandler(World.WithStandardMap(), strict: true));
|
||||
|
||||
[Test]
|
||||
public void SetupHandler()
|
||||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Munich
|
||||
unit Austria Army Tyrolia
|
||||
unit England F Lon
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
|
||||
SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!;
|
||||
|
@ -32,7 +29,9 @@ public class ReplTest
|
|||
Assert.That(handler.World.GetUnitAt("Tyr"), Is.Not.Null);
|
||||
Assert.That(handler.World.GetUnitAt("Lon"), Is.Not.Null);
|
||||
|
||||
repl.Execute("---");
|
||||
repl["""
|
||||
---
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||
}
|
||||
|
@ -42,7 +41,7 @@ public class ReplTest
|
|||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Austria A Tyr
|
||||
unit England F Lon
|
||||
|
@ -51,7 +50,7 @@ public class ReplTest
|
|||
Austria: Army Tyrolia - Vienna
|
||||
England:
|
||||
Lon h
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
||||
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
|
||||
|
@ -63,7 +62,9 @@ public class ReplTest
|
|||
|
||||
World before = handler.World;
|
||||
|
||||
repl.Execute("---");
|
||||
repl["""
|
||||
---
|
||||
"""].AssertReady();
|
||||
|
||||
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
|
||||
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
|
||||
|
@ -76,88 +77,94 @@ public class ReplTest
|
|||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Munich
|
||||
---
|
||||
---
|
||||
assert true
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
repl.AssertFails("assert false");
|
||||
repl["assert false"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertOrderValidity()
|
||||
public void AssertInvalidOrder()
|
||||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
---
|
||||
Germany A Mun - Stp
|
||||
Germany A Mun - Mars
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Order should be invalid
|
||||
repl.Execute("assert order-invalid Mun");
|
||||
repl.AssertFails("assert order-valid Mun");
|
||||
// Assertion should pass for an invalid order
|
||||
repl["assert order-invalid Mun"].AssertReady();
|
||||
// Assertion should fail for an invalid order
|
||||
repl["assert order-valid Mun"].AssertClosed();
|
||||
}
|
||||
|
||||
repl.ExecuteAll("""
|
||||
[Test]
|
||||
public void AssertValidOrder()
|
||||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
---
|
||||
Germany A Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Order should be valid
|
||||
repl.Execute("assert order-valid Mun");
|
||||
repl.AssertFails("assert order-invalid Mun");
|
||||
// Assertion should pass for a valid order
|
||||
repl["assert order-valid Mun"].AssertReady();
|
||||
// Assertion should fail for a valid order
|
||||
repl["assert order-invalid Mun"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertSeasonPast()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit England F London
|
||||
---
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Assertion should pass for a season's past
|
||||
repl.Execute("assert has-past a1>a0");
|
||||
repl["assert has-past a1>a0"].AssertReady();
|
||||
// Assertion should fail for an incorrect past
|
||||
repl.AssertFails("assert has-past a0>a1");
|
||||
repl["assert has-past a0>a1"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertHolds()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Austria A Tyr
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Assertion should pass for a repelled move
|
||||
repl.Execute("assert holds Tyr");
|
||||
repl["assert holds Tyr"].AssertReady();
|
||||
// Assertion should fail for a repelled move
|
||||
repl.Execute("assert dislodged Tyr");
|
||||
repl["assert dislodged Tyr"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertDislodged()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
|
@ -165,60 +172,57 @@ public class ReplTest
|
|||
Germany Mun - Tyr
|
||||
Germany Boh s Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Assertion should pass for a dislodge
|
||||
repl.Execute("assert dislodged Tyr");
|
||||
repl["assert dislodged Tyr"].AssertReady();
|
||||
// Assertion should fail for a repelled move
|
||||
repl.AssertFails("assert holds Tyr");
|
||||
repl["assert holds Tyr"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertMoves()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Assertion should pass for a move
|
||||
repl.Execute("assert moves Mun");
|
||||
repl["assert moves Mun"].AssertReady();
|
||||
// Assertion should fail for a successful move
|
||||
repl.AssertFails("assert no-move Mun");
|
||||
repl["assert no-move Mun"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertRepelled()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Austria A Tyr
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// Assertion should pass for a repelled move
|
||||
repl.Execute("assert no-move Mun");
|
||||
repl["assert no-move Mun"].AssertReady();
|
||||
// Assertion should fail for no move
|
||||
repl.AssertFails("assert moves Mun");
|
||||
repl["assert moves Mun"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertSupports()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
|
@ -227,20 +231,19 @@ public class ReplTest
|
|||
Mun - Tyr
|
||||
Boh s Mun - Tyr
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// `supports` and `cut` are opposites
|
||||
repl.Execute("assert supports Boh");
|
||||
repl.AssertFails("assert cut Boh");
|
||||
repl["assert supports Boh"].AssertReady();
|
||||
repl["assert cut Boh"].AssertClosed();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertCutSupport()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
repl["""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
|
@ -252,10 +255,10 @@ public class ReplTest
|
|||
|
||||
Italy Vienna - Boh
|
||||
---
|
||||
""");
|
||||
"""].AssertReady();
|
||||
|
||||
// `supports` and `cut` are opposites
|
||||
repl.Execute("assert cut Boh");
|
||||
repl.AssertFails("assert supports Boh");
|
||||
repl["assert cut Boh"].AssertReady();
|
||||
repl["assert supports Boh"].AssertClosed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,18 +22,11 @@ public class ScriptTests
|
|||
Assert.Ignore("Script tests postponed until parsing tests are done");
|
||||
string filename = Path.GetFileName(testScriptPath);
|
||||
int line = 0;
|
||||
IScriptHandler handler = new SetupScriptHandler(
|
||||
(msg) => {/* discard */},
|
||||
World.WithStandardMap(),
|
||||
Adjudicator.MovementPhase);
|
||||
IScriptHandler? handler = new SetupScriptHandler(World.WithStandardMap(), strict: true);
|
||||
foreach (string input in File.ReadAllLines(testScriptPath)) {
|
||||
line++;
|
||||
var result = handler.HandleInput(input);
|
||||
if (!result.Success) throw new AssertionException(
|
||||
$"Script {filename} error at line {line}: {result.Message}");
|
||||
if (result.NextHandler is null) throw new AssertionException(
|
||||
$"Script {filename} quit unexpectedly at line {line}: \"{input}\"");
|
||||
handler = result.NextHandler;
|
||||
handler = handler?.HandleInput(input);
|
||||
if (handler is null) Assert.Fail($"Script {filename} quit unexpectedly at line {line}: \"{input}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using System.Text.Json;
|
||||
|
||||
using MultiversalDiplomacy.Adjudicate;
|
||||
using MultiversalDiplomacy.Adjudicate.Decision;
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using static MultiversalDiplomacyTests.Adjudicator;
|
||||
|
||||
namespace MultiversalDiplomacyTests;
|
||||
|
||||
public class SerializationTest
|
||||
|
@ -75,7 +74,7 @@ public class SerializationTest
|
|||
public void SerializeRoundTrip_MDATC_3_A_2()
|
||||
{
|
||||
// Set up MDATC 3.A.2
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhase);
|
||||
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
||||
setup[("a", 0)]
|
||||
.GetReference(out Season s0)
|
||||
["Germany"]
|
||||
|
@ -108,7 +107,7 @@ public class SerializationTest
|
|||
});
|
||||
|
||||
// Resume the test case
|
||||
setup = new(reserialized, MovementPhase);
|
||||
setup = new(reserialized, MovementPhaseAdjudicator.Instance);
|
||||
setup[("a", 1)]
|
||||
["Germany"]
|
||||
.Army("Mun").Supports.Army("Mun", season: s0).MoveTo("Tyr").GetReference(out var mun1)
|
||||
|
|
Loading…
Reference in New Issue