Add province shortcuts to decrease verbosity
This commit is contained in:
parent
b679558d9c
commit
9f5ecaa16a
|
@ -84,7 +84,7 @@ public class MovementDecisions
|
||||||
// Create a dislodge decision for this unit.
|
// Create a dislodge decision for this unit.
|
||||||
List<MoveOrder> incoming = orders
|
List<MoveOrder> incoming = orders
|
||||||
.OfType<MoveOrder>()
|
.OfType<MoveOrder>()
|
||||||
.Where(move => move.Location.Province == order.Unit.Location.Province)
|
.Where(move => move.Province == order.Unit.Province)
|
||||||
.ToList();
|
.ToList();
|
||||||
this.IsDislodged[order.Unit] = new(order, incoming);
|
this.IsDislodged[order.Unit] = new(order, incoming);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class MovementDecisions
|
||||||
.OfType<MoveOrder>()
|
.OfType<MoveOrder>()
|
||||||
.Where(other
|
.Where(other
|
||||||
=> other != move
|
=> other != move
|
||||||
&& other.Location.Province == move.Location.Province)
|
&& other.Province == move.Province)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Create the move-related decisions.
|
// Create the move-related decisions.
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
// Trivial check: cannot convoy to non-coastal province.
|
// Trivial check: cannot convoy to non-coastal province.
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
AdjudicatorHelpers.InvalidateIfNotMatching(
|
||||||
order => order.Location.Type == LocationType.Land
|
order => order.Location.Type == LocationType.Land
|
||||||
&& order.Location.Province.Locations.Any(loc => loc.Type == LocationType.Water),
|
&& order.Province.Locations.Any(loc => loc.Type == LocationType.Water),
|
||||||
ValidationReason.IllegalDestinationType,
|
ValidationReason.IllegalDestinationType,
|
||||||
ref convoyOrders,
|
ref convoyOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
@ -170,7 +170,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
order =>
|
order =>
|
||||||
// Map adjacency with respect to province
|
// Map adjacency with respect to province
|
||||||
order.Unit.Location.Adjacents.Any(
|
order.Unit.Location.Adjacents.Any(
|
||||||
adjLocation => adjLocation.Province == order.Target.Location.Province)
|
adjLocation => adjLocation.Province == order.Target.Province)
|
||||||
// Turn adjacency
|
// Turn adjacency
|
||||||
&& Math.Abs(order.Unit.Season.Turn - order.Target.Season.Turn) <= 1
|
&& Math.Abs(order.Unit.Season.Turn - order.Target.Season.Turn) <= 1
|
||||||
// Timeline adjacency
|
// Timeline adjacency
|
||||||
|
@ -189,7 +189,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
// Support-move orders are invalid if the unit supports a move to any location in its own
|
// Support-move orders are invalid if the unit supports a move to any location in its own
|
||||||
// province.
|
// province.
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
AdjudicatorHelpers.InvalidateIfNotMatching(
|
||||||
order => order.Unit.Location.Province != order.Location.Province,
|
order => order.Unit.Province != order.Province,
|
||||||
ValidationReason.NoSupportMoveAgainstSelf,
|
ValidationReason.NoSupportMoveAgainstSelf,
|
||||||
ref supportMoveOrders,
|
ref supportMoveOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
@ -202,7 +202,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
order =>
|
order =>
|
||||||
// Map adjacency with respect to province
|
// Map adjacency with respect to province
|
||||||
order.Unit.Location.Adjacents.Any(
|
order.Unit.Location.Adjacents.Any(
|
||||||
adjLocation => adjLocation.Province == order.Location.Province)
|
adjLocation => adjLocation.Province == order.Province)
|
||||||
// Turn adjacency
|
// Turn adjacency
|
||||||
&& Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1
|
&& Math.Abs(order.Unit.Season.Turn - order.Season.Turn) <= 1
|
||||||
// Timeline adjacency
|
// Timeline adjacency
|
||||||
|
|
|
@ -36,7 +36,7 @@ public static class PathFinder
|
||||||
|
|
||||||
// Verify that the origin is a coastal province.
|
// Verify that the origin is a coastal province.
|
||||||
if (movingUnit.Location.Type != LocationType.Land) return false;
|
if (movingUnit.Location.Type != LocationType.Land) return false;
|
||||||
IEnumerable<Location> originCoasts = movingUnit.Location.Province.Locations
|
IEnumerable<Location> originCoasts = movingUnit.Province.Locations
|
||||||
.Where(location => location.Type == LocationType.Water);
|
.Where(location => location.Type == LocationType.Water);
|
||||||
if (!originCoasts.Any()) return false;
|
if (!originCoasts.Any()) return false;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ public class Unit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; }
|
public Location Location { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The province where the unit is.
|
||||||
|
/// </summary>
|
||||||
|
public Province Province => this.Location.Province;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The season in time when the unit is.
|
/// The season in time when the unit is.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -33,7 +38,7 @@ public class Unit
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unit's spatiotemporal location as a province-season tuple.
|
/// The unit's spatiotemporal location as a province-season tuple.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public (Province province, Season season) Point => (this.Location.Province, this.Season);
|
public (Province province, Season season) Point => (this.Province, this.Season);
|
||||||
|
|
||||||
private Unit(Unit? past, Location location, Season season, Power power, UnitType type)
|
private Unit(Unit? past, Location location, Season season, Power power, UnitType type)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +51,7 @@ public class Unit
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Power} {this.Type} {this.Location.Province} {this.Season}";
|
return $"{this.Power} {this.Type} {this.Province} {this.Season}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -291,7 +291,7 @@ public class World
|
||||||
seasonCoord ??= (this.RootSeason.Turn, this.RootSeason.Timeline);
|
seasonCoord ??= (this.RootSeason.Turn, this.RootSeason.Timeline);
|
||||||
Season season = GetSeason(seasonCoord.Value.turn, seasonCoord.Value.timeline);
|
Season season = GetSeason(seasonCoord.Value.turn, seasonCoord.Value.timeline);
|
||||||
Unit? foundUnit = this.Units.SingleOrDefault(
|
Unit? foundUnit = this.Units.SingleOrDefault(
|
||||||
u => u != null && u.Location.Province == province && u.Season == season,
|
u => u != null && u.Province == province && u.Season == season,
|
||||||
null);
|
null);
|
||||||
if (foundUnit == null) throw new KeyNotFoundException(
|
if (foundUnit == null) throw new KeyNotFoundException(
|
||||||
$"Unit at {province} at {season} not found");
|
$"Unit at {province} at {season} not found");
|
||||||
|
|
|
@ -22,6 +22,11 @@ public class ConvoyOrder : UnitOrder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; }
|
public Location Location { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The destination province to which the target is moving.
|
||||||
|
/// </summary>
|
||||||
|
public Province Province => this.Location.Province;
|
||||||
|
|
||||||
public ConvoyOrder(Power power, Unit unit, Unit target, Season season, Location location)
|
public ConvoyOrder(Power power, Unit unit, Unit target, Season season, Location location)
|
||||||
: base (power, unit)
|
: base (power, unit)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,10 +17,15 @@ public class MoveOrder : UnitOrder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; }
|
public Location Location { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The destination province to which the unit should move.
|
||||||
|
/// </summary>
|
||||||
|
public Province Province => this.Location.Province;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The destination's spatiotemporal location as a province-season tuple.
|
/// The destination's spatiotemporal location as a province-season tuple.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public (Province province, Season season) Point => (this.Location.Province, this.Season);
|
public (Province province, Season season) Point => (this.Province, this.Season);
|
||||||
|
|
||||||
public MoveOrder(Power power, Unit unit, Season season, Location location)
|
public MoveOrder(Power power, Unit unit, Season season, Location location)
|
||||||
: base (power, unit)
|
: base (power, unit)
|
||||||
|
@ -32,6 +37,6 @@ public class MoveOrder : UnitOrder
|
||||||
public bool IsOpposing(MoveOrder other)
|
public bool IsOpposing(MoveOrder other)
|
||||||
=> this.Season == other.Unit.Season
|
=> this.Season == other.Unit.Season
|
||||||
&& other.Season == this.Unit.Season
|
&& other.Season == this.Unit.Season
|
||||||
&& this.Location.Province == other.Unit.Location.Province
|
&& this.Province == other.Unit.Province
|
||||||
&& other.Location.Province == this.Unit.Location.Province;
|
&& other.Province == this.Unit.Province;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,15 @@ public class SupportMoveOrder : SupportOrder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; }
|
public Location Location { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The destination province to which the target is moving.
|
||||||
|
/// </summary>
|
||||||
|
public Province Province => this.Location.Province;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The target's destination's spatiotemporal location as a province-season tuple.
|
/// The target's destination's spatiotemporal location as a province-season tuple.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public (Province province, Season season) Point => (this.Location.Province, this.Season);
|
public (Province province, Season season) Point => (this.Province, this.Season);
|
||||||
|
|
||||||
public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location)
|
public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location)
|
||||||
: base(power, unit, target)
|
: base(power, unit, target)
|
||||||
|
|
|
@ -108,7 +108,7 @@ public abstract class OrderReference
|
||||||
DefendStrength defend => defend.Order == this.Order,
|
DefendStrength defend => defend.Order == this.Order,
|
||||||
PreventStrength prevent => prevent.Order == this.Order,
|
PreventStrength prevent => prevent.Order == this.Order,
|
||||||
HoldStrength hold => this.Order is UnitOrder unitOrder
|
HoldStrength hold => this.Order is UnitOrder unitOrder
|
||||||
? hold.Province == unitOrder.Unit.Location.Province
|
? hold.Province == unitOrder.Unit.Province
|
||||||
: false,
|
: false,
|
||||||
_ => false,
|
_ => false,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class TestCaseBuilder
|
||||||
foreach (Unit unit in this.World.Units)
|
foreach (Unit unit in this.World.Units)
|
||||||
{
|
{
|
||||||
if (unit.Power == power
|
if (unit.Power == power
|
||||||
&& unit.Location.Province == location.Province
|
&& unit.Province == location.Province
|
||||||
&& unit.Season == season)
|
&& unit.Season == season)
|
||||||
{
|
{
|
||||||
return unit;
|
return unit;
|
||||||
|
|
|
@ -68,7 +68,7 @@ class TestCaseBuilderTest
|
||||||
List<UnitOrder> orders = setup.Orders.OfType<UnitOrder>().ToList();
|
List<UnitOrder> orders = setup.Orders.OfType<UnitOrder>().ToList();
|
||||||
|
|
||||||
Func<UnitOrder, bool> OrderForProvince(string name)
|
Func<UnitOrder, bool> OrderForProvince(string name)
|
||||||
=> order => order.Unit.Location.Province.Name == name;
|
=> order => order.Unit.Province.Name == name;
|
||||||
|
|
||||||
UnitOrder orderBer = orders.Single(OrderForProvince("Berlin"));
|
UnitOrder orderBer = orders.Single(OrderForProvince("Berlin"));
|
||||||
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");
|
Assert.That(orderBer, Is.InstanceOf<MoveOrder>(), "Unexpected order type");
|
||||||
|
|
Loading…
Reference in New Issue