public void LoadSquareTiles(LevelDescriptor levelConfiguration)
    {
        uint width  = levelConfiguration.PlotWidth;
        uint height = levelConfiguration.PlotLength;

        List <ObjectiveStep> mandatorySteps = levelConfiguration.MandatorySteps;

        BoundingBox2D tileBBox = GameObjectHelper.getBoundingBoxInWorld(TemplateTile.gameObject);
        float         sqWidth  = GameObjectHelper.getWidthFromBBox(tileBBox);
        float         sqHeight = GameObjectHelper.getWidthFromBBox(tileBBox);

        float sqDistance = sqWidth / 10;                // distance between tiles

        for (int plotY = 0; plotY < height; plotY++)    //iterates through lines (y)
        {
            for (int plotX = 0; plotX < width; plotX++) //iterates through columns (x)
            {
                // Checks if this is a mandatory step, and obtains info
                ObjectiveStep step = levelConfiguration.MandatorySteps.Where(s => s.CoordinateInPlot.x == plotX && s.CoordinateInPlot.y == plotY).FirstOrDefault();

                // Creates the tile
                SquareTile tile = (plotX + plotY) == 0 ? TemplateTile : TemplateTile.CloneThisTile();
                //tile.transform.parent = TemplateTile.gameObject.transform.parent;
                //tile.transform.position = TemplateTile.transform.position;

                // Sets the tile colour
                tile.SetColour(step == null ? SquareTile.STExpectedState.NOT_TO_STEP :
                               (step.SpecialAction ? SquareTile.STExpectedState.TO_EXECUTE_SPECIAL_ACTION : SquareTile.STExpectedState.TO_STEP));

                // Sets the coordinates text display
                tile.SetCoordinateText(plotX, plotY);

                // Creates a new position
                Vector3 newTilePos = tile.transform.position;
                newTilePos.x += plotX * (sqWidth + sqDistance);
                newTilePos.y += plotY * (sqHeight + sqDistance);

                // Sets the new position
                tile.transform.position = newTilePos;

                squareTiles.Add(tile);
            }
        }
    }
Example #2
0
    /// <summary>
    /// We are assuming this function is called after a success execution
    ///
    /// Basically we have to read
    /// -Straight lines (either up or down)
    /// -Turns
    /// -If a straight lines does not lead either to a left or a right, consider like the previous ones
    ///
    /// - how an user dealed with climb up and climb down?
    ///
    /// We have to check how the user implemented those patterns
    ///
    /// For example, making three lines with the same size, may have a Turn left or right based on if iteration equals a concrete number
    /// or if an iteration number is a multiple of some number
    ///
    ///
    /// Other example,  making four lines, two of the same size, and two not of the same size. The user could have three for cycles, one for the first
    /// two lines, and the others for the remaining lines. Or the user could have a bunch of walks and turns. Or the user could have one big cycle,
    /// with a bunch of if's for each turn.
    ///
    ///
    /// When we implement the AI we need to look at the closest patterns and get the synthesized solution
    ///
    /// Maybe we just start reading patterns in "for" levels and check how the user solved them?
    ///
    /// -Sequences of Walks and Climbs
    /// -Cycles -> how many? one for each, or one for every?
    /// -
    ///
    /// To read same lines we go to mandatory steps and check sequences of the same X and same Y, and same count
    ///
    /// </summary>
    public void ReadPatterns()
    {
        //LevelConfiguration.MandatorySteps.GroupBy(step => step.CoordinateInPlot.y).Select(step => new { count = step.Count(), });

        //First we read line sequences
        ObjectiveStep previousStep  = null;
        int           lineSizeCount = 0;
        bool          followingX    = false;

        foreach (ObjectiveStep step in LevelConfiguration.MandatorySteps)
        {
            if (previousStep == null)
            {
                previousStep   = step;
                lineSizeCount += 1;
            }
            else
            {
                followingX = step.CoordinateInPlot.x == previousStep.CoordinateInPlot.x;
            }
        }
    }