Add adjudicate command and implement AdjudicateOrders

This commit is contained in:
Jaculabilis 2023-04-06 19:15:28 -07:00
parent 26329e9186
commit 3cde558d33
6 changed files with 67 additions and 4 deletions

View File

@ -8,6 +8,18 @@ namespace MultiversalDiplomacy.Adjudicate;
/// </summary> /// </summary>
public interface IPhaseAdjudicator public interface IPhaseAdjudicator
{ {
/// <summary>
/// Given a list of order sets, determine which entries are comprehensible as orders.
/// An order set entry may comprehensible as an order but not valid for the current
/// phase; these orders will be rejected by <see cref="ValidateOrders"/>.
/// </summary>
/// <param name="world">The global game state.</param>
/// <param name="orderSets">The order sets to adjudicate.</param>
/// <returns>
/// A list of <see cref="Order"/> objects representing the orders parsed.
/// </returns>
public List<Order> ParseOrderSets(World world, List<OrderSet> orderSets);
/// <summary> /// <summary>
/// Given a list of orders, determine which orders are valid for this adjudicator and /// Given a list of orders, determine which orders are valid for this adjudicator and
/// which should be rejected before adjudication. Adjudication should be performed on /// which should be rejected before adjudication. Adjudication should be performed on

View File

@ -19,6 +19,11 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
this.logger = logger; this.logger = logger;
} }
public List<Order> ParseOrderSets(World world, List<OrderSet> orderSets)
{
throw new NotImplementedException();
}
public List<OrderValidation> ValidateOrders(World world, List<Order> orders) public List<OrderValidation> ValidateOrders(World world, List<Order> orders)
{ {
// The basic workflow of this function will be to look for invalid orders, remove these // The basic workflow of this function will be to look for invalid orders, remove these

View File

@ -1,4 +1,6 @@
using MultiversalDiplomacy.Adjudicate;
using MultiversalDiplomacy.Model; using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
namespace MultiversalDiplomacy; namespace MultiversalDiplomacy;
@ -21,9 +23,28 @@ public static class GameController
public static World AdjudicateOrders(World world) public static World AdjudicateOrders(World world)
{ {
// TODO: Parse the order sets into orders // Determine which phase the game is in, which determines how orders should be interpreted and adjudicated.
// TODO: Execute the correct adjudicator for the current world state PhaseType phaseType = world.GetNextPhaseType();
// TODO: Update the world
return world; IPhaseAdjudicator adjudicator = phaseType switch {
PhaseType.Movement => MovementPhaseAdjudicator.Instance,
PhaseType.Retreat => throw new NotImplementedException(),
PhaseType.Build => throw new NotImplementedException(),
PhaseType.Sustain => throw new NotImplementedException(),
_ => throw new InvalidOperationException(phaseType.ToString()),
};
// Parse the order sets into actual orders.
List<Order> parsedOrders = adjudicator.ParseOrderSets(world, world.OrderSets.ToList());
// Validate the orders.
var orderValidations = adjudicator.ValidateOrders(world, parsedOrders);
// Adjudicate the orders.
var validOrders = orderValidations.Where(v => v.Valid).Select(v => v.Order).ToList();
var results = adjudicator.AdjudicateOrders(world, validOrders);
// Update the world.
return adjudicator.UpdateWorld(world, results);
} }
} }

View File

@ -0,0 +1,9 @@
namespace MultiversalDiplomacy.Model;
public enum PhaseType
{
Movement = 1,
Retreat = 2,
Build = 3,
Sustain = 4,
}

View File

@ -309,6 +309,17 @@ public class World
return foundUnit; return foundUnit;
} }
public PhaseType GetNextPhaseType()
{
// TODO: Figure how to order build and sustain phases in a staggered multiverse
if (RetreatingUnits.Any())
{
return PhaseType.Retreat;
}
return PhaseType.Movement;
}
/// <summary> /// <summary>
/// The standard Diplomacy provinces. /// The standard Diplomacy provinces.
/// </summary> /// </summary>

View File

@ -30,11 +30,16 @@ public class GameScriptHandler : IScriptHandler
case "help": case "help":
case "?": case "?":
Console.WriteLine("commands:"); Console.WriteLine("commands:");
Console.WriteLine(" adjudicate: adjudicate the current orders");
Console.WriteLine(" list: list things in a game category"); Console.WriteLine(" list: list things in a game category");
Console.WriteLine(" orders: submit order sets"); Console.WriteLine(" orders: submit order sets");
Console.WriteLine(" status: overview of the state of the game"); Console.WriteLine(" status: overview of the state of the game");
break; break;
case "adjudicate":
World = GameController.AdjudicateOrders(World);
break;
case "list" when args.Length == 1: case "list" when args.Length == 1:
Console.WriteLine("usage:"); Console.WriteLine("usage:");
Console.WriteLine(" list ordersets: unadjudicated order sets"); Console.WriteLine(" list ordersets: unadjudicated order sets");