From f02e71d4f94f23af529d6b1ab11b03963e06cc93 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 28 Aug 2024 14:41:23 +0000 Subject: [PATCH] Implement repl adjudication --- .../Script/GameScriptHandler.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/MultiversalDiplomacy/Script/GameScriptHandler.cs b/MultiversalDiplomacy/Script/GameScriptHandler.cs index 35214ac..dda1d80 100644 --- a/MultiversalDiplomacy/Script/GameScriptHandler.cs +++ b/MultiversalDiplomacy/Script/GameScriptHandler.cs @@ -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}:"