2023-04-07 02:15:28 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate;
|
2022-12-31 20:06:03 +00:00
|
|
|
using MultiversalDiplomacy.Model;
|
2023-04-07 02:15:28 +00:00
|
|
|
using MultiversalDiplomacy.Orders;
|
2022-12-31 20:06:03 +00:00
|
|
|
|
|
|
|
namespace MultiversalDiplomacy;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The game controller is a stateless class that defines the basic, high-level operations that can be taken to modify
|
|
|
|
/// the game state.
|
|
|
|
/// </summary>
|
|
|
|
public static class GameController
|
|
|
|
{
|
|
|
|
public static World InitializeWorld()
|
|
|
|
{
|
|
|
|
return World.Standard;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static World SubmitOrderSet(World world, string text)
|
|
|
|
{
|
|
|
|
var orderSet = new OrderSet(text);
|
|
|
|
return world.Update(orderSets: world.OrderSets.Append(orderSet));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static World AdjudicateOrders(World world)
|
|
|
|
{
|
2023-04-07 02:15:28 +00:00
|
|
|
// 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);
|
2022-12-31 20:06:03 +00:00
|
|
|
}
|
|
|
|
}
|