public Result PerformAction(IGameAction <TGameModel> gameAction, ref TGameModel game) { Result result = gameAction.Validate(game); if (!result.Success) { return(result); } try { return(gameAction.Perform(ref game)); } catch (Exception e) { return(Result.Create(false, new[] { $"{gameAction} was valid, but threw an exception: {e.Message}" })); } }
public Optional.Option <Engine, IEnumerable <string> > Perform( [NotNull] IGameAction action) { var rules = this.Rules.GetValueOrDefault(action.GetType()); if (rules == null) { return(Option.None <Engine, IEnumerable <string> >(new string[] { $"Engine does not not {action.GetType().FullName} actions" })); } if (!rules.All(rule => rule.Verify(this, action))) { return(Option.None <Engine, IEnumerable <string> >(new string[] {})); } var newEngine = Engine.NextTurn(action.Perform(this)); return(Option.Some <Engine, IEnumerable <string> >(newEngine)); }