private void Step() { Vector2Int hollow = structure.PopFirstHollow(); List <Wasp> waspWhichCanPutTemplate = new List <Wasp>(); foreach (var wasp in trainer.wasps) { bool dontFitShape = false; if (structure.TemplateFitIn(hollow, wasp, shape, out dontFitShape)) { if (dontFitShape) { wasp.ModifyHealth(trainer.waspPunishment); } else { waspWhichCanPutTemplate.Add(wasp); wasp.ModifyHealth(trainer.waspReward); } } } if (waspWhichCanPutTemplate.Count == 0) { if (trainer.probOfUseSameBrickNumber != 0) { waspWhichCanPutTemplate.Add(CreateWaspFor(hollow, lastBrickNumber)); waspWhichCanPutTemplate.Last().health *= trainer.probOfUseSameBrickNumber; } if (trainer.probOfCreateNewBrickNumber != 0) { lastBrickNumber++; waspWhichCanPutTemplate.Add(CreateWaspFor(hollow, lastBrickNumber)); waspWhichCanPutTemplate.Last().health *= trainer.probOfCreateNewBrickNumber; } foreach (var w in waspWhichCanPutTemplate) { trainer.AddWasp(w); } } Wasp selectedTemplate = Wasp.Select(waspWhichCanPutTemplate); var newBricks = structure.AddBricks(hollow, selectedTemplate); if (newBricks.Count > 0) { structure.RecalculateHollows(newBricks); } foreach (var wasp in trainer.wasps) { wasp.health += trainer.healthStepDecay; } }
// Start is called before the first frame update public void Generate(List <Wasp> wasps) { BrickStructure structure = new BrickStructure(); var bricks = InitStructure(structure); structure.RecalculateHollows(bricks); int iter = 0; while (structure.HaveHollows() && iter < maxIter) { List <Wasp> posibleTemplates = new List <Wasp>(); Vector2Int hollow = structure.PopFirstHollow(); foreach (var wasp in wasps) { if (structure.TemplateFitIn(hollow, wasp)) { posibleTemplates.Add(wasp); } } if (posibleTemplates.Count > 0) { var newBricks = structure.AddBricks(hollow, Wasp.Select(posibleTemplates)); if (newBricks.Count > 0) { structure.RecalculateHollows(newBricks); } } iter++; } GetComponent <StructureRenderer>().Render(structure); }