/// <summary>
 /// Creation of the VisualNovelManager
 /// </summary>
 private VisualNovelManager()
 {
     this.EpisodeManager   = EpisodeManager.Instance;
     this.CharacterManager = CharacterManager.Instance;
     SavingPointOriginator = new SavingPointOriginator();
     this.history          = new List <SavingPointMemento>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MovingObstacle"/> class.
 /// </summary>
 /// <param name="position">The initial position.</param>
 /// <param name="type">The type of the obstacle.</param>
 public MovingObstacle(GridPosition position, MovingObstacleType type)
     : base(position)
 {
     this.type = type;
     this.PossibleMovements = MovementAction.VonNeumannNeighbourhoodMovements();
     EpisodeManager.AddEpisodeChangesReceiver(this);
 }
Exemple #3
0
    /// <summary>
    /// Initializes a new instance of the <see cref="StatisticsWriter"/> class.
    /// </summary>
    /// <param name="paramSet">The set of project parameters.</param>
    public StatisticsWriter(Garden garden, ParamSet paramSet)
    {
        this.garden             = garden;
        this.statisticsFileName = paramSet.StringParam(ParamSet.ParamGroupStatisticsWriter, ParamSet.ParamStatisticsFileName);
        GameObject stepGenGameObject = GameObject.FindGameObjectWithTag("StepGenerator");

        this.stepGenerator = stepGenGameObject.GetComponent <StepGenerator>();
        EpisodeManager.AddEpisodeChangesReceiver(this);
        // Write the statistics headline into the csv file
        WriteValuesIntoCSVLine(new string[] { statisticsNameEpisode, statisticsNameStepsNeeded });
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelTable"/> class as an internal model of the garden.
 /// </summary>
 /// <param name="gardenWidth">The garden width.</param>
 /// <param name="gardenHeight">The garden height.</param>
 /// <param name="mowerMovements">All movements the mower can perform.</param>
 /// <param name="mowReward">The reward granted for successfully mowing one tile of the garden.</param>
 /// <param name="notMownReward">The reward granted for moving onto a garden tile without grass to mow.</param>
 /// <param name="deserializeFromFile">The file where this <see cref="T:ModelTable"/> should be deserialized from. Can be null.</param>
 public ModelTable(uint gardenWidth, uint gardenHeight, List <MovementAction> mowerMovements, float mowReward, float notMownReward, string deserializeFromFile = null)
 {
     InitGardenModel(gardenWidth, gardenHeight);
     this.mowerMovements = new List <MovementAction>(mowerMovements);
     this.mowReward      = mowReward;
     this.notMownReward  = notMownReward;
     if (deserializeFromFile != null && deserializeFromFile.Length > 0)
     {
         DeserializeTableFromFile(deserializeFromFile);
     }
     EpisodeManager.AddEpisodeChangesReceiver(this);
 }
Exemple #5
0
 public ShowService(
     IMappingEngine mappingEngine, 
     ShowManager showManager, 
     EpisodeManager episodeManager, 
     SubscriptionManager subscriptionManager, 
     IFetcher fetcher)
 {
     this.MappingEngine = mappingEngine;
     this.ShowManager = showManager;
     this.EpisodeManager = episodeManager;
     this.SubscriptionManager = subscriptionManager;
     this.Fetcher = fetcher;
 }
Exemple #6
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Garden"/> class.
    /// Since this is a heavy-weight constructor with lots of error-potential if used incorrectly,
    /// all Garden objects should be created using the <see cref="T:GardenFactory"/>.
    /// </summary>
    /// <param name="gardenWidth">The garden width.</param>
    /// <param name="gardenHeight">The garden height.</param>
    /// <param name="tiles">A list of all tiles of the garden. Must contain <paramref name="gardenWidth"/> times <paramref name="gardenHeight"/> tiles</param>.
    /// <param name="mowerStartPosition">The start position of the mower robot.</param>
    /// <param name="movingObstacles">A list of all moving obstacles in the garden.</param>
    /// <param name="staticObstacles">A list of all static obstacles in the garden.</param>
    /// <param name="paramSet">The set of parameters for this project.</param>
    public Garden(uint gardenWidth, uint gardenHeight,
                  List <Tile> tiles,
                  GridPosition mowerStartPosition,
                  List <MovingObstacle> movingObstacles,
                  List <StaticObstacle> staticObstacles,
                  ParamSet paramSet)
    {
        this.GardenWidth        = gardenWidth;
        this.GardenHeigth       = gardenHeight;
        this.Tiles              = tiles;
        this.MowerStartPosition = mowerStartPosition;
        this.MovingObstacles    = movingObstacles;
        this.StaticObstacles    = staticObstacles;

        this.NumGrassTiles = 0;
        foreach (var tile in Tiles)
        {
            if (tile.GetMowStatus() == Tile.MowStatus.LongGrass)
            {
                this.NumGrassTiles++;
            }
        }
        Debug.Log(string.Format("Garden initialized with {0} tiles to mow", this.NumGrassTiles));

        // Create the mower agent.
        mower = new Mower(MowerStartPosition, this, paramSet);
        mower.AddObserver(this);

        foreach (var movingObstacle in MovingObstacles)
        {
            movingObstacle.AddObserver(this);
        }

        // Receive episode changes.
        EpisodeManager.AddEpisodeChangesReceiver(this);

        // Receive a step-call after each time-step.
        GameObject    stepGenGameObject = GameObject.FindGameObjectWithTag("StepGenerator");
        StepGenerator stepGen           = stepGenGameObject.GetComponent <StepGenerator>();

        stepGen.AddStepReceiver(this);
    }
Exemple #7
0
    /// <summary>
    /// Perform one cycle / time step.
    /// Implementation of <see cref="StepGenerator.IStepReceiver"/>
    /// </summary>
    public void DoStep()
    {
        // Ask all moving objects in the garden to perfrom one step aka one movement action.
        // The mower is always asked last.

        // Create a list of all moving objects in the garden with the robot at the last index.
        List <MovingGardenObject> movingObjects = new List <MovingGardenObject>(1 + movingObstacles.Count);

        foreach (var obstacle in movingObstacles)
        {
            movingObjects.Add(obstacle);
        }
        movingObjects.Add(Mower);

        // Check for all movements the object can perform if they are permitted.
        foreach (var movingObject in movingObjects)
        {
            List <MovementAction> permittedMovements = new List <MovementAction>(movingObject.PossibleMovements.Count);
            foreach (var movement in movingObject.PossibleMovements)
            {
                GridPosition resultingPosition = new GridPosition(movingObject.Position + movement.GridMovement);
                Tile         resultingTile     = GetTile(resultingPosition);
                if (IsValidPosition(resultingPosition) && !(resultingTile.Occupied) && (resultingTile.GetMowStatus() != Tile.MowStatus.Obstacle))
                {
                    permittedMovements.Add(movement);
                }
            }
            if (permittedMovements.Count > 0)
            {
                movingObject.PerformMovementActionFromAvailableActions(permittedMovements);
            }
        }

        // Chech if the episode is finished.
        if (Mower.MowingFinished)
        {
            EpisodeManager.NextEpisode();
        }
    }
        /// <summary>
        /// Retreive attribute from epsiode manager.
        /// </summary>
        /// <param name="manager">Manager of epsiode</param>
        private void LoadEpsiodeManagerAttributes(EpisodeManager manager)
        {
            // Update story attribute
            Story = manager.CurrentStory;

            // Update epsiode attribute
            Episode = manager.CurrentEpisode;

            // Update choices attribute
            if (Story != null && Story.Choices != null && Story.Choices.Count == 2)
            {
                FirstChoice  = Story.Choices[0];
                SecondChoice = Story.Choices[1];

                FinalStory       = false;
                ChoiceVisibility = true;
            }
            else
            {
                FinalStory       = true;
                ChoiceVisibility = false;
            }
        }
Exemple #9
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Mower"/> class.
    /// </summary>
    /// <param name="x">The x coordinate of the start position.</param>
    /// <param name="y">The y coordinate of the start position.</param>
    /// <param name="garden">The <see cref="T:Garden"/> this mower operates in.</param>
    /// <param name="paramSet">The <see cref="T:ParamSet"/> of the project which contains the neccessary parameters for the mower.</param>
    public Mower(uint x, uint y, Garden garden, ParamSet paramSet)
        : base(x, y)
    {
        this.Garden            = garden;
        this.PossibleMovements = MovementAction.VonNeumannNeighbourhoodMovements();
        this.MowReward         = paramSet.FloatParam(ParamSet.ParamGroupMower, ParamSet.ParamMowReward);
        this.NotMownReward     = paramSet.FloatParam(ParamSet.ParamGroupMower, ParamSet.ParamNotMownReward);
        string learnerParam = paramSet.StringParam(ParamSet.ParamGroupMower,
                                                   ParamSet.ParamLearnerType);

        if (learnerParam.Equals(QLearner.LearnerType))
        {
            this.learner = new QLearner(new StateExtractor(this), this, paramSet);
        }
        else if (learnerParam.Equals(RandomLearner.LearnerType))
        {
            this.learner = new RandomLearner(new StateExtractor(this));
        }
        else
        {
            throw new Exception("Unknown LearnerType detected.");
        }
        EpisodeManager.AddEpisodeChangesReceiver(this);
    }
Exemple #10
0
    /// <summary>
    /// Constructor of the QLearner
    /// </summary>
    /// <param name="stateExtractor"></param>
    /// The mower, that is learning
    /// <param name="mower"></param>
    ///
    /// The following are all classic QLearning parameters,
    /// with values in between 0 and 1:
    ///
    /// Greediness of the Q learning algorithm
    /// <param name="greediness"></param>
    /// Discountvalue: How much are old experiences weighted
    /// <param name="discountValue"></param>
    /// How fast or slow shall the mower learn?
    /// Fast: High value, slow: low value
    /// <param name="learnRate"></param>
    ///
    /// "Special" parameters:
    ///
    /// QLearning with optimitstic initial values
    /// <param name="initialQValue"></param>
    /// File to load the qTable from. Can be null.
    /// <param name="qTableDeserializationFile">
    /// File to write the qTable to after the episode limit is reached.
    /// <param name="qTableSerializationFile">
    /// Running with ETraces, yes or no?
    /// <param name="eligTraces"></param>
    /// If so, with what gamma?
    /// <param name="gamma"></param>
    /// File to load the EligibilityTable from. Can be null.
    /// <param name="eTableDeserializationFile">
    /// File to write the EligibilityTable to after the episode limit is reached.
    /// <param name="eTableSerializationFile">
    /// Running with Model?
    /// <param name="modelPlanning"></param>
    /// Using refined (true) or DynaQ (false) model
    /// <param name="refined"></param>
    /// File to load the Model from. Can be null.
    /// <param name="modelTableDeserializationFile">
    /// File to write the Model to after the episode limit is reached.
    /// <param name="modelTableSerializationFile">
    /// How many N virtual steps are executed in the model?
    /// <param name="n"></param>
    /// Shall the parameter label be shown?
    /// <param name="showParamLabel"></param>

    public QLearner(StateExtractor stateExtractor,
                    Mower mower,
                    float greediness,
                    float discountValue,
                    float learnRate,
                    float initialQValue,
                    string qTableDeserializationFile,
                    string qTableSerializationFile,
                    bool eligTraces,
                    float gamma,
                    string eTableDeserializationFile,
                    string eTableSerializationFile,
                    bool modelPlanning,
                    bool refined,
                    string modelTableDeserializationFile,
                    string modelTableSerializationFile,
                    int n,
                    bool showParamLabel)
        : base(stateExtractor)
    {
        Greediness               = greediness;
        DiscountValue            = discountValue;
        LearnRate                = learnRate;
        InitialQValue            = initialQValue;
        _qTableSerializationFile = qTableSerializationFile;
        _qTable                      = new QTable(InitialQValue, qTableDeserializationFile);
        Run_with_etraces             = eligTraces;
        Gamma                        = gamma;
        _eTableSerializationFile     = eTableSerializationFile;
        ModelPlanning                = modelPlanning;
        Refined                      = refined;
        _modelTableSerializationFile = modelTableSerializationFile;
        if (Run_with_etraces)
        {
            _eTable = new EligibilityTable(0f, eTableDeserializationFile);
        }
        if (ModelPlanning)
        {
            if (refined)
            {
                _mTable = new ModelTable(mower, modelTableDeserializationFile);
            }
            else
            {
                _simpleMTable = new ModelTableSimple(0f, modelTableDeserializationFile);
            }
        }

        N = n;
        _showParamLabel = showParamLabel;

        Debug.Log(string.Format(
                      "QLearner instantiated with greediness:{0}, discountValue:{1}, learnRate:{2}, initialQValue:{3}, N for Model:{4}",
                      Greediness,
                      DiscountValue,
                      LearnRate,
                      InitialQValue,
                      N));

        EpisodeManager.AddEpisodeChangesReceiver(this);
    }
Exemple #11
0
 private void OnDestroy()
 {
     Instance = null;
 }
Exemple #12
0
 private void Awake()
 {
     Instance = this;
 }
 /// <summary>
 /// Initialisation
 /// </summary>
 void Start()
 {
     textLabel = this.GetComponent <Text>();
     EpisodeManager.AddEpisodeChangesReceiver(this);
 }
 /// <summary>
 /// Basic initialisation.
 /// </summary>
 void Start()
 {
     EpisodeManager.AddEpisodeChangesReceiver(this);
 }