Quantcast
Channel: Latest Questions by esitoinatteso
Viewing all articles
Browse latest Browse all 92

Drunkard Walk Algorithm C# Question

$
0
0
Hi dear Unity's community! I've been away for a lot, but I spent that time trying and studying by myself the mysterious world of coding, lurking here and there, reading your kind answers to questions already asked that were useful to fulfill my needs! I'm now here once more to subject to you my last achievement in this field, trusting in your unselfish dedication to these subjects and hoping to hear helpful advices. Before I continue, I think I should justify my decision to talk about this by opening a question... well, I wanted to make known the method I used to help other amateurs in their own quests for knowledge, but I also wanted to make clear that what follows is by no means finished or " correct". Thus I preferred unityAnswers to the Forums. So, I wanted to use Procedural Generation of Contents. I learned about Drunkard Walk which is basically what I thought to do by myself, except that somebody else already thought about it. What follows is my own personal attempt to make such an algorithm. So far it doesn't stop by itself and is unable to " think" too much... it " just" build up a map of squares. Squares, yes, because I've attached this script to a plane with a box collider in my editor and I've got another script attached to a GameMaster that instantiate the first square from which to start walking. Here it is, in all his unholy ignorance! ## e's ROUGH Drunkard Square Generator ## using UnityEngine; using System.Collections; using System.Collections.Generic;//List Enabled public class DrunkardSquareGenerator : MonoBehaviour { // This class will handle the algorithms for my Drunkard Walk Procedural Generated Content /* * I originally thought to store all the functions here, but then I tried to separate them in other scripts. * I'm going to put them back here once more... I kinda miss some basics in software architecture. * Problem is, I thought to use a List to handle all this stuff, instead of a sequence of IF statements, BUT * I wasn't capable of doing it because I lack the competence. * * There will be 3 different algorithms and all of them will be capable of avoid overlap via a specific method. * Maybe... */ private int chosenAlgo; // it's a random int to know which algorithm must be picked. //Algorithms' Stuff private List PosList = new List(); // here we will store the coordinates to choose from private int iPosList; // index for PosList. private int sPosList; // sieze of PosList. private Transform myTransform; // reference to this transform. private Vector3 posChosen; // reference to the position chosen private int shouldI; // int to decide if it should try to instantiate or skip private Vector3 north;//items of PosLists private Vector3 south; private Vector3 east; private Vector3 west; // I'll set up some things in here void Awake () { //set the random int to choose chosenAlgo = 1; // FOR TEST SAKE //chosenAlgo = Random.Range(1,3); Debug.Log ("Chosen Algo is:" + chosenAlgo); //get reference myTransform = gameObject.transform; north = new Vector3(myTransform.position.x+10.0f, 0, myTransform.position.z); south = new Vector3(myTransform.position.x-10.0f, 0, myTransform.position.z); east = new Vector3(myTransform.position.x, 0, myTransform.position.z+10.0f); west = new Vector3(myTransform.position.x, 0, myTransform.position.z-10.0f); //populate list PosList.Add(north); PosList.Add(south); PosList.Add(east); PosList.Add(west); sPosList = PosList.Count; } // Use this for initialization void Start () { //When the square is spawned, it will decide what to do. //I know this thing down here sucks but hey! at least it's working! if(chosenAlgo == 1){ CdrunkardWalk(); } if(chosenAlgo == 2){ SdrunkardWalk(); } if(chosenAlgo == 3){ BdrunkardWalk(); } } // Update is called once per frame void Update () { } //Classic Drunkard Walk void CdrunkardWalk(){ //Debug.Log ("You got to Classic"); just to be sure... //Now we have to build the algorithm... SO, for every item in List for(int i = 0; i

Viewing all articles
Browse latest Browse all 92

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>