Skip to content

Commit

Permalink
Fix failed moves to the past generating timelines if traversing a win…
Browse files Browse the repository at this point in the history
…ter board
  • Loading branch information
Oliveriver committed Sep 19, 2024
1 parent ae8ebc7 commit 396ed8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/Adjudication/Execution/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Executor(World world, List<Region> regions)
private readonly List<Unit> originalRetreatingUnits = world.Boards.SelectMany(b => b.Units).Where(u => u!.MustRetreat).ToList();

private readonly List<Region> regions = regions;
private readonly MapComparer mapComparer = new();
private readonly MapComparer mapComparer = new(world.Orders.OfType<Build>().ToList());

public void ExecuteOrders()
{
Expand Down
12 changes: 7 additions & 5 deletions server/Adjudication/Execution/MapComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Adjudication;

public class MapComparer : EqualityComparer<Board>
public class MapComparer(List<Build> builds) : EqualityComparer<Board>
{
private readonly CentreComparer centreComparer = new();
private readonly UnitComparer unitComparer = new();

private readonly List<Build> builds = builds;

public override bool Equals(Board? x, Board? y)
{
if (x == null || y == null)
Expand All @@ -24,10 +26,10 @@ public override bool Equals(Board? x, Board? y)
return false;
}

var hasMatchingUnits = x.Units
.OrderBy(u => u.Location.RegionId)
.SequenceEqual(y.Units.OrderBy(u => u.Location.RegionId),
unitComparer);
var xUnits = x.Units.Where(u => !builds.Any(b => b.Unit == u)).OrderBy(u => u.Location.RegionId);
var yUnits = y.Units.Where(u => !builds.Any(b => b.Unit == u)).OrderBy(u => u.Location.RegionId);

var hasMatchingUnits = xUnits.SequenceEqual(yUnits, unitComparer);

return hasMatchingUnits;
}
Expand Down

0 comments on commit 396ed8a

Please sign in to comment.