Add adjudicate command and implement AdjudicateOrders

This commit is contained in:
Jaculabilis 2023-04-06 19:15:28 -07:00 committed by Tim Van Baak
parent c5bd74ae1e
commit fa04aab6c6
6 changed files with 67 additions and 4 deletions

View File

@ -8,6 +8,18 @@ namespace MultiversalDiplomacy.Adjudicate;
/// </summary>
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>
/// 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

View File

@ -19,6 +19,11 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
this.logger = logger;
}
public List<Order> ParseOrderSets(World world, List<OrderSet> orderSets)
{
throw new NotImplementedException();
}
public List<OrderValidation> ValidateOrders(World world, List<Order> orders)
{
// 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.Orders;
namespace MultiversalDiplomacy;
@ -21,9 +23,28 @@ public static class GameController
public static World AdjudicateOrders(World world)
{
// TODO: Parse the order sets into orders
// TODO: Execute the correct adjudicator for the current world state
// TODO: Update the world
return world;
// Determine which phase the game is in, which determines how orders should be interpreted and adjudicated.
PhaseType phaseType = world.GetNextPhaseType();
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;
}
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>
/// The standard Diplomacy provinces.
/// </summary>

View File

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