//Get the best node to move to private Action GetBestMoveToNode(FactoryNode destinationNode, IEnumerable <FactoryNode> myNodes, bool requireUpperHand) { var myDirectLink = destinationNode.LinkedNodes .Where(n => n.IsMine && (!requireUpperHand || n.NrOfCyborgs > destinationNode.NrOfCyborgs)) .OrderByDescending(n => n.NrOfCyborgs) .FirstOrDefault(); int amountToSend = requireUpperHand ? destinationNode.NrOfCyborgs : (int)Math.Ceiling((myDirectLink?.NrOfCyborgs ?? 0) / 2.0); return(myDirectLink != null?GenerateMovementAction(myDirectLink, destinationNode, amountToSend) : null); }
//Generate a movement and substract the amount of troops private Action GenerateMovementAction(FactoryNode from, FactoryNode to, int amountOfTroops) { if (!from.IsMine) { throw new Exception($"Attempting to send from node {from} which is not ours"); } if (from.NrOfCyborgs < amountOfTroops) { Log($"!! Sending all or more troops ({amountOfTroops}) than available from {from}"); } from.NrOfCyborgs = from.NrOfCyborgs - amountOfTroops; return(new MoveTroopsAction() { From = from.NodeIndex, To = to.NodeIndex, AmountOfTroops = amountOfTroops }); }