From 9a646096055e7568f26ed9c69b84a0144eca97f3 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 15 Aug 2024 22:20:03 -0700 Subject: [PATCH] Update adjudication logging --- .../Adjudicate/MovementPhaseAdjudicator.cs | 21 +++++++++++-------- MultiversalDiplomacy/Model/Timelines.cs | 1 - .../SerializationTest.cs | 12 ++++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs b/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs index f4b89c9..573996a 100644 --- a/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs +++ b/MultiversalDiplomacy/Adjudicate/MovementPhaseAdjudicator.cs @@ -620,7 +620,10 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator if (!potentialDislodger) { - progress |= LoggedUpdate(decision, false, depth, "No invader can move"); + string reason = decision.Incoming.Count == 0 + ? "No unit is attacking" + : "All attacks failed"; + progress |= LoggedUpdate(decision, false, depth, reason); } return progress; @@ -752,7 +755,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator if (givesSupport.Outcome == true) min += 1; if (givesSupport.Outcome != false) max += 1; } - progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} hold supports"); return progress; } } @@ -788,7 +791,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator } if (// In any case here, there will have to be a unit at the destination with an order, // which means that destOrder will have to be populated. Including this in the if - //condition lets the compiler know it won't be null in the if block. + // condition lets the compiler know it won't be null in the if block. destOrder != null && (// Is head to head decision.OpposingMove != null @@ -817,7 +820,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator if (givesSupport.Outcome == true) min += 1; if (givesSupport.Outcome != false) max += 1; } - progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports from other powers"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} (?) move supports from third parties"); return progress; } } @@ -839,7 +842,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator } // Force min to zero in case of an attempt to disloge a unit of the same power. if (decision.Order.Unit.Power == destPower) min = 0; - progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} (?) move supports"); return progress; } else @@ -855,7 +858,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator if (givesSupport.Outcome == true) min += 1; if (givesSupport.Outcome != false) max += 1; } - progress |= LoggedUpdate(decision, min, max, depth, "Updated with supports from all powers"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated with {decision.Supports.Count} move supports from all powers"); return progress; } } @@ -880,7 +883,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator if (givesSupport.Outcome == true) min += 1; if (givesSupport.Outcome != false) max += 1; } - progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} supports"); return progress; } @@ -934,7 +937,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator min = 0; } - progress |= LoggedUpdate(decision, min, max, depth, "Updated based on unit's supports"); + progress |= LoggedUpdate(decision, min, max, depth, $"Updated based on {decision.Supports.Count} supports"); return progress; } @@ -992,7 +995,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator decision, attack.MinValue > defense.MaxValue && beatsAllCompetingMoves, depth, - "Updated based on competing moves"); + $"Updated based on {decision.Competing.Count} competing moves"); return progress; } } diff --git a/MultiversalDiplomacy/Model/Timelines.cs b/MultiversalDiplomacy/Model/Timelines.cs index e165bc4..bead274 100644 --- a/MultiversalDiplomacy/Model/Timelines.cs +++ b/MultiversalDiplomacy/Model/Timelines.cs @@ -116,7 +116,6 @@ public class Timelines(int next, Dictionary pasts) /// public Season GetTimelineRoot(Season season) { - Console.WriteLine($"GetTimelineRoot({season.Key})"); return Pasts[season.Key] is Season past && season.Timeline == past.Timeline ? GetTimelineRoot(past) : season; diff --git a/MultiversalDiplomacyTests/SerializationTest.cs b/MultiversalDiplomacyTests/SerializationTest.cs index 34ca89c..b8d87e9 100644 --- a/MultiversalDiplomacyTests/SerializationTest.cs +++ b/MultiversalDiplomacyTests/SerializationTest.cs @@ -94,8 +94,11 @@ public class SerializationTest Assert.That(setup.World.OrderHistory[s0.Key].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves"); Assert.That(setup.World.OrderHistory[s0.Key].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges"); + // Assert.Ignore("Serialization doesn't fully work yet"); + // Serialize and deserialize the world string serialized = JsonSerializer.Serialize(setup.World, Options); + Console.WriteLine(serialized); World reserialized = JsonSerializer.Deserialize(serialized, Options) ?? throw new AssertionException("Failed to reserialize world"); @@ -103,10 +106,9 @@ public class SerializationTest Assert.That(reserialized.OrderHistory[s0.Key].Orders.Count, Is.GreaterThan(0), "Missing orders"); Assert.That(reserialized.OrderHistory[s0.Key].DoesMoveOutcomes.Count, Is.GreaterThan(0), "Missing moves"); Assert.That(reserialized.OrderHistory[s0.Key].IsDislodgedOutcomes.Count, Is.GreaterThan(0), "Missing dislodges"); + Assert.That(reserialized.Timelines.Pasts, Is.Not.Empty, "Missing timeline history"); }); - Assert.Ignore("Serialization doesn't fully work yet"); - // Resume the test case setup = new(reserialized, MovementPhaseAdjudicator.Instance); setup[("a", 1)] @@ -118,8 +120,12 @@ public class SerializationTest setup.ValidateOrders(); Assert.That(mun1, Is.Valid); var adjudications = setup.AdjudicateOrders(); + foreach (var adj in adjudications) + { + Console.WriteLine($"{adj}"); + } + Assert.That(mun1, Is.NotCut); - Console.WriteLine(string.Join(", ", adjudications.Select(a => a.ToString()))); DoesMove mun0move = adjudications.OfType().Single(move => move.Order.Unit.Key == mun0.Order.Unit.Key); Assert.That(mun0move.Outcome, Is.True); IsDislodged tyr0dislodge = adjudications.OfType().Single(dis => dis.Order.Unit.Key == tyr0.Order.Unit.Key);