Пример #1
0
    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);
    }
Пример #2
0
 float GetProbability(WFCScriptableOBJ _check)
 {
     Debug.Log("probability in the scriptable obj is " + _check.probability);
     Debug.Log("number of tiles " + checkedTiles);
     Debug.Log("probability of this tile is " + (((_check.probability / checkedTiles) * 100)));
     return(((_check.probability / checkedTiles) * 100));
 }
Пример #3
0
    void ProcessPropagateQueu()
    {
        if (!ispropagating)
        {
            if (showPropagation)
            {
                ispropagating = true;
                StartCoroutine(WaitForPropagation());
            }

            if (propagateQueu.Count != 0)
            {
                Propagate(propagateQueu[0].location);
            }
            else
            {
                if (generationgWater)
                {
                    if (waterQueu.Count != 0)
                    {
                        WFCScriptableOBJ waterScriptable = FindWFCScriptableObj(water);
                        solution.SetTile(new Vector3Int(waterQueu[0].x, waterQueu[0].y, 0), water);       //set the boards to water
                        possibilites[waterQueu[0].x, waterQueu[0].y].CopyConnectionData(waterScriptable); //get the data to the possibility
                        propagateQueu.Add(possibilites[waterQueu[0].x, waterQueu[0].y]);                  //queu the propagate
                        possibilityList.Remove(possibilites[waterQueu[0].x, waterQueu[0].y]);             //remove it from the list of possibilities since it has been choosen
                        waterScriptable.probability -= 1;
                        waterQueu.RemoveAt(0);
                        NewPropagate();
                    }
                    else
                    {
                        generationgWater = false;
                    }
                }
                else
                {
                    if (possibilityList.Count != 0)
                    {
                        NewPropagate();
                        CollapseBaseOnProbability(possibilityList[0]);
                    }
                }
            }
        }
    }
Пример #4
0
    void TileMapSampleUpdate()
    {
        if (sampleTilemap[0].GetTile(new Vector3Int(posOfSample.x, posOfSample.y, 0)) != null)
        {
            WFCScriptableOBJ newTile = FindWFCScriptableObj(sampleTilemap[0].GetTile <Tile>(new Vector3Int(posOfSample.x, posOfSample.y, 0)));
            CheckSidesTileMap(posOfSample, newTile);
            newTile.probability += 1;
            posOfSample.x       += 1;
            checkedTiles        += 1;

            TileMapSampleUpdate();
        }
        else
        {
            if (sampleTilemap[0].GetTile(new Vector3Int(0, posOfSample.y - 1, 0)) != null)
            {
                if (!trueRandom)
                {
                    if (solutionSize != 0)                     //has been set before
                    {
                        if (solutionSize != posOfSample.x + 1) //check if samples have the same size
                        {
                            Debug.Log("WARNING: Sample have different sizes this will affect the probabilities of each tile");
                        }
                    }
                    solutionSize = posOfSample.x + 1;
                }
                posOfSample.x  = 0;
                posOfSample.y -= 1;
                TileMapSampleUpdate();
            }
            else
            {
                Debug.Log("END OF SAMPLE UPDATE");
                sampleTilemap[0].gameObject.SetActive(false);
                posOfSample.x = 0;
                posOfSample.y = 0;
                sampleTilemap.RemoveAt(0);
            }
        }
    }
Пример #5
0
 static int SortByProbability(WFCScriptableOBJ _prob1, WFCScriptableOBJ _prob2)
 {
     return(_prob1.probability.CompareTo(_prob2.probability));
 }
Пример #6
0
    void CheckSidesTileMap(Vector2Int _currentpos, WFCScriptableOBJ _currentData)
    {
        Tile             neighbourTile;
        WFCScriptableOBJ neighbourData;


        //RIGHT tile
        neighbourTile = sampleTilemap[0].GetTile <Tile>(new Vector3Int(_currentpos.x + 1, _currentpos.y, 0));
        if (neighbourTile != null)
        {
            neighbourData = FindWFCScriptableObj(neighbourTile);
            //Debug.Log("found neighbour to the right");
            //check if this tile already exists in the list for this direction
            if (!_currentData.rightWFC.Contains(neighbourData))
            {
                // update this neighbour on the list of the obj
                _currentData.rightWFC.Add(neighbourData);
                // Debug.Log("added neighbour that was to the right");
            }
        }

        //LEFT tile
        neighbourTile = sampleTilemap[0].GetTile <Tile>(new Vector3Int(_currentpos.x - 1, _currentpos.y, 0));
        if (neighbourTile != null)
        {
            neighbourData = FindWFCScriptableObj(neighbourTile);
            //Debug.Log("found neighbour to the left");
            //check if this tile already exists in the list for this direction
            if (!_currentData.leftWFC.Contains(neighbourData))
            {
                // update this neighbour on the list of the obj
                _currentData.leftWFC.Add(neighbourData);
                //Debug.Log("added neighbour that was to the left");
            }
        }

        //UP tile
        neighbourTile = sampleTilemap[0].GetTile <Tile>(new Vector3Int(_currentpos.x, _currentpos.y + 1, 0));
        if (neighbourTile != null)
        {
            neighbourData = FindWFCScriptableObj(neighbourTile);
            //Debug.Log("found neighbour above");
            //check if this tile already exists in the list for this direction
            if (!_currentData.upWFC.Contains(neighbourData))
            {
                // update this neighbour on the list of the obj
                _currentData.upWFC.Add(neighbourData);
                //Debug.Log("added neighbour that was above");
            }
        }

        //DOWN tile
        neighbourTile = sampleTilemap[0].GetTile <Tile>(new Vector3Int(_currentpos.x, _currentpos.y - 1, 0));
        if (neighbourTile != null)
        {
            neighbourData = FindWFCScriptableObj(neighbourTile);
            //Debug.Log("found neighbour below");
            //check if this tile already exists in the list for this direction
            if (!_currentData.downWFC.Contains(neighbourData))
            {
                // update this neighbour on the list of the obj
                _currentData.downWFC.Add(neighbourData);
                //Debug.Log("added neighbour that was below");
            }
        }
    }
Пример #7
0
 public void CopyConnectionData(WFCScriptableOBJ _option)
 {
     possibleWFC.Clear();
     possibleWFC.Add(_option);
     hasBeenChoosen = true;
 }