Exemplo n.º 1
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);
    }