WFCScriptableOBJ RandomTile(WFCpossibility _tile) { WFCScriptableOBJ hightsProb = _tile.possibleWFC[0]; //obtain the hights probability for this group of possibilities for (int i = 0; i < _tile.possibleWFC.Count; i++) { if (GetProbability(_tile.possibleWFC[i]) > GetProbability(hightsProb)) { hightsProb = _tile.possibleWFC[i]; } } Debug.Log("hightes probabilit is " + GetProbability(hightsProb)); //get a random number between 0 and 100 for probability int rand = Random.Range(0, 100); //sort the possibleWFC by probability _tile.possibleWFC.Sort(SortByProbability); //run a for loop until we find the 1st number //where our random is hightest than the relative probability for (int i = 0; i < _tile.possibleWFC.Count; i++) { if (GetRelativeProbability(GetProbability(_tile.possibleWFC[i]), GetProbability(hightsProb)) > rand) { _tile.possibleWFC[i].probability -= 1; return(_tile.possibleWFC[i]); } } //if none are higher than it is the hights probability ( the 100%) return(hightsProb); }
void GenerateSolution() { //Fill the space with nodes of possibility that store information regarding all possible available options for all nodes for (int i = 0; i < solutionSize; i++) { for (int j = 0; j < solutionSize; j++) { solution.SetTile(new Vector3Int(i, j, 0), posibility); WFCpossibility newPosibility = new WFCpossibility(); newPosibility.location = new Vector2Int(i, j); newPosibility.CopyData(dataList); newPosibility.possibleWFC.Sort(SortByProbability); possibilites[i, j] = newPosibility; possibilityList.Add(newPosibility); } } if (surroundedByWater) { //make the boarders of the tilemap water for (int i = 0; i < solutionSize; i++) { for (int j = 0; j < solutionSize; j++) { if (j == 0 || i == 0 || j == solutionSize - 1 || i == solutionSize - 1) { waterQueu.Add(new Vector2Int(i, j)); } } } Debug.Log("WATER BASE SET"); } }
void CollapseBaseOnProbability(WFCpossibility _tile) { Debug.Log("PROPAGATE WITH PROBABILITY"); if (trueRandom) { WFCScriptableOBJ randomObj; int rand = Random.Range(0, _tile.possibleWFC.Count); randomObj = _tile.possibleWFC[rand]; _tile.CopyConnectionData(randomObj); } else { _tile.CopyConnectionData(RandomTile(_tile)); } solution.SetTile(new Vector3Int(_tile.location.x, _tile.location.y, 0), _tile.possibleWFC[0].WFCtile); possibilityList.Remove(_tile); propagateQueu.Add(_tile); }
static int SortByEntropy(WFCpossibility _possi1, WFCpossibility _possi2) { return(_possi1.possibleWFC.Count.CompareTo(_possi2.possibleWFC.Count)); }