Implement repl adjudication

This commit is contained in:
Tim Van Baak 2024-08-28 14:41:23 +00:00
parent f77cc60185
commit f02e71d4f9
1 changed files with 19 additions and 6 deletions

View File

@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using MultiversalDiplomacy.Adjudicate;
using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
@ -31,19 +32,31 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
// "---" submits the orders and allows queries about the outcome
if (input == "---") {
Console.WriteLine("Submitting orders for adjudication");
// TODO submit, validate, and adjudicate orders
// TODO pass validation, adjudication, and prev/next World to next handler
return new AdjudicationQueryScriptHandler(World, Strict);
var adjudicator = MovementPhaseAdjudicator.Instance;
var validation = adjudicator.ValidateOrders(World, Orders);
var validOrders = validation
.Where(v => v.Valid)
.Select(v => v.Order)
.ToList();
var adjudication = adjudicator.AdjudicateOrders(World, validOrders);
var newWorld = adjudicator.UpdateWorld(World, adjudication);
return new AdjudicationQueryScriptHandler(newWorld, Strict);
}
// "===" submits the orders and moves immediately to taking the next set of orders
// i.e. it's "---" twice
if (input == "===") {
Console.WriteLine("Submitting orders for adjudication");
// TODO submit, validate, and adjudicate orders
// TODO replace World with updated world and return a new handler
var adjudicator = MovementPhaseAdjudicator.Instance;
var validation = adjudicator.ValidateOrders(World, Orders);
var validOrders = validation
.Where(v => v.Valid)
.Select(v => v.Order)
.ToList();
var adjudication = adjudicator.AdjudicateOrders(World, validOrders);
World = adjudicator.UpdateWorld(World, adjudication);
Console.WriteLine("Ready for orders");
return new GameScriptHandler(World, Strict);
return this;
}
// A block of orders for a single power beginning with "{name}:"