Compare commits
No commits in common. "5b32786904b17c3073a6ae70121c068162c4af39" and "26f7cee07097a23606e68b80ba9efaea2b78070b" have entirely different histories.
5b32786904
...
26f7cee070
|
@ -214,8 +214,7 @@ public class OrderParser(World world)
|
|||
return true;
|
||||
}
|
||||
|
||||
public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order)
|
||||
{
|
||||
public static bool TryParseOrder(World world, string power, string command, [NotNullWhen(true)] out Order? order) {
|
||||
order = null;
|
||||
OrderParser re = new(world);
|
||||
|
||||
|
@ -347,19 +346,7 @@ public class OrderParser(World world)
|
|||
{
|
||||
order = null;
|
||||
var support = ParseSupportHold(match);
|
||||
|
||||
if (!TryParseOrderSubject(world, support.timeline, support.turn, support.province, out Unit? subject)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryParseOrderSubject(
|
||||
world, support.targetTimeline, support.targetTurn, support.targetProvince, out Unit? target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
order = new SupportHoldOrder(power, subject, target);
|
||||
return true;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static bool TryParseSupportMoveOrder(
|
||||
|
@ -370,60 +357,9 @@ public class OrderParser(World world)
|
|||
{
|
||||
order = null;
|
||||
var support = ParseSupportMove(match);
|
||||
throw new NotImplementedException();
|
||||
|
||||
if (!TryParseOrderSubject(world, support.timeline, support.turn, support.province, out Unit? subject)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryParseOrderSubject(
|
||||
world, support.targetTimeline, support.targetTurn, support.targetProvince, out Unit? target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string destTimeline = support.destTimeline.Length > 0
|
||||
? support.destTimeline
|
||||
// If the destination is unspecified, use the target's
|
||||
: target.Season.Timeline;
|
||||
|
||||
int destTurn = support.destTurn.Length > 0
|
||||
? int.Parse(support.destTurn)
|
||||
// If the destination is unspecified, use the unit's
|
||||
: target.Season.Turn;
|
||||
|
||||
var destProvince = world.Map.Provinces.Single(province => province.Is(support.destProvince));
|
||||
|
||||
// DATC 4.B.6 requires that "irrelevant" locations like army to Spain nc be ignored.
|
||||
// To satisfy this, any location of the wrong type is categorically ignored, so for an army the
|
||||
// "north coast" location effectively doesn't exist here.
|
||||
// Note that target is used instead of subject, since it is possible to support a move to an inaccessible
|
||||
// coast as long as the subject can reach the province and the target can reach the location.
|
||||
var unitLocations = destProvince.Locations.Where(loc => loc.Type switch {
|
||||
LocationType.Land => target.Type == UnitType.Army,
|
||||
LocationType.Water => target.Type == UnitType.Fleet,
|
||||
_ => false,
|
||||
});
|
||||
// DATC 4.6.B also requires that unknown coasts be ignored. To satisfy this, an additional filter by name.
|
||||
// Doing both of these filters means "A - Spain/nc" is as meaningful as "F - Spain/wc".
|
||||
var matchingLocations = unitLocations.Where(loc => loc.Is(support.destLocation));
|
||||
|
||||
// If one location matched, use that location. If the coast is inaccessible to the target, the order will
|
||||
// be invalidated by a path check later to satisfy DATC 4.B.3.
|
||||
string? destLocationKey = matchingLocations.FirstOrDefault(defaultValue: null)?.Key;
|
||||
|
||||
if (destLocationKey is null) {
|
||||
// If no location matched, location was omitted, nonexistent, or the wrong type.
|
||||
// If one location is accessible, DATC 4.B.2 requires that it be used.
|
||||
// If more than one location is accessible, DATC 4.B.1 requires the order fail.
|
||||
|
||||
// TODO check which locations are accessible per the above
|
||||
destLocationKey = unitLocations.First().Key;
|
||||
|
||||
// return false;
|
||||
}
|
||||
|
||||
var destLocation = world.Map.GetLocation(destLocationKey);
|
||||
order = new SupportMoveOrder(power, subject, target, new(destTimeline, destTurn), destLocation);
|
||||
return true;
|
||||
// It is possible to support a move to an inaccessible coast if another coast is accessible to the subject.
|
||||
// DATC 4.B.4 prefers that automatic adjudicators strictly require matching coasts in supports.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,8 +120,10 @@ public class AdjudicationQueryScriptHandler(
|
|||
return ScriptResult.Succeed(this);
|
||||
|
||||
case "holds":
|
||||
// Assert a unit successfully held
|
||||
|
||||
case "dislodged":
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
// Assert a unit was dislodged
|
||||
|
||||
case "moves":
|
||||
case "no-move":
|
||||
|
@ -161,9 +163,11 @@ public class AdjudicationQueryScriptHandler(
|
|||
}
|
||||
return ScriptResult.Succeed(this);
|
||||
|
||||
case "support-given":
|
||||
case "support-cut":
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
case "supports":
|
||||
// Assert a unit's support was given
|
||||
|
||||
case "cut":
|
||||
// Assert a unit's support was cut
|
||||
|
||||
default:
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ReplDriver(IScriptHandler initialHandler, bool echo = false)
|
|||
|
||||
public ReplDriver ExecuteAll(string multiline)
|
||||
{
|
||||
var lines = multiline.Split('\n', StringSplitOptions.TrimEntries);
|
||||
var lines = multiline.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
return lines.Aggregate(this, (repl, line) => repl.Execute(line));
|
||||
}
|
||||
|
||||
|
|
|
@ -161,74 +161,10 @@ public class ReplTest
|
|||
repl.AssertFails("assert no-move Mun");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertSupportHold()
|
||||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
---
|
||||
Germany Mun s Boh
|
||||
---
|
||||
""");
|
||||
|
||||
// Support is given
|
||||
repl.Execute("assert support-given Mun");
|
||||
repl.AssertFails("assert support-cut Mun");
|
||||
|
||||
repl.ExecuteAll("""
|
||||
---
|
||||
Germany Mun s Boh
|
||||
Austria Tyr - Mun
|
||||
---
|
||||
""");
|
||||
|
||||
// Support is cut
|
||||
repl.Execute("assert support-cut Mun");
|
||||
repl.AssertFails("assert support-given Mun");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertSupportMove()
|
||||
{
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Berlin
|
||||
unit Germany A Bohemia
|
||||
unit Austria A Tyrolia
|
||||
---
|
||||
Germany:
|
||||
Berlin - Silesia
|
||||
Bohemia s Berlin - Silesia
|
||||
---
|
||||
""");
|
||||
|
||||
// Support is given
|
||||
repl.Execute("assert support-given Boh");
|
||||
repl.AssertFails("assert support-cut Boh");
|
||||
|
||||
repl.ExecuteAll("""
|
||||
---
|
||||
Germany:
|
||||
Silesia - Munich
|
||||
Bohemia s Silesia - Munich
|
||||
|
||||
Austria Tyrolia - Bohemia
|
||||
---
|
||||
""");
|
||||
|
||||
// Support is cut
|
||||
repl.AssertFails("assert support-given Boh");
|
||||
repl.Execute("assert support-cut Boh");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertDislodged()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
|
@ -237,22 +173,99 @@ public class ReplTest
|
|||
unit Austria A Tyr
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
|
||||
// Move repelled
|
||||
repl.Execute("assert holds Tyr");
|
||||
repl.AssertFails("assert dislodged Tyr");
|
||||
|
||||
repl.ExecuteAll("""
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
Germany Boh s Mun - Tyr
|
||||
---
|
||||
""");
|
||||
|
||||
// Move succeeds
|
||||
// Assertion should pass for a dislodge
|
||||
repl.Execute("assert dislodged Tyr");
|
||||
// Assertion should fail for a repelled move
|
||||
repl.AssertFails("assert holds Tyr");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertMoves()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Mun
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
|
||||
// Assertion should pass for a move
|
||||
repl.Execute("assert moves Mun");
|
||||
// Assertion should fail for a successful move
|
||||
repl.AssertFails("assert no-move Mun");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertRepelled()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Mun
|
||||
unit Austria A Tyr
|
||||
---
|
||||
Germany Mun - Tyr
|
||||
---
|
||||
""");
|
||||
|
||||
// Assertion should pass for a repelled move
|
||||
repl.Execute("assert no-move Mun");
|
||||
// Assertion should fail for no move
|
||||
repl.AssertFails("assert moves Mun");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertSupports()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
---
|
||||
Germany:
|
||||
Mun - Tyr
|
||||
Boh s Mun - Tyr
|
||||
---
|
||||
""");
|
||||
|
||||
// `supports` and `cut` are opposites
|
||||
repl.Execute("assert supports Boh");
|
||||
repl.AssertFails("assert cut Boh");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertCutSupport()
|
||||
{
|
||||
Assert.Ignore();
|
||||
var repl = StandardRepl();
|
||||
|
||||
repl.ExecuteAll("""
|
||||
unit Germany A Mun
|
||||
unit Germany A Boh
|
||||
unit Austria A Tyr
|
||||
unit Italy A Vienna
|
||||
---
|
||||
Germany:
|
||||
Mun - Tyr
|
||||
Boh s Mun - Tyr
|
||||
|
||||
Italy Vienna - Boh
|
||||
---
|
||||
""");
|
||||
|
||||
// `supports` and `cut` are opposites
|
||||
repl.Execute("assert cut Boh");
|
||||
repl.AssertFails("assert supports Boh");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue