public List <IUnitCommand> GetCommandsForUnit(IUnit unit, InfluenceMaps maps) { var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit); var reachableCellsByDistance = HexPathfinder.GetAllCellsReachableIn( unitLocation, unit.CurrentMovement, UnitPositionCanon.GetPathfindingCostFunction(unit, false), Grid.Cells ); var validCandidates = reachableCellsByDistance.Keys.Where(cell => UnitPositionCanon.CanPlaceUnitAtLocation(unit, cell, false)); IHexCell bestCandidate = validCandidates.MaxElement(BrainTools.GetFleeWeightFunction(unit, maps)); var retval = new List <IUnitCommand>(); if (bestCandidate != null) { var moveCommand = Container.Instantiate <MoveUnitCommand>(); moveCommand.UnitToMove = unit; moveCommand.DesiredLocation = bestCandidate; retval.Add(moveCommand); } return(retval); }