bool GetPatternArray_ComplexOffsetPatternSizeFive_PatternIdentificationMatches(bool debug) { int pattern_size = 5; int[] offset_linear = new int[] { 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6 }; int[][] offset_array = LinearArrayToSquare(offset_linear, (int)Mathf.Sqrt(offset_linear.Length)); List <Pattern> unique_patterns = WFCPattern.GetUniquePatterns(offset_array, pattern_size); ////////////////////////////////////////////// int[] output_expected = new int[] { 0, 1, 0, 1, 0, 1, -1, -1, -1, -1, 2, 3, 2, 3, 2, 3, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, -1, -1, -1, -1, 2, 3, 2, 3, 2, 3, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, -1, -1, -1, -1, 2, 3, 2, 3, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; ////////////////////////////////////////////// int[][] output_square = WFCPattern.GetPatternArray(offset_array, pattern_size, unique_patterns); int[] output_linear = SquareArrayToLinear(output_square); bool result = CompareLinearArrays(output_linear, output_expected); if (debug) { Debug.Log("<color=magenta> GetPatternArray_ComplexOffsetPatternSizeFive_PatternIdentificationMatches: " + result + "</color>\n" + ReadIntArrayLinear(offset_linear) + "\n" + ReadIntArrayLinear((output_expected)) + "\n" + ReadIntArrayLinear(SquareArrayToLinear(output_square))); } return(result); }
bool GetPatternArray_RealOffsetPatternSizeFour_PatternIdentificationMatches(bool debug) { return(true); int pattern_size = 4; int[] offset_linear = new int[] { 8, 8, 0, 0, 8, 8, 0, 0, 8, 8, 0, 0, 8, 8, 0, 0, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 8, 8, 0, 0, 8, 8, 0, 0, 8, 8, 0, 0, 8, 8, 0, 0, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6 }; int[][] offset_array = LinearArrayToSquare(offset_linear, (int)Mathf.Sqrt(offset_linear.Length)); List <Pattern> unique_patterns = WFCPattern.GetUniquePatterns(offset_array, pattern_size); ////////////////////////////////////////////// int[] output_expected = new int[] { 0, 1, 2, 3, 0, -1, -1, -1, 4, 5, 6, 7, 4, -1, -1, -1, 8, 9, 10, 11, 8, -1, -1, -1, 12, 13, 14, 15, 12, -1, -1, -1, 0, 1, 2, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 - 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; ////////////////////////////////////////////// int[][] output_square = WFCPattern.GetPatternArray(offset_array, pattern_size, unique_patterns); int[] output_linear = SquareArrayToLinear(output_square); bool result = CompareLinearArrays(output_linear, output_expected); if (debug) { Debug.Log("<color=magenta> GetPatternArray_RealOffsetPatternSizeFour_PatternIdentificationMatches: " + result + "</color>\n" + ReadIntArrayLinear(offset_linear) + "\n" + ReadIntArrayLinear((output_expected)) + "\n" + ReadIntArrayLinear(SquareArrayToLinear(output_square))); } return(result); }
IEnumerator Test() { //Get the tileset and dataset from the respective transforms unique_tileset = tileset_transform.GetComponentsInChildren<Tile>(); dataset = dataset_transform.GetComponentsInChildren<Tile>(); Debug.Log("<color=grey> Got tileset of size: " + unique_tileset.Length + ". Got dataset of size: " + dataset.Length + "</color>\n "); //input_unique = InputReader.GetInput(dataset); //Debug.Log("<color=green> Generated input: </color>\n " + ReadArrayInt(input_unique)); input_constrained = InputReader.GetConstraintArray(dataset); Debug.Log("<color=green> Input grid: </color>\n " + ReadIntArraySquare(input_constrained)); offset = WFCInputOutput.GetOffsetArray(input_constrained, pattern_size); Debug.Log("<color=green> Offset grid: </color>\n " + ReadIntArraySquare(offset)); unique = WFCPattern.GetUniquePatterns(offset,pattern_size); pattern = WFCPattern.GetPatternArray(offset,pattern_size,unique); Debug.Log("<color=orange> Pattern grid output: </color>\n " + ReadIntArraySquare(pattern)); unique = WFCPattern.GetNeighbors(pattern, pattern_size, unique); string log = ""; for (int i = 0; i < unique.Count; i++) log += unique[i].GetValues() + "\n"; Debug.Log("<color=orange> Unique patterns: </color> \n" + log); log = ""; for (int i = 0; i < unique.Count; i++) log += unique[i].GetFrequency() + "\n"; Debug.Log("<color=red> Frequency of unique patterns:</color> \n " + log); //log = ""; //for (int i = 0; i < unique.Count; i++) // log += unique[i].GetSides() + "\n"; //Debug.Log("<color=red> Sides of unique patterns: \n</color> " + log); log = ""; for (int i = 0; i < unique.Count; i++) log += "For pattern \n" + unique[i].GetValues() + "\n" + unique[i].GetNeighbors(unique) + "\n-----------\n"; Debug.Log("<color=red> Neighbors of patterns: </color> " + log); //Output an array of patterns of X size according to a pattern list //Optional parameters to include a preset first cell yield return CollapseArray(output_size, unique); InstantiateOutput(output, unique_tileset, invalid_tile); Debug.Log("Finished test routine."); yield break; }