Beispiel #1
0
        public static Algorithm Parse(
            string baseName,
            IState initialState,
            IState finalState,
            XElement element,
            Solver solver)
        {
            var(algorithm, colors) = GetBaseAlgorithm(element, solver);

            algorithm = algorithm
                        .WithName(BuildName(baseName, element.Attribute(nameof(Algorithm.Name))?.Value))
                        .WithDescription(element.Element(nameof(Algorithm.Description))?.Value);

            var movesText = element.Element(nameof(Algorithm.Moves))?.Value;

            if (!string.IsNullOrWhiteSpace(movesText))
            {
                algorithm = algorithm.WithMoves(ParseMoves(movesText));
            }

            var myInitialState  = GetState(initialState, element.Element(nameof(Algorithm.InitialState)), solver);
            var myFinishedState = GetState(finalState, element.Element(nameof(Algorithm.FinishedState)), solver);

            return(algorithm
                   .WithInitialState(AndState.Combine(algorithm.InitialState, myInitialState))
                   .WithFinishedState(AndState.Combine(algorithm.FinishedState, myFinishedState))
                   .WithColors(colors));
        }
 public Algorithm WithInitialState(IState state)
 => state == this.InitialState
     ? this
     : new Algorithm(
     this.Name,
     this.Description,
     AndState.Combine(this.InitialState, state),
     this.FinishedState,
     this.Moves);