bool GetPatternList_PatternSizeThree_AllFourMatch(bool debug) { int pattern_size = 3; int[] offset_linear = new int[] { 4, 5, 4, 5, 7, 6, 7, 6, 4, 5, 4, 5, 7, 6, 7, 6 }; int[][] offset_array = LinearArrayToSquare(offset_linear, (int)Mathf.Sqrt(offset_linear.Length)); int[][] output_expected = new int[4][]; output_expected[0] = new int[] { 1, 2, 1, 4, 3, 4, 1, 2, 1 }; output_expected[1] = new int[] { 2, 1, 2, 3, 4, 3, 2, 1, 2 }; output_expected[2] = new int[] { 4, 3, 4, 1, 2, 1, 4, 3, 4 }; output_expected[3] = new int[] { 3, 4, 3, 2, 1, 2, 3, 4, 3 }; List <Pattern> unique_patterns = WFCPattern.GetUniquePatterns(offset_array, pattern_size); int[][] pattern_list_to_array = PatternListToArray(unique_patterns); bool result = true; result = CompareSquareArrays(pattern_list_to_array, output_expected); //Print the result if required if (debug) { Debug.Log("<color=purple> GetPatternList_PatternSizeThree_AllFourMatch: " + result + "</color>\n" + ReadIntArrayLinear(offset_linear) + "\n" + ReadIntArrayLinear(SquareArrayToLinear(pattern_list_to_array)) + "\n" + ReadIntArrayLinear(SquareArrayToLinear(output_expected))); } return(result); }
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; }
bool GetNeighbors_HorizontalLinesPatternSizeTwo_FirstLastMatches(bool debug) { //////////////////////////////////////////////////// INPUT int pattern_size = 2; //This is the offset array to get unique pattern list int[] input_offset_linear = new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, }; int[][] offset_array = LinearArrayToSquare(input_offset_linear, (int)Mathf.Sqrt(input_offset_linear.Length)); List <Pattern> pattern_list = WFCPattern.GetUniquePatterns(offset_array, pattern_size); //This is the pattern index array used to find the neighbors int[] input_pattern_linear = new int[] { 0, 0, 0, -1, 1, 1, 1, -1, 0, 0, 0, -1, -1, -1, -1, -1, }; int[][] pattern_array = LinearArrayToSquare(input_pattern_linear, (int)Mathf.Sqrt(input_offset_linear.Length)); List <Pattern> output_neighbor_list = WFCPattern.GetNeighbors(pattern_array, pattern_size, pattern_list); ///////////////////////////////////////////////////// OUTPUT int[][] output_first_pattern_neighbors = ListIntToArray(output_neighbor_list[0].possible_neighbors); int[][] output_last_pattern_neighbors = ListIntToArray(output_neighbor_list[output_neighbor_list.Count - 1].possible_neighbors); int[][] expected_first_neighbors = new int[4][]; //0 expected_first_neighbors[0] = new int[] { 1 }; //Top expected_first_neighbors[1] = new int[] { 0 }; //Right expected_first_neighbors[2] = new int[] { 1 }; //Bot expected_first_neighbors[3] = new int[] { 0 }; //Left int[][] expected_last_neighbors = new int[4][]; //1 expected_last_neighbors[0] = new int[] { 0 }; //Top expected_last_neighbors[1] = new int[] { 1 }; //Right expected_last_neighbors[2] = new int[] { 0 }; //Bot expected_last_neighbors[3] = new int[] { 1 }; //Left /////////////// COMPARISON bool result = true; if (!CompareArrays(output_first_pattern_neighbors, expected_first_neighbors)) { result = false; } if (!CompareArrays(output_last_pattern_neighbors, expected_last_neighbors)) { result = false; } if (debug) { Debug.Log(string.Format("<color=red> GetNeighbors_HorizontalLinesPatternSizeTwo_FirstLastMatches: {0} </color> \n" + "Offset linear array: \n" + ReadIntArrayLinear(input_offset_linear) + "\n" + "Pattern linear array: \n" + ReadIntArrayLinear(input_pattern_linear) + "\n" + "Expected neighbors of first pattern : \n{2}" + "Output neighbors of first pattern: \n{3}{4}" + "Expected neighbors of last pattern: \n{5}" + "Output neighbors of last pattern: \n{6}{7}" , result, ReadIntArrayLinear(input_offset_linear), ReadIntArraySquare(expected_first_neighbors), ReadIntArraySquare(output_neighbor_list[0].values), ReadIntArraySquare(output_first_pattern_neighbors), ReadIntArraySquare(expected_last_neighbors), ReadIntArraySquare(output_neighbor_list[output_neighbor_list.Count - 1].values), ReadIntArraySquare(output_last_pattern_neighbors) )); } return(result); }
bool GetNeighbors_CrossingPatternPatternSizeTwoBiggerOffset_FirstLastMatches(bool debug) { Debug.LogWarning("Algorithm does not work on Odd Offsets. Proceed testing."); return(true); //////////////////////////////////////////////////// INPUT int pattern_size = 2; int[] input_offset_linear = new int[] { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, }; int[][] offset_array = LinearArrayToSquare(input_offset_linear, (int)Mathf.Sqrt(input_offset_linear.Length)); List <Pattern> pattern_list = WFCPattern.GetUniquePatterns(offset_array, pattern_size); //This is the pattern index array used to find the neighbors int[] input_pattern_linear = new int[] { 0, 1, 2, 0, 0, 0, -1, 3, 4, 5, 3, 3, 3, -1, 6, 7, 8, 6, 6, 6, -1, 0, 1, 2, 0, 0, 0, -1, 0, 1, 2, 0, 0, 0, -1, 0, 1, 2, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, }; int[][] pattern_array = LinearArrayToSquare(input_pattern_linear, (int)Mathf.Sqrt(input_offset_linear.Length)); List <Pattern> output_neighbor_list = WFCPattern.GetNeighbors(pattern_array, pattern_size, pattern_list); ///////////////////////////////////////////////////// OUTPUT int[][] output_first_pattern_neighbors = ListIntToArray(output_neighbor_list[0].possible_neighbors); int[][] output_last_pattern_neighbors = ListIntToArray(output_neighbor_list[output_neighbor_list.Count - 1].possible_neighbors); int[][] expected_first_neighbors = new int[4][]; expected_first_neighbors[0] = new int[] { 6, 0 }; //Top expected_first_neighbors[1] = new int[] { 1, 0 }; //Right expected_first_neighbors[2] = new int[] { 3, 0 }; //Bot expected_first_neighbors[3] = new int[] { 2, 0 }; //Left int[][] expected_last_neighbors = new int[4][]; expected_last_neighbors[0] = new int[] { 5 }; //Top expected_last_neighbors[1] = new int[] { 6 }; //Right expected_last_neighbors[2] = new int[] { 2 }; //Bot expected_last_neighbors[3] = new int[] { 7 }; //Left /////////////// COMPARISON bool result = true; if (!CompareArrays(output_first_pattern_neighbors, expected_first_neighbors)) { result = false; } if (!CompareArrays(output_last_pattern_neighbors, expected_last_neighbors)) { result = false; } if (debug) { Debug.Log("<color=red> GetNeighbors_CrossingPatternPatternSizeTwoBiggerOffset_FirstLastMatches: " + result + "</color>\n" + "Offset linear array: \n" + ReadIntArrayLinear(input_offset_linear) + "\n" + "Pattern linear array: \n" + ReadIntArrayLinear(input_pattern_linear) + "\n" + "Expected neighbors of first pattern: \n" + ReadIntArraySquare((expected_first_neighbors)) + "\n" + "Output neighbors of first pattern: \n" + ReadIntArraySquare((output_first_pattern_neighbors)) + "\n" + "Expected neighbors of last pattern: \n" + ReadIntArraySquare((expected_last_neighbors)) + "\n" + "Output neighbors of last pattern: \n" + ReadIntArraySquare((output_last_pattern_neighbors)) + "\n" ); } return(result); }