From 66558149ca26e1d39325091352a49be4647e6f3e Mon Sep 17 00:00:00 2001 From: Dawid Pietrykowski Date: Mon, 5 Sep 2022 00:27:58 +0200 Subject: [PATCH] Added free space filling --- .../Scripts/InitialConfigurationGenerator.cs | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/InitialConfigurationGenerator.cs b/Assets/Scripts/InitialConfigurationGenerator.cs index fbb01f0..2591a8a 100644 --- a/Assets/Scripts/InitialConfigurationGenerator.cs +++ b/Assets/Scripts/InitialConfigurationGenerator.cs @@ -29,7 +29,7 @@ namespace Parking } var countsString = $"Małe: {counts[0]} Średnie: {counts[1]} Duże: {counts[2]} " + - $"Suma: {counts.Sum()}"; + $"Suma: {counts.Sum() + 1}"; ParkingManager.Instance.UpdateText(countsString); Debug.Log(countsString); @@ -104,33 +104,39 @@ namespace Parking } } - // for (var laneId = 3; laneId >= 0; laneId--) { - // if (spotCountsPerpendicular[laneId] != 0) { - // if (sizeIds[laneId] == 0) { - // // empty - // } - // else if (sizeIds[laneId] == 1) { - // // parallel only - // } - // else { - // spotsCreatedTemp[laneId, sizeIds[laneId] - 2] += spotCountsPerpendicular[laneId]; - // spotCountsPerpendicular[laneId] = 0; - // } - // } - // } int count = 0; for (var i = 0; i < spotsCreatedTemp.GetLength(0); i++) for (var j = 0; j < spotsCreatedTemp.GetLength(1); j++) - count += spotsCreatedTemp[i, j]; - - if(copyToArray) - for (var i = 0; i < spotsCreatedTemp.GetLength(0); i++) - for (var j = 0; j < spotsCreatedTemp.GetLength(1); j++) - spotsCreated[i, j] = spotsCreatedTemp[i, j]; + count += spotsCreatedTemp[i, j]; + if (!copyToArray) + return count; + + for (var laneId = 3; laneId >= 0; laneId--) { + if (spotCountsPerpendicular[laneId] != 0) { + if (sizeIds[laneId] == 0) { + // empty + } + else if (sizeIds[laneId] == 1) { + // parallel only + } + else { + spotsCreatedTemp[laneId, sizeIds[laneId] - 2] += spotCountsPerpendicular[laneId]; + count += spotCountsPerpendicular[laneId]; + spotCountsPerpendicular[laneId] = 0; + } + } + } + + + for (var i = 0; i < spotsCreatedTemp.GetLength(0); i++) + for (var j = 0; j < spotsCreatedTemp.GetLength(1); j++) + spotsCreated[i, j] = spotsCreatedTemp[i, j]; + + return count; }