protected void DoNextGenerationStep(DiggingAgent agent) { //First we move the agent. //We change direction by chance or if the next position in the current direction is not in the level. if (Random.value < changeDirectionProb || !ContainsCoordinates(agent.pos + agent.direction.ToIntVector2())) { //Randomly move the agent to a new valid position in the level. GridDirection newDir = ChangeDirection(agent.pos, agent.direction); agent.direction = newDir; agent.turnProb = changeDirectionProb; } else if (dynamicProbabilities) { agent.turnProb += changeDirDelta; } //Now we now the next position! agent.pos += agent.direction.ToIntVector2(); //Make a room? if (Random.value < agent.roomProb) { rooms.Add(CreateRoom(agent.pos, RandomRoomSize)); agent.roomProb = makeRoomProb; } else { //else just open current cell agent.OpenCurrentCell(); if (dynamicProbabilities) { agent.roomProb += makeRoomDelta; } } }
protected List <DiggingAgent> agents; //This will keep track of the agents. protected override void Init() { base.Init(); agents = new List <DiggingAgent>(agentPositions.Count); for (int agent = 0; agent < agentPositions.Count; agent++) { GridDirection dir; if (startDirections != null) { dir = startDirections[agent]; //We are assuming that if startDirections exists, its size is equal to nr of agents. } else { dir = GridDirections.RandomValue; } DiggingAgent da = new DiggingAgent(this, agentPositions[agent], dir, changeDirectionProb, makeRoomProb); agents.Add(da); } }