/* Returns the zone that contains the cell. */ Zone FloodFillZone(Cell c, int zoneNumber, Zone zone = null) { // Only flood empty, zoneless cells. if (c.IsFilled() || c.zoneNumber >= 0) { return(zone); } if (zone == null) { zone = new Zone(zoneNumber); } // Add the cell to the deadZone. c.zoneNumber = zoneNumber; zone.Add(c); // Recursively call on the Von Neumann neighbors of the cell at (x, y). List <Cell> adjacentCells = GetAdjacentCells(c); foreach (Cell adjCell in adjacentCells) { zone = FloodFillZone(adjCell, zoneNumber, zone); } return(zone); }
/* Returns the hScore for the step from fromCell to toCell. */ float GetCostForStep(Cell fromCell, Cell toCell) { float multiplier = (toCell.IsFilled()) ? filledStepCost : emptyStepCost; return(multiplier * (Mathf.Abs(toCell.x - fromCell.x) + Mathf.Abs(toCell.y - fromCell.y))); }