Exemplo n.º 1
0
        public void Load(string path)
        {
            Clean();
            var loadedProgress = _stateLoader.Load(path);

            ReloadHints(loadedProgress.Goal);
            BuildGame(loadedProgress);
        }
Exemplo n.º 2
0
        private static FrequenciesAndNumRows FindStateForParticularGrouping(IEnumerable <IGroupingAnalyzer <IMetric> >
                                                                            analyzers, IStateLoader stateLoader)
        {
            /* One of the analyzers must have the state persisted */
            IEnumerable <Option <FrequenciesAndNumRows> > states = analyzers.Select(analyzer =>
                                                                                    stateLoader.Load <FrequenciesAndNumRows>(
                                                                                        (Analyzer <FrequenciesAndNumRows, IMetric>)analyzer));


            return(states.FirstOrDefault().Value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Aggregates two states loaded by the state loader and saves the resulting aggregation using the target state
        /// persister.
        /// </summary>
        /// <param name="sourceA">The first state to load <see cref="IStateLoader"/></param>
        /// <param name="sourceB">The second state to load <see cref="IStateLoader"/></param>
        /// <param name="target">The target persister <see cref="IStatePersister"/></param>
        public void AggregateStateTo(IStateLoader sourceA, IStateLoader sourceB, IStatePersister target)
        {
            Option <S> maybeStateA = sourceA.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));
            Option <S> maybeStateB = sourceB.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));

            S aggregated = (maybeStateA.HasValue, maybeStateB.HasValue) switch
            {
                (true, true) => maybeStateA.Value.Sum(maybeStateB.Value),
                (true, false) => maybeStateA.Value,
                (false, true) => maybeStateB.Value,
                _ => null
            };

            target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), new Option <S>(aggregated));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Copy the state from source to target.
 /// </summary>
 /// <param name="source">The <see cref="IStateLoader"/> to read from.</param>
 /// <param name="target">The <see cref="IStatePersister"/> to write to.</param>
 public void CopyStateTo(IStateLoader source, IStatePersister target) =>
 target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), source.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this)));
Exemplo n.º 5
0
 /// <summary>
 /// Load the <see cref="State{T}"/> from a <see cref="IStateLoader"/> and compute the <see cref="Metric{T}"/>
 /// </summary>
 /// <param name="source">The <see cref="IStateLoader"/>.</param>
 /// <returns>Returns the computed <see cref="Metric{T}"/>.</returns>
 public M LoadStateAndComputeMetric(IStateLoader source) =>
 ComputeMetricFrom(source.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this)));
Exemplo n.º 6
0
 public BattleState(IViewBase viewBase, IStateLoader loader, ITimeSimulater simulater)
 {
     ViewBase   = viewBase;
     Perception = new BattlePerception(this, viewBase.Create(simulater));
     loader.Load(this);
 }