Vector2 CollapseInitialCell (List<Pattern> all_patterns,int initial_pattern, int x, int y)
    {
        initial_pattern = 0;

        if (x == -1)
            x = 0;//Random.Range(0, output_size);
        if (y == -1)
            y = 0;//Random.Range(0, output_size);
        Vector2 coords = new Vector2(x, y);
        collapsing[x][y] = WFCCollapse.GetHyperstates(all_patterns);
        WFCCollapse.CollapseSpecificCell(collapsing, entropy, coords, all_patterns, initial_pattern);
        //After collapse, remove from infinite list
        Debug.Log("Collapsed first cell of coordinates: " + x + "," + y + " from " + all_patterns.Count);
        return coords;
    }
    IEnumerator CollapseArray(int output_size, List<Pattern> all_patterns, int initial_pattern = -1, int initial_x = -1, int initial_y = -1)
    {
        //Setup useful lists and variables
        SetupCollapseArrays(output_size);

        if (all_patterns == null)
            Debug.LogError("Cannot collapse array with null patterns.");
        else if (all_patterns.Count <= 0)
            Debug.LogError("Cannot collapse array with no patterns.");
        else if (output_size <= 0)
            Debug.LogError("Cannot output array of invalid size.");
        else if (collapsing == null)
            Debug.LogError("Cannot collapse null collapsing array.");
        else if (entropy == null)
            Debug.LogError("Cannot collapse null entropy array.");

        #region WFC Algorithm
        //FIRST CELL COLLAPSE --------------------------------------------------------------------
        Vector2 initial_collapse = new Vector2(-1,-1);
        if (initial_pattern != -1)
            CollapseInitialCell(all_patterns,initial_pattern,initial_x, initial_y);
        else
            initial_collapse = WFCCollapse.CollapseHyperCell(collapsing, entropy, all_patterns);

        string log = ReadArrayList(collapsing);
        Debug.Log("<color=yellow> Tile array: </color> \n" + ReadIntArraySquare(input_constrained));
        Debug.Log("<color=cyan> Initial pattern array collapse: </color> \n" + log);

        //Log initial cell collapse
        output = WFCInputOutput.GetOutputArray(collapsing, unique, pattern_size);
        log = ReadIntArraySquare(output);
        Debug.Log("<color=green>Initial output array collapse: </color> \n" + log);

        //LOOP COLLAPSE --------------------------------------------------------------------
        //Loop until no left cells and result is valid
        bool is_valid = false;
        while (!is_valid)
        {
            for (int t = 0; t < 999; t++)
            {
                WFCCollapse.CollapseMostProbable(collapsing, entropy, all_patterns);

                //READ COLLAPSING
                //log = ReadArrayList(collapsing);
                //Debug.Log("<color=cyan> " + "Test" + " collapse: </color> \n" + log);

                //READ ENTROPY
                //log = ReadArray(entropy);
                // Debug.Log("<color=blue> " + "Test" + " collapse: </color> \n" + log);

                //READ OUTPUT
                output = WFCInputOutput.GetOutputArray(collapsing, unique, pattern_size);
                log = ReadIntArraySquare(output);
                //Debug.Log("<color=magenta> " + "Initial output array" + " collapse: </color> \n" + log);
                //result = InterpretOutput(output);

                //error here
                log = ReadArrayList(collapsing);
                Debug.Log("<color=green> " + t +" interpreted output array" + " collapse: </color> \n" + log);


                output = WFCInputOutput.GetOutputArray(collapsing, unique, pattern_size);
                yield return null;

                InstantiateOutput(output, unique_tileset, invalid_tile);
                yield return null;


                if (CheckValidity(entropy, output_size))
                    break;
            }
            yield return null;
            is_valid = CheckValidity(entropy, output_size);
        }
        //Creation was successful!
        //Generate the output
        output = WFCInputOutput.GetOutputArray(collapsing, unique, pattern_size);
        log = ReadIntArraySquare(output);
        Debug.Log("<color=magenta> " + "Output array" + " collapse: </color> \n" + log);
        #endregion
        yield break;
    }