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); }