From eec301a28cdf1f993876153fe28ae269ea8b1d32 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sun, 1 Sep 2024 12:16:02 +0100 Subject: [PATCH 01/15] Added some basic adjudication functions --- .../Evaluation/MovementEvaluator.cs | 60 +++++++++++++++++++ server/Entities/Location.cs | 9 +++ 2 files changed, 69 insertions(+) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 9b9d7b6..8ce95cd 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -22,5 +22,65 @@ public void EvaluateMovements() // - Mark orders as success/failure // - Mark units needing retreat or add disbands if not possible (use adjacencyValidator) } + + public void AdjudicateSupport(Support support) + { + foreach (var attackingMove in support.Location.AttackingMoves) + { + if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) + { + //TODO - also need to check if it's an unresolved convoy move first... + support.Status = Enums.OrderStatus.Failure; + } + } + + } + + public void AdjudicateMove(Move move) + { + + int maxPreventStr = 0; + int minPreventStr = 0; + foreach (var attackingMove in move.Destination.AttackingMoves) + { + if (!Object.ReferenceEquals(attackingMove, move)) + { + if (attackingMove.PreventStrength.Max > maxPreventStr) + { + maxPreventStr = attackingMove.PreventStrength.Max; + } + if (attackingMove.PreventStrength.Min > minPreventStr) + { + minPreventStr = attackingMove.PreventStrength.Min; + } + } + } + + if (((move.OpposingMove != null) && (move.AttackStrength.Min > move.OpposingMove.DefendStrength.Max)) || ((move.OpposingMove == null) && (move.AttackStrength.Min > move.Destination.HoldStrength.Max))) + { + if (move.AttackStrength.Min > maxPreventStr) + { + move.Status = Enums.OrderStatus.Success; + if(move.OpposingMove != null) + { + move.OpposingMove.Unit.MustRetreat = true; + } + //Need to also check if the opposing territory has a unit present and dislodge it if true + + foreach(var attackingMove in move.Destination.AttackingMoves) + { + if(!Object.ReferenceEquals(attackingMove, move)) + { + attackingMove.Status = Enums.OrderStatus.Failure; + } + } + } + } + + if (((move.OpposingMove != null) && (move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min)) || ((move.OpposingMove == null) && (move.AttackStrength.Max <= move.Destination.HoldStrength.Min)) || (move.AttackStrength.Max <= minPreventStr)) + { + //unsuccessful + } + } } diff --git a/server/Entities/Location.cs b/server/Entities/Location.cs index a2f3276..d0e8b4c 100644 --- a/server/Entities/Location.cs +++ b/server/Entities/Location.cs @@ -24,4 +24,13 @@ public bool Equals(Location? other) public override bool Equals(object? obj) => Equals(obj as Location); public override int GetHashCode() => (Timeline, Year, Phase, RegionId).GetHashCode(); + + [NotMapped] + public List AttackingMoves { get; set; } = new List(); + + [NotMapped] + public OrderStrength HoldStrength { get; set; } = new(); + + [NotMapped] + public Unit PresentUnit { get; set; } } From 74e7baf889aadbe3c4c2247085236177c0c0fbe7 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sun, 1 Sep 2024 12:18:24 +0100 Subject: [PATCH 02/15] Updating Adjudication Functions --- .../Evaluation/MovementEvaluator.cs | 26 +++++++++++++------ server/Entities/Location.cs | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 688fe66..879de8d 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -21,23 +21,26 @@ public void EvaluateMovements() // - Implement adjudication algorithm // - Mark orders as success/failure // - Mark units needing retreat or add disbands if not possible (use adjacencyValidator) - - // TEMP - foreach (var order in activeOrders.Where(o => o.Status != Enums.OrderStatus.Invalid)) - { - order.Status = Enums.OrderStatus.Success; - } } public void AdjudicateSupport(Support support) { + bool unresolved = false; foreach (var attackingMove in support.Location.AttackingMoves) { if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) { - //TODO - also need to check if it's an unresolved convoy move first... + //TODO - also need to check if it's an unresolved convoy move first... If so the support should also be unresolved. support.Status = Enums.OrderStatus.Failure; } + else + { + unresolved = true; + } + } + if(!unresolved) + { + support.Status = Enums.OrderStatus.Success; } } @@ -71,7 +74,13 @@ public void AdjudicateMove(Move move) { move.OpposingMove.Unit.MustRetreat = true; } - //Need to also check if the opposing territory has a unit present and dislodge it if true + else if (move.Destination.OrderAtLocation != null && !(move.Destination.OrderAtLocation is Move)) + { + move.Destination.OrderAtLocation.Status = Enums.OrderStatus.Failure; + move.Destination.OrderAtLocation.Unit.MustRetreat = true; + //This also needs to be done if the OrderAtDestination is an unsuccessful move, but that might not be determined yet. + //So I'm thinking to maybe remove the MustRetreat line from here from here and calculate which units are dislodged after everything else is done. + } foreach(var attackingMove in move.Destination.AttackingMoves) { @@ -86,6 +95,7 @@ public void AdjudicateMove(Move move) if (((move.OpposingMove != null) && (move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min)) || ((move.OpposingMove == null) && (move.AttackStrength.Max <= move.Destination.HoldStrength.Min)) || (move.AttackStrength.Max <= minPreventStr)) { //unsuccessful + move.Status = Enums.OrderStatus.Failure; } } } diff --git a/server/Entities/Location.cs b/server/Entities/Location.cs index d0e8b4c..550df3d 100644 --- a/server/Entities/Location.cs +++ b/server/Entities/Location.cs @@ -32,5 +32,5 @@ public bool Equals(Location? other) public OrderStrength HoldStrength { get; set; } = new(); [NotMapped] - public Unit PresentUnit { get; set; } + public Order OrderAtLocation { get; set; } } From 7e45c7e00efc815567bf6acda2abc9f19d71e75e Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sun, 1 Sep 2024 12:31:07 +0100 Subject: [PATCH 03/15] Added basic Convoy order adjudication --- .../Evaluation/MovementEvaluator.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 879de8d..2191ece 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -23,20 +23,40 @@ public void EvaluateMovements() // - Mark units needing retreat or add disbands if not possible (use adjacencyValidator) } + public void AdjudicateConvoy(Convoy convoy) + { + bool unresolved = false; + foreach (Move attackingMove in support.Location.AttackingMoves) + { + if (attackingMove.Status = Enums.OrderStatus.Success) + { + convoy.Status = Enums.OrderStatus.Failure; + } + else if (attackingMove.Status != Enums.OrderStatus.Failure) + { + unresolved = true; + } + } + if (!unresolved) + { + support.Status = Enums.OrderStatus.Success; + } + } + public void AdjudicateSupport(Support support) { bool unresolved = false; - foreach (var attackingMove in support.Location.AttackingMoves) + foreach (Move attackingMove in support.Location.AttackingMoves) { if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) { - //TODO - also need to check if it's an unresolved convoy move first... If so the support should also be unresolved. support.Status = Enums.OrderStatus.Failure; } else { unresolved = true; } + //TODO - if AttackingMove is Move via Convoy and AttackingMove is unresolved, then unresolved = true } if(!unresolved) { @@ -50,7 +70,7 @@ public void AdjudicateMove(Move move) int maxPreventStr = 0; int minPreventStr = 0; - foreach (var attackingMove in move.Destination.AttackingMoves) + foreach (Move attackingMove in move.Destination.AttackingMoves) { if (!Object.ReferenceEquals(attackingMove, move)) { @@ -82,7 +102,7 @@ public void AdjudicateMove(Move move) //So I'm thinking to maybe remove the MustRetreat line from here from here and calculate which units are dislodged after everything else is done. } - foreach(var attackingMove in move.Destination.AttackingMoves) + foreach(Move attackingMove in move.Destination.AttackingMoves) { if(!Object.ReferenceEquals(attackingMove, move)) { From fe710f5f618df6439780412b75f4178fb3d511f9 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 10:59:46 +0100 Subject: [PATCH 04/15] Added OrderStrength calculation Added OrderStrength calculation and some other adjudication methods. --- .../Evaluation/MovementEvaluator.cs | 199 ++++++++++++++++++ server/Entities/Orders/Order.cs | 3 + 2 files changed, 202 insertions(+) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 2191ece..f443344 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -23,6 +23,30 @@ public void EvaluateMovements() // - Mark units needing retreat or add disbands if not possible (use adjacencyValidator) } + public void InitialiseAdjudication() + { + foreach(Order order in activeOrders) + { + Order.Location.OrderAtLocation = order; + } + foreach(Move move in activeOrders) + { + move.Destination.AttackingMoves.Add(move); + } + foreach(Support support in activeOrders) + { + //add each support to the PotentialSupports list in the corresponding order + support.Midpoint.OrderAtLocation.PotentialSupports.Add(support); + + AdjudicateSupport(support); + } + } + + public void AdjudicateMoveViaConvoy(Move move) + { + //TODO + } + public void AdjudicateConvoy(Convoy convoy) { bool unresolved = false; @@ -118,5 +142,180 @@ public void AdjudicateMove(Move move) move.Status = Enums.OrderStatus.Failure; } } + + public void OrderStrengthCalculator(Order order) + { + if(order is Move) + { + MoveStrengthCalculator(order); + } else + { + //for all other order types, we only need Hold Strength + //initialise to base unit strength of 1 + order.HoldStrength.Min = 1; + order.HoldStrength.Max = 1; + foreach (Support support in order.PotentialSupports) + { + //all successful supports add 1 to min and max, all unresolved add 1 to max. + if (support.Status == Enums.OrderStatus.Success) + { + order.HoldStrength.Max += 1; + order.HoldStrength.Min += 1; + } + else if (support.Status != Enums.OrderStatus.Failure) + { + order.HoldStrength.Max += 1; + } + } + //copy over HoldStrength to the Location, as this makes adjudication more simple + order.Location.HoldStrength.Min = order.HoldStrength.Min; + order.Location.HoldStrength.Max = order.HoldStrength.Max; + } + } + + public void MoveStrengthCalculator(Move move) + { + //initialise all strengths to the base strength of the unit + move.AttackStrength.Min = 1; + move.AttackStrength.Max = 1; + move.HoldStrength.Min = 1; + move.HoldStrength.Max = 1; + move.DefendStrength.Min = 1; + move.DefendStrength.Max = 1; + move.PreventStrength.Min = 1; + move.PreventStrength.Max = 1; + //Hold Strength + if (move.Status == Enums.OrderStatus.Success) + { + //if a move is successful, its hold strength is 0 + move.HoldStrength.Min = 0; + move.HoldStrength.Max = 0; + } else if (move.Status = Enums.OrderStatus.Failure) + { + //if a move fails, its hold strength is 1 + move.HoldStrength.Min = 1; + move.HoldStrength.Max = 1; + } else + { + //if unknown resolution, could be 0 or 1 + move.HoldStrength.Min = 0; + move.HoldStrength.Max = 1; + } + //copy over HoldStrength to the Location, as this makes adjudication more simple + move.Location.HoldStrength.Min = move.HoldStrength.Min; + move.Location.HoldStrength.Max = move.HoldStrength.Max; + + //Attack Strength + //TODO - this still needs convoy logic. If the move is via convoy the min strength is always 0 until a Successful path is determined. + bool minAttackStrengthSet = false; + bool maxAttackStrengthSet = false; + if(move.Destination.OrderAtLocation != null && move.Unit.Owner == move.Destination.OrderAtLocation.Unit.Owner) + { + if(move.Destination.OrderAtLocation is Move) + { + if(move.Destination.OrderAtLocation.Status == Enums.OrderStatus.Failure) + { + //if the unit at the destination belongs to the same country and is moving, the attack strength is 0 if that unit fails to move. + move.AttackStrength.Min = 0; + move.AttackStrength.Max = 0; + minAttackStrengthSet = true; + maxAttackStrengthSet = true; + } + else if(move.Destination.OrderAtLocation.Status != Enums.OrderStatus.Success) + { + //if that destination move is unresolved, then the min attack strength is the case where it fails. + move.AttackStrength.Min = 0; + minAttackStrengthSet = true; + } + } + else + { + //if the unit at the destination belongs to the same country and is not moving, the attack strength is always 0. + move.AttackStrength.Min = 0; + move.AttackStrength.Max = 0; + minAttackStrengthSet = true; + maxAttackStrengthSet = true; + } + } + if(!maxAttackStrengthSet) + { + foreach(Support support in move.PotentialSupports) + { + if (support.Unit.Owner != move.Destination.OrderAtLocation.Unit.Owner || move.Destination.OrderAtLocation.Status == Enums.OrderStatus.Success) + { + //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful + //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). + if (support.Status == Enums.OrderStatus.Success) + { + move.AttackStrength.Max += 1; + if (!minAttackStrengthSet) { move.AttackStrength.Min += 1; } + } + else if (support.Status != Enums.OrderStatus.Failure) + { + move.AttackStrength.Max += 1; + } + } else if(move.Destination.OrderAtLocation.Status != Enums.OrderStatus.Failure) + { + //if that destination move is unresolved, then a support belonging to the same country can be counted, but only for max strength. + if (support.Status != Enums.OrderStatus.Failure) + { + move.AttackStrength.Max += 1; + } + } + } + } + //Defend Strength + foreach (Support support in move.PotentialSupports) + { + //all successful supports add 1 to min and max, all unresolved add 1 to max. + if (support.Status == Enums.OrderStatus.Success) + { + move.DefendStrength.Max += 1; + move.DefendStrength.Min += 1; + } + else if (support.Status != Enums.OrderStatus.Failure) + { + move.DefendStrength.Max += 1; + } + } + + //Prevent Strength + //TODO - this also still needs convoy logic. Will be same as Attack Strength. + bool minPreventStrengthSet = false; + bool maxPreventStrengthSet = false; + if (move.OpposingMove != null) + { + if(move.OpposingMove.Status == Enums.OrderStatus.Success) + { + //if the head to head attacker is successful, a move order has no attack strength + move.PreventStrength.Min = 0; + move.PreventStrength.Max = 0; + minPreventStrengthSet = true; + maxPreventStrengthSet = true; + } else if (move.OpposingMove.Status != Enums.OrderStatus.Failure) + { + //head to head attacker has not yet been resolved, so minimum value is the case where the head to head attacker is successful + move.PreventStrength.Min = 0; + minPreventStrengthSet = true; + } + } + if (!maxPreventStrengthSet) + { + foreach (Support support in move.PotentialSupports) + { + //Min Prevent Str is 1 + number of successful supports, if not already set to 0. + //Max Prevent Str is 1 + number of successful or unresolved supports, if not already set to 0. + if (support.Status == Enums.OrderStatus.Success) + { + move.AttackStrength.Max += 1; + if (!minPreventStrengthSet) { move.PreventStrength.Min += 1; } + } + else if (support.Status != Enums.OrderStatus.Failure) + { + move.PreventStrength.Max += 1; + } + } + } + } } diff --git a/server/Entities/Orders/Order.cs b/server/Entities/Orders/Order.cs index d6b4dac..5a53bf1 100644 --- a/server/Entities/Orders/Order.cs +++ b/server/Entities/Orders/Order.cs @@ -23,4 +23,7 @@ public abstract class Order [NotMapped] public OrderStrength HoldStrength { get; set; } = new(); + + [NotMapped] + public List PotentialSupports { get; set; } = []; } From 473a3a9ca7acf4fa6b23af03ae8b754e55db18b4 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 11:30:34 +0100 Subject: [PATCH 05/15] Update MovementEvaluator.cs --- server/Adjudication/Evaluation/MovementEvaluator.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index f443344..d163f0f 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -1,4 +1,5 @@ using Entities; +using Enums; namespace Adjudication; From 77bc7cf028631514114b252f840b6fa4a3d28d87 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 12:23:32 +0100 Subject: [PATCH 06/15] Bugfixes --- .../Evaluation/MovementEvaluator.cs | 94 +++++++++++-------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index d163f0f..fc523f2 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -26,15 +26,17 @@ public void EvaluateMovements() public void InitialiseAdjudication() { - foreach(Order order in activeOrders) + foreach (var order in activeOrders) { - Order.Location.OrderAtLocation = order; + order.Location.OrderAtLocation = order; } - foreach(Move move in activeOrders) + + foreach (var move in activeOrders.OfType()) { move.Destination.AttackingMoves.Add(move); } - foreach(Support support in activeOrders) + + foreach (var support in activeOrders.OfType()) { //add each support to the PotentialSupports list in the corresponding order support.Midpoint.OrderAtLocation.PotentialSupports.Add(support); @@ -51,20 +53,21 @@ public void AdjudicateMoveViaConvoy(Move move) public void AdjudicateConvoy(Convoy convoy) { bool unresolved = false; - foreach (Move attackingMove in support.Location.AttackingMoves) + foreach (Move attackingMove in convoy.Location.AttackingMoves) { - if (attackingMove.Status = Enums.OrderStatus.Success) + if (attackingMove.Status == OrderStatus.Success) { - convoy.Status = Enums.OrderStatus.Failure; + convoy.Status = OrderStatus.Failure; } - else if (attackingMove.Status != Enums.OrderStatus.Failure) + else if (attackingMove.Status != OrderStatus.Failure) { unresolved = true; } } + if (!unresolved) { - support.Status = Enums.OrderStatus.Success; + convoy.Status = OrderStatus.Success; } } @@ -75,7 +78,7 @@ public void AdjudicateSupport(Support support) { if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) { - support.Status = Enums.OrderStatus.Failure; + support.Status = OrderStatus.Failure; } else { @@ -83,11 +86,11 @@ public void AdjudicateSupport(Support support) } //TODO - if AttackingMove is Move via Convoy and AttackingMove is unresolved, then unresolved = true } + if(!unresolved) { - support.Status = Enums.OrderStatus.Success; + support.Status = OrderStatus.Success; } - } public void AdjudicateMove(Move move) @@ -95,7 +98,7 @@ public void AdjudicateMove(Move move) int maxPreventStr = 0; int minPreventStr = 0; - foreach (Move attackingMove in move.Destination.AttackingMoves) + foreach (var attackingMove in move.Destination.AttackingMoves) { if (!Object.ReferenceEquals(attackingMove, move)) { @@ -103,6 +106,7 @@ public void AdjudicateMove(Move move) { maxPreventStr = attackingMove.PreventStrength.Max; } + if (attackingMove.PreventStrength.Min > minPreventStr) { minPreventStr = attackingMove.PreventStrength.Min; @@ -114,24 +118,24 @@ public void AdjudicateMove(Move move) { if (move.AttackStrength.Min > maxPreventStr) { - move.Status = Enums.OrderStatus.Success; + move.Status = OrderStatus.Success; if(move.OpposingMove != null) { move.OpposingMove.Unit.MustRetreat = true; } else if (move.Destination.OrderAtLocation != null && !(move.Destination.OrderAtLocation is Move)) { - move.Destination.OrderAtLocation.Status = Enums.OrderStatus.Failure; + move.Destination.OrderAtLocation.Status = OrderStatus.Failure; move.Destination.OrderAtLocation.Unit.MustRetreat = true; //This also needs to be done if the OrderAtDestination is an unsuccessful move, but that might not be determined yet. //So I'm thinking to maybe remove the MustRetreat line from here from here and calculate which units are dislodged after everything else is done. } - foreach(Move attackingMove in move.Destination.AttackingMoves) + foreach (var attackingMove in move.Destination.AttackingMoves) { if(!Object.ReferenceEquals(attackingMove, move)) { - attackingMove.Status = Enums.OrderStatus.Failure; + attackingMove.Status = OrderStatus.Failure; } } } @@ -140,7 +144,7 @@ public void AdjudicateMove(Move move) if (((move.OpposingMove != null) && (move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min)) || ((move.OpposingMove == null) && (move.AttackStrength.Max <= move.Destination.HoldStrength.Min)) || (move.AttackStrength.Max <= minPreventStr)) { //unsuccessful - move.Status = Enums.OrderStatus.Failure; + move.Status = OrderStatus.Failure; } } @@ -155,15 +159,15 @@ public void OrderStrengthCalculator(Order order) //initialise to base unit strength of 1 order.HoldStrength.Min = 1; order.HoldStrength.Max = 1; - foreach (Support support in order.PotentialSupports) + foreach (var support in order.PotentialSupports) { //all successful supports add 1 to min and max, all unresolved add 1 to max. - if (support.Status == Enums.OrderStatus.Success) + if (support.Status == OrderStatus.Success) { order.HoldStrength.Max += 1; order.HoldStrength.Min += 1; } - else if (support.Status != Enums.OrderStatus.Failure) + else if (support.Status != OrderStatus.Failure) { order.HoldStrength.Max += 1; } @@ -186,12 +190,12 @@ public void MoveStrengthCalculator(Move move) move.PreventStrength.Min = 1; move.PreventStrength.Max = 1; //Hold Strength - if (move.Status == Enums.OrderStatus.Success) + if (move.Status == OrderStatus.Success) { //if a move is successful, its hold strength is 0 move.HoldStrength.Min = 0; move.HoldStrength.Max = 0; - } else if (move.Status = Enums.OrderStatus.Failure) + } else if (move.Status = OrderStatus.Failure) { //if a move fails, its hold strength is 1 move.HoldStrength.Min = 1; @@ -214,7 +218,7 @@ public void MoveStrengthCalculator(Move move) { if(move.Destination.OrderAtLocation is Move) { - if(move.Destination.OrderAtLocation.Status == Enums.OrderStatus.Failure) + if(move.Destination.OrderAtLocation.Status == OrderStatus.Failure) { //if the unit at the destination belongs to the same country and is moving, the attack strength is 0 if that unit fails to move. move.AttackStrength.Min = 0; @@ -222,7 +226,7 @@ public void MoveStrengthCalculator(Move move) minAttackStrengthSet = true; maxAttackStrengthSet = true; } - else if(move.Destination.OrderAtLocation.Status != Enums.OrderStatus.Success) + else if(move.Destination.OrderAtLocation.Status != OrderStatus.Success) { //if that destination move is unresolved, then the min attack strength is the case where it fails. move.AttackStrength.Min = 0; @@ -238,27 +242,31 @@ public void MoveStrengthCalculator(Move move) maxAttackStrengthSet = true; } } + if(!maxAttackStrengthSet) { - foreach(Support support in move.PotentialSupports) + foreach (var support in move.PotentialSupports) { - if (support.Unit.Owner != move.Destination.OrderAtLocation.Unit.Owner || move.Destination.OrderAtLocation.Status == Enums.OrderStatus.Success) + if (support.Unit.Owner != move.Destination.OrderAtLocation.Unit.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) { //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). - if (support.Status == Enums.OrderStatus.Success) + if (support.Status == OrderStatus.Success) { move.AttackStrength.Max += 1; - if (!minAttackStrengthSet) { move.AttackStrength.Min += 1; } + if (!minAttackStrengthSet) + { + move.AttackStrength.Min += 1; + } } - else if (support.Status != Enums.OrderStatus.Failure) + else if (support.Status != OrderStatus.Failure) { move.AttackStrength.Max += 1; } - } else if(move.Destination.OrderAtLocation.Status != Enums.OrderStatus.Failure) + } else if(move.Destination.OrderAtLocation.Status != OrderStatus.Failure) { //if that destination move is unresolved, then a support belonging to the same country can be counted, but only for max strength. - if (support.Status != Enums.OrderStatus.Failure) + if (support.Status != OrderStatus.Failure) { move.AttackStrength.Max += 1; } @@ -266,15 +274,15 @@ public void MoveStrengthCalculator(Move move) } } //Defend Strength - foreach (Support support in move.PotentialSupports) + foreach (var support in move.PotentialSupports) { //all successful supports add 1 to min and max, all unresolved add 1 to max. - if (support.Status == Enums.OrderStatus.Success) + if (support.Status == OrderStatus.Success) { move.DefendStrength.Max += 1; move.DefendStrength.Min += 1; } - else if (support.Status != Enums.OrderStatus.Failure) + else if (support.Status != OrderStatus.Failure) { move.DefendStrength.Max += 1; } @@ -286,32 +294,36 @@ public void MoveStrengthCalculator(Move move) bool maxPreventStrengthSet = false; if (move.OpposingMove != null) { - if(move.OpposingMove.Status == Enums.OrderStatus.Success) + if(move.OpposingMove.Status == OrderStatus.Success) { //if the head to head attacker is successful, a move order has no attack strength move.PreventStrength.Min = 0; move.PreventStrength.Max = 0; minPreventStrengthSet = true; maxPreventStrengthSet = true; - } else if (move.OpposingMove.Status != Enums.OrderStatus.Failure) + } else if (move.OpposingMove.Status != OrderStatus.Failure) { //head to head attacker has not yet been resolved, so minimum value is the case where the head to head attacker is successful move.PreventStrength.Min = 0; minPreventStrengthSet = true; } } + if (!maxPreventStrengthSet) { - foreach (Support support in move.PotentialSupports) + foreach (var support in move.PotentialSupports) { //Min Prevent Str is 1 + number of successful supports, if not already set to 0. //Max Prevent Str is 1 + number of successful or unresolved supports, if not already set to 0. - if (support.Status == Enums.OrderStatus.Success) + if (support.Status == OrderStatus.Success) { move.AttackStrength.Max += 1; - if (!minPreventStrengthSet) { move.PreventStrength.Min += 1; } + if (!minPreventStrengthSet) + { + move.PreventStrength.Min += 1; + } } - else if (support.Status != Enums.OrderStatus.Failure) + else if (support.Status != OrderStatus.Failure) { move.PreventStrength.Max += 1; } From aff76fc126c5de77dc2f7c2db858320a36fb6fa4 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 12:56:00 +0100 Subject: [PATCH 07/15] More bugfixes and formatting fixes --- .../Evaluation/MovementEvaluator.cs | 59 ++++++++++--------- server/Entities/Location.cs | 2 +- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index fc523f2..e39c23a 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -52,8 +52,8 @@ public void AdjudicateMoveViaConvoy(Move move) public void AdjudicateConvoy(Convoy convoy) { - bool unresolved = false; - foreach (Move attackingMove in convoy.Location.AttackingMoves) + var unresolved = false; + foreach (var attackingMove in convoy.Location.AttackingMoves) { if (attackingMove.Status == OrderStatus.Success) { @@ -73,8 +73,8 @@ public void AdjudicateConvoy(Convoy convoy) public void AdjudicateSupport(Support support) { - bool unresolved = false; - foreach (Move attackingMove in support.Location.AttackingMoves) + var unresolved = false; + foreach (var attackingMove in support.Location.AttackingMoves) { if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) { @@ -87,7 +87,7 @@ public void AdjudicateSupport(Support support) //TODO - if AttackingMove is Move via Convoy and AttackingMove is unresolved, then unresolved = true } - if(!unresolved) + if (!unresolved) { support.Status = OrderStatus.Success; } @@ -96,8 +96,8 @@ public void AdjudicateSupport(Support support) public void AdjudicateMove(Move move) { - int maxPreventStr = 0; - int minPreventStr = 0; + var maxPreventStr = 0; + var minPreventStr = 0; foreach (var attackingMove in move.Destination.AttackingMoves) { if (!Object.ReferenceEquals(attackingMove, move)) @@ -114,12 +114,12 @@ public void AdjudicateMove(Move move) } } - if (((move.OpposingMove != null) && (move.AttackStrength.Min > move.OpposingMove.DefendStrength.Max)) || ((move.OpposingMove == null) && (move.AttackStrength.Min > move.Destination.HoldStrength.Max))) + if ((move.OpposingMove != null && move.AttackStrength.Min > move.OpposingMove.DefendStrength.Max) || (move.OpposingMove == null && move.AttackStrength.Min > move.Destination.HoldStrength.Max)) { if (move.AttackStrength.Min > maxPreventStr) { move.Status = OrderStatus.Success; - if(move.OpposingMove != null) + if (move.OpposingMove != null) { move.OpposingMove.Unit.MustRetreat = true; } @@ -133,7 +133,7 @@ public void AdjudicateMove(Move move) foreach (var attackingMove in move.Destination.AttackingMoves) { - if(!Object.ReferenceEquals(attackingMove, move)) + if (!Object.ReferenceEquals(attackingMove, move)) { attackingMove.Status = OrderStatus.Failure; } @@ -141,7 +141,7 @@ public void AdjudicateMove(Move move) } } - if (((move.OpposingMove != null) && (move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min)) || ((move.OpposingMove == null) && (move.AttackStrength.Max <= move.Destination.HoldStrength.Min)) || (move.AttackStrength.Max <= minPreventStr)) + if ((move.OpposingMove != null && move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min) || (move.OpposingMove == null && move.AttackStrength.Max <= move.Destination.HoldStrength.Min) || (move.AttackStrength.Max <= minPreventStr)) { //unsuccessful move.Status = OrderStatus.Failure; @@ -150,10 +150,11 @@ public void AdjudicateMove(Move move) public void OrderStrengthCalculator(Order order) { - if(order is Move) + if (order is Move) { MoveStrengthCalculator(order); - } else + } + else { //for all other order types, we only need Hold Strength //initialise to base unit strength of 1 @@ -195,12 +196,14 @@ public void MoveStrengthCalculator(Move move) //if a move is successful, its hold strength is 0 move.HoldStrength.Min = 0; move.HoldStrength.Max = 0; - } else if (move.Status = OrderStatus.Failure) + } + else if (move.Status == OrderStatus.Failure) { //if a move fails, its hold strength is 1 move.HoldStrength.Min = 1; move.HoldStrength.Max = 1; - } else + } + else { //if unknown resolution, could be 0 or 1 move.HoldStrength.Min = 0; @@ -212,13 +215,13 @@ public void MoveStrengthCalculator(Move move) //Attack Strength //TODO - this still needs convoy logic. If the move is via convoy the min strength is always 0 until a Successful path is determined. - bool minAttackStrengthSet = false; - bool maxAttackStrengthSet = false; - if(move.Destination.OrderAtLocation != null && move.Unit.Owner == move.Destination.OrderAtLocation.Unit.Owner) + var minAttackStrengthSet = false; + var maxAttackStrengthSet = false; + if (move.Destination.OrderAtLocation != null && move.Unit.Owner == move.Destination.OrderAtLocation.Unit.Owner) { - if(move.Destination.OrderAtLocation is Move) + if (move.Destination.OrderAtLocation is Move) { - if(move.Destination.OrderAtLocation.Status == OrderStatus.Failure) + if (move.Destination.OrderAtLocation.Status == OrderStatus.Failure) { //if the unit at the destination belongs to the same country and is moving, the attack strength is 0 if that unit fails to move. move.AttackStrength.Min = 0; @@ -226,7 +229,7 @@ public void MoveStrengthCalculator(Move move) minAttackStrengthSet = true; maxAttackStrengthSet = true; } - else if(move.Destination.OrderAtLocation.Status != OrderStatus.Success) + else if (move.Destination.OrderAtLocation.Status != OrderStatus.Success) { //if that destination move is unresolved, then the min attack strength is the case where it fails. move.AttackStrength.Min = 0; @@ -243,7 +246,7 @@ public void MoveStrengthCalculator(Move move) } } - if(!maxAttackStrengthSet) + if (!maxAttackStrengthSet) { foreach (var support in move.PotentialSupports) { @@ -263,7 +266,8 @@ public void MoveStrengthCalculator(Move move) { move.AttackStrength.Max += 1; } - } else if(move.Destination.OrderAtLocation.Status != OrderStatus.Failure) + } + else if (move.Destination.OrderAtLocation.Status != OrderStatus.Failure) { //if that destination move is unresolved, then a support belonging to the same country can be counted, but only for max strength. if (support.Status != OrderStatus.Failure) @@ -290,18 +294,19 @@ public void MoveStrengthCalculator(Move move) //Prevent Strength //TODO - this also still needs convoy logic. Will be same as Attack Strength. - bool minPreventStrengthSet = false; - bool maxPreventStrengthSet = false; + var minPreventStrengthSet = false; + var maxPreventStrengthSet = false; if (move.OpposingMove != null) { - if(move.OpposingMove.Status == OrderStatus.Success) + if (move.OpposingMove.Status == OrderStatus.Success) { //if the head to head attacker is successful, a move order has no attack strength move.PreventStrength.Min = 0; move.PreventStrength.Max = 0; minPreventStrengthSet = true; maxPreventStrengthSet = true; - } else if (move.OpposingMove.Status != OrderStatus.Failure) + } + else if (move.OpposingMove.Status != OrderStatus.Failure) { //head to head attacker has not yet been resolved, so minimum value is the case where the head to head attacker is successful move.PreventStrength.Min = 0; diff --git a/server/Entities/Location.cs b/server/Entities/Location.cs index 550df3d..6757519 100644 --- a/server/Entities/Location.cs +++ b/server/Entities/Location.cs @@ -32,5 +32,5 @@ public bool Equals(Location? other) public OrderStrength HoldStrength { get; set; } = new(); [NotMapped] - public Order OrderAtLocation { get; set; } + public virtual Order? OrderAtLocation { get; set; } } From 27295637aeee860f4c4488c2f0d411c1e3acfda5 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 13:06:06 +0100 Subject: [PATCH 08/15] More bugfixes --- server/Adjudication/Evaluation/MovementEvaluator.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index e39c23a..2c39cb7 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -121,12 +121,12 @@ public void AdjudicateMove(Move move) move.Status = OrderStatus.Success; if (move.OpposingMove != null) { - move.OpposingMove.Unit.MustRetreat = true; + move.OpposingMove.Unit!.MustRetreat = true; } else if (move.Destination.OrderAtLocation != null && !(move.Destination.OrderAtLocation is Move)) { move.Destination.OrderAtLocation.Status = OrderStatus.Failure; - move.Destination.OrderAtLocation.Unit.MustRetreat = true; + move.Destination.OrderAtLocation.Unit!.MustRetreat = true; //This also needs to be done if the OrderAtDestination is an unsuccessful move, but that might not be determined yet. //So I'm thinking to maybe remove the MustRetreat line from here from here and calculate which units are dislodged after everything else is done. } @@ -150,9 +150,9 @@ public void AdjudicateMove(Move move) public void OrderStrengthCalculator(Order order) { - if (order is Move) + if (order is Move move) { - MoveStrengthCalculator(order); + MoveStrengthCalculator(move); } else { @@ -217,7 +217,7 @@ public void MoveStrengthCalculator(Move move) //TODO - this still needs convoy logic. If the move is via convoy the min strength is always 0 until a Successful path is determined. var minAttackStrengthSet = false; var maxAttackStrengthSet = false; - if (move.Destination.OrderAtLocation != null && move.Unit.Owner == move.Destination.OrderAtLocation.Unit.Owner) + if (move.Destination.OrderAtLocation != null && move.Unit!.Owner == move.Destination.OrderAtLocation.Unit!.Owner) { if (move.Destination.OrderAtLocation is Move) { @@ -250,7 +250,7 @@ public void MoveStrengthCalculator(Move move) { foreach (var support in move.PotentialSupports) { - if (support.Unit.Owner != move.Destination.OrderAtLocation.Unit.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) + if (support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) { //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). From fda46b40d0beaf7d468c2d768341110e9f673dcb Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 13:11:24 +0100 Subject: [PATCH 09/15] Formatting fixes --- .../Adjudication/Evaluation/MovementEvaluator.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 2c39cb7..394464b 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -45,10 +45,10 @@ public void InitialiseAdjudication() } } - public void AdjudicateMoveViaConvoy(Move move) - { - //TODO - } + //public void AdjudicateMoveViaConvoy(Move move) + //{ + //TODO + //} public void AdjudicateConvoy(Convoy convoy) { @@ -114,7 +114,7 @@ public void AdjudicateMove(Move move) } } - if ((move.OpposingMove != null && move.AttackStrength.Min > move.OpposingMove.DefendStrength.Max) || (move.OpposingMove == null && move.AttackStrength.Min > move.Destination.HoldStrength.Max)) + if (move.OpposingMove != null && move.AttackStrength.Min > move.OpposingMove.DefendStrength.Max || move.OpposingMove == null && move.AttackStrength.Min > move.Destination.HoldStrength.Max) { if (move.AttackStrength.Min > maxPreventStr) { @@ -123,7 +123,7 @@ public void AdjudicateMove(Move move) { move.OpposingMove.Unit!.MustRetreat = true; } - else if (move.Destination.OrderAtLocation != null && !(move.Destination.OrderAtLocation is Move)) + else if (move.Destination.OrderAtLocation != null && move.Destination.OrderAtLocation is not Move) { move.Destination.OrderAtLocation.Status = OrderStatus.Failure; move.Destination.OrderAtLocation.Unit!.MustRetreat = true; @@ -141,7 +141,7 @@ public void AdjudicateMove(Move move) } } - if ((move.OpposingMove != null && move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min) || (move.OpposingMove == null && move.AttackStrength.Max <= move.Destination.HoldStrength.Min) || (move.AttackStrength.Max <= minPreventStr)) + if (move.OpposingMove != null && move.AttackStrength.Max <= move.OpposingMove.DefendStrength.Min || move.OpposingMove == null && move.AttackStrength.Max <= move.Destination.HoldStrength.Min || move.AttackStrength.Max <= minPreventStr) { //unsuccessful move.Status = OrderStatus.Failure; From 302ae9fc466b681f6c8b7b03f4e2e60071574319 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 13:21:06 +0100 Subject: [PATCH 10/15] Fixed a null pointer issue --- server/Adjudication/Evaluation/MovementEvaluator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 394464b..f528280 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -39,7 +39,7 @@ public void InitialiseAdjudication() foreach (var support in activeOrders.OfType()) { //add each support to the PotentialSupports list in the corresponding order - support.Midpoint.OrderAtLocation.PotentialSupports.Add(support); + support.Midpoint.OrderAtLocation!.PotentialSupports.Add(support); AdjudicateSupport(support); } @@ -250,7 +250,7 @@ public void MoveStrengthCalculator(Move move) { foreach (var support in move.PotentialSupports) { - if (support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) + if (move.Destination.OrderAtLocation != null && support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) { //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). From d8ad3c4cfce27150cb15b4afd788a92cb397da63 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 13:28:14 +0100 Subject: [PATCH 11/15] Formatting fixes Removed a lot of trailing spaces, and fixed a null pointer issue --- .../Evaluation/MovementEvaluator.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index f528280..4ff1766 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -250,23 +250,23 @@ public void MoveStrengthCalculator(Move move) { foreach (var support in move.PotentialSupports) { - if (move.Destination.OrderAtLocation != null && support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) + if (move.Destination.OrderAtLocation != null && (support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success)) { //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). if (support.Status == OrderStatus.Success) { move.AttackStrength.Max += 1; - if (!minAttackStrengthSet) - { - move.AttackStrength.Min += 1; + if (!minAttackStrengthSet) + { + move.AttackStrength.Min += 1; } } else if (support.Status != OrderStatus.Failure) { move.AttackStrength.Max += 1; } - } + } else if (move.Destination.OrderAtLocation.Status != OrderStatus.Failure) { //if that destination move is unresolved, then a support belonging to the same country can be counted, but only for max strength. @@ -305,7 +305,7 @@ public void MoveStrengthCalculator(Move move) move.PreventStrength.Max = 0; minPreventStrengthSet = true; maxPreventStrengthSet = true; - } + } else if (move.OpposingMove.Status != OrderStatus.Failure) { //head to head attacker has not yet been resolved, so minimum value is the case where the head to head attacker is successful @@ -323,9 +323,9 @@ public void MoveStrengthCalculator(Move move) if (support.Status == OrderStatus.Success) { move.AttackStrength.Max += 1; - if (!minPreventStrengthSet) - { - move.PreventStrength.Min += 1; + if (!minPreventStrengthSet) + { + move.PreventStrength.Min += 1; } } else if (support.Status != OrderStatus.Failure) From d7dc095f658c43a15b569c986b788d69e64f6114 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 13:42:30 +0100 Subject: [PATCH 12/15] More bugfixes --- server/Adjudication/Evaluation/MovementEvaluator.cs | 2 +- server/Entities/Location.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 4ff1766..7eaf4d2 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -250,7 +250,7 @@ public void MoveStrengthCalculator(Move move) { foreach (var support in move.PotentialSupports) { - if (move.Destination.OrderAtLocation != null && (support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success)) + if (move.Destination.OrderAtLocation == null || support.Unit!.Owner != move.Destination.OrderAtLocation.Unit!.Owner || move.Destination.OrderAtLocation.Status == OrderStatus.Success) { //a support will not add to the attack strength if it belongs to the same country as the unit at the destination, unless that destination move was successful //otherwise all successful supports add to the min and max str, and all unresolved supports add to the max str (where min and max have not been set to 0 previously). diff --git a/server/Entities/Location.cs b/server/Entities/Location.cs index 6757519..cfe0fd2 100644 --- a/server/Entities/Location.cs +++ b/server/Entities/Location.cs @@ -26,7 +26,7 @@ public bool Equals(Location? other) public override int GetHashCode() => (Timeline, Year, Phase, RegionId).GetHashCode(); [NotMapped] - public List AttackingMoves { get; set; } = new List(); + public List AttackingMoves { get; set; } = new(); [NotMapped] public OrderStrength HoldStrength { get; set; } = new(); From 7d1f1fcdc3947f7fab5a5ae036d1383bc7b05fbf Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 15:54:05 +0100 Subject: [PATCH 13/15] Formatting fixes --- server/Adjudication/Evaluation/MovementEvaluator.cs | 2 +- server/Entities/Location.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 7eaf4d2..e112bfa 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -76,7 +76,7 @@ public void AdjudicateSupport(Support support) var unresolved = false; foreach (var attackingMove in support.Location.AttackingMoves) { - if (!Object.ReferenceEquals(support.Midpoint,support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) + if (!Object.ReferenceEquals(support.Midpoint, support.Destination) && !Object.ReferenceEquals(support.Destination, attackingMove.Location)) { support.Status = OrderStatus.Failure; } diff --git a/server/Entities/Location.cs b/server/Entities/Location.cs index cfe0fd2..451689c 100644 --- a/server/Entities/Location.cs +++ b/server/Entities/Location.cs @@ -26,7 +26,7 @@ public bool Equals(Location? other) public override int GetHashCode() => (Timeline, Year, Phase, RegionId).GetHashCode(); [NotMapped] - public List AttackingMoves { get; set; } = new(); + public List AttackingMoves { get; set; } = []; [NotMapped] public OrderStrength HoldStrength { get; set; } = new(); From 3d51dcd62b3e467cc7b3887ee7a6b1134070a270 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 16:15:27 +0100 Subject: [PATCH 14/15] Bugfix --- server/Adjudication/Evaluation/MovementEvaluator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index e112bfa..3f0530a 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -123,7 +123,7 @@ public void AdjudicateMove(Move move) { move.OpposingMove.Unit!.MustRetreat = true; } - else if (move.Destination.OrderAtLocation != null && move.Destination.OrderAtLocation is not Move) + else if (move.Destination.OrderAtLocation is not null && move.Destination.OrderAtLocation is not Move) { move.Destination.OrderAtLocation.Status = OrderStatus.Failure; move.Destination.OrderAtLocation.Unit!.MustRetreat = true; From b6b3fc39c8e61d361702b96c0a7deb2d5c5a4c55 Mon Sep 17 00:00:00 2001 From: CaptainMeme Date: Sat, 7 Sep 2024 16:25:29 +0100 Subject: [PATCH 15/15] Fixed formatting --- server/Adjudication/Evaluation/MovementEvaluator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Adjudication/Evaluation/MovementEvaluator.cs b/server/Adjudication/Evaluation/MovementEvaluator.cs index 3f0530a..3b42992 100644 --- a/server/Adjudication/Evaluation/MovementEvaluator.cs +++ b/server/Adjudication/Evaluation/MovementEvaluator.cs @@ -123,7 +123,7 @@ public void AdjudicateMove(Move move) { move.OpposingMove.Unit!.MustRetreat = true; } - else if (move.Destination.OrderAtLocation is not null && move.Destination.OrderAtLocation is not Move) + else if (move.Destination.OrderAtLocation is not null or Move) { move.Destination.OrderAtLocation.Status = OrderStatus.Failure; move.Destination.OrderAtLocation.Unit!.MustRetreat = true;