WIP Adding Reservations
This commit is contained in:
parent
ca0eaa9568
commit
f26a570c93
141
Assets/Data/Tablica1.csv
Normal file
141
Assets/Data/Tablica1.csv
Normal file
@ -0,0 +1,141 @@
|
||||
Ranga stanowiska ,wybrany sposób parkowania,Klasyfikacja gabarytu ,od planwane,do planowane,od rzeczywiste,do rzeczywiste,czas miedzy sprawdzaniem miejsca
|
||||
1,P,Duży,9,15,8:45,13:20,60
|
||||
1,T,Duży,8,10,7:53,10:01,60
|
||||
1,,Duży,9,13,8:53,14:02,60
|
||||
1,P,Duży,8,16,7:45,16:10,60
|
||||
1,,Duży,9,16,9:30,14,60
|
||||
1,P,Duży,11,14,12,14:10,60
|
||||
1,P,Duży,10,15,9:50,13:10,60
|
||||
1,P,Duży,9,15,9:20,14:50,60
|
||||
1,,Duży,9,17,9,17:04,60
|
||||
1,,Duży,12,17,12:50,17:02,60
|
||||
1,,Duży,9,17,9,16:58,60
|
||||
1,P,Duży,10,15,9:50,13:30,60
|
||||
1,,Duży,9,14,9:30,14:10,60
|
||||
1,,Duży,8,16,7:56,17:12,60
|
||||
1,,Duży,9,15,10,12:30,60
|
||||
2,,Duży,8,16,7:50,17:05,15
|
||||
2,P,Mały,7,15,6:40,14:50,15
|
||||
2,,Średni,7,15,7:05,15:14,15
|
||||
2,,Duży,10,16,10:49,15:58,15
|
||||
2,P,Średni,8,16,8:49,15:04,15
|
||||
2,,Średni,9,17,9:23,16:59,15
|
||||
2,P,Duży,8,16,7:49,16:05,15
|
||||
2,T,Średni,7:30,15:30,7:27,15:36,15
|
||||
2,T,Duży,8,16,8:10,15:50,15
|
||||
2,P,Duży,7:30,15:30,7:53,15:37,15
|
||||
2,,Duży,8,16,7:53,16:01,15
|
||||
2,T,Średni,7:30,15:30,7:35,15:30,15
|
||||
2,,Duży,8,16,7:53,16:40,15
|
||||
2,P,Średni,8,16,7:57,16:01,15
|
||||
2,,Średni,8,16,7:45,16:10,15
|
||||
2,T,Duży,11,16,11:18,16:13,15
|
||||
2,,Duży,10,16,10:05,16:08,15
|
||||
2,,Duży,7,15,7,15:10,15
|
||||
3,P,Mały,6,14,6:05,13:55,15
|
||||
3,,Mały,8,16,7:45,16:10,15
|
||||
3,P,Średni,8,16,7:50,16:15,15
|
||||
3,,Duży,8,16,8:03,16:10,15
|
||||
3,,Średni,8,10,8,9:58,15
|
||||
3,,Średni,7:30,12:30,7:25,12:32,15
|
||||
3,T,Duży,8,12,8:02,12:05,15
|
||||
3,,Średni,7:30,13:30,7:28,13:40,15
|
||||
3,T,Średni,7:30,15:30,7:15,15:17,15
|
||||
3,,Mały,8,16,7:45,16:10,15
|
||||
3,P,Średni,7,7,6:58,7:10,15
|
||||
3,P,Duży,8,16,7:57,15:58,15
|
||||
3,,Średni,6,14,6:05,14:10,15
|
||||
3,,Średni,6,14,6:01,14:03,15
|
||||
3,,Mały,6:30,14:30,6:32,14:34,15
|
||||
3,P,Średni,7,15,6:57,15,15
|
||||
3,P,Duży,8,16,7:45,16:10,15
|
||||
3,,Średni,8,16,8:02,15:59,15
|
||||
3,,Średni,8:30,16:30,8:21,16:27,15
|
||||
3,P,Mały,9,17,9:02,17:10,15
|
||||
3,,Średni,9,17,8:57,16:58,15
|
||||
3,,Średni,8,16,8:04,16:12,15
|
||||
3,,Mały,8,16,7:52,15:57,15
|
||||
3,T,Średni,7,15,7:08,15:14,15
|
||||
3,,Średni,7:30,15:30,7:31,15:39,15
|
||||
3,,Duży,8,16,7:56,15:57,15
|
||||
3,,Mały,8,16,7:50,15:59,15
|
||||
3,P,Średni,8:30,16:30,8:27,16:34,15
|
||||
3,,Mały,7,15,6:57,15:05,15
|
||||
3,,Średni,8,16,8:02,15:59,15
|
||||
3,T,Średni,7,15,6:54,15:01,15
|
||||
3,,Mały,8,16,7:49,15:58,15
|
||||
3,,Średni,8,16,8,15:58,15
|
||||
3,,Duży,8:30,16:30,8:25,16:32,15
|
||||
3,T,Średni,8,16,8:04,16:10,15
|
||||
3,,Średni,7,15,6:58,15:03,15
|
||||
3,,Średni,7:30,15:30,7:29,15:40,15
|
||||
3,,Mały,7:30,3:30,7:28,12:33,15
|
||||
3,P,Średni,7,15,7:57,14:59,15
|
||||
3,P,Mały,7,13,0:00,0:00,15
|
||||
3,,Duży,8,16,8:04,15:59,15
|
||||
3,,Średni,7:30,15:30,7:25,15:35,15
|
||||
3,P,Mały,8,16,8:02,15:58,15
|
||||
3,,Duży,7:30,15:30,7:28,15:34,15
|
||||
3,,Średni,8,16,7:53,16:01,15
|
||||
3,,Średni,7,12,6:58,12:05,15
|
||||
3,,Mały,8,13,7:56,13:59,15
|
||||
3,,Mały,7:30,12,7:24,12:28,15
|
||||
3,,Średni,8,14,8:01,14:07,15
|
||||
3,T,Duży,8,13,8:10,13:12,15
|
||||
3,,Średni,7:30,15:30,7:22,15:20,15
|
||||
3,P,Średni,8,16,7:49,15:58,15
|
||||
3,,Mały,8,16,7:45,16:10,15
|
||||
3,,Średni,7:30,15:30,7:31,15:35,15
|
||||
3,,Duży,7,15,6:57,15:01,15
|
||||
3,T,Średni,7,15,7:08,1:15,15
|
||||
3,,Mały,7:30,15:30,7:25,15:28,15
|
||||
3,,Duży,8,16,7:53,16:01,15
|
||||
3,P,Średni,8,16,7:56,15:58,15
|
||||
3,,Średni,7,15,6:56,15:03,15
|
||||
3,T,Mały,7,15,7,15:05,15
|
||||
3,,Średni,8,16,7:56,16:58,15
|
||||
3,P,Średni,7,15,6:57,14:59,15
|
||||
3,,Średni,7,15,6:55,14:58,15
|
||||
3,,Duży,8,16,8:02,16:07,15
|
||||
3,T,Średni,8,16,7:56,16:05,15
|
||||
3,,Średni,7,15,6:58,15:03,15
|
||||
3,,Duży,8,16,8,16:05,15
|
||||
3,,Mały,8,16,8:04,15:58,15
|
||||
3,,Średni,7:30,15:30,7:34,15:40,15
|
||||
3,P,Średni,8,16,7:53,16:01,15
|
||||
3,,Średni,8,13,7:49,13:02,15
|
||||
3,,Średni,7,15,6:58,15:04,15
|
||||
3,,Średni,7,15,7:08,15:05,15
|
||||
3,P,Średni,8,16,7:58,16:05,15
|
||||
3,,Średni,7,15,7:04,15:11,15
|
||||
3,P,Średni,6:30,14:30,6:25,14:29,15
|
||||
3,P,Średni,9,17,8:49,17:05,15
|
||||
3,,Średni,9,17,8:55,17:01,15
|
||||
3,P,Duży,7,15,6:58,15:10,15
|
||||
3,,Duży,7:30,15:30,7:25,15:31,15
|
||||
3,,Średni,7:30,11:30,7:27,11:32,15
|
||||
3,T,Średni,8,16,7:56,16,15
|
||||
3,,Średni,8,16,8:02,16:05,15
|
||||
3,,Średni,7:30,15:30,7:36,15:40,15
|
||||
3,,Średni,8,16,8:04,16:07,15
|
||||
3,P,Średni,8,9,7:59,9:09,15
|
||||
3,,Średni,7:15,15:15,7:10,15:18,15
|
||||
3,T,Duży,8,16,7:49,15:51,15
|
||||
3,,Średni,8,16,8:04,16:11,15
|
||||
3,P,Średni,8,16,8:02,16:03,15
|
||||
3,,Średni,7,15,7:01,15:07,15
|
||||
3,,Duży,7:30,15:30,7:25,15:25,15
|
||||
3,P,Średni,7,15,7:08,15:15,15
|
||||
3,,Średni,8,16,7:45,16:10,15
|
||||
3,,Średni,8,16,7:49,15:59,15
|
||||
3,,Średni,8,16,7:45,16:10,15
|
||||
3,T,Duży,7,15,7:07,15:20,15
|
||||
3,,Średni,7,15,7:02,15:11,15
|
||||
3,,Średni,8,16,8:06,15:49,15
|
||||
3,P,Średni,7,15,7:24,16:40,15
|
||||
3,,Średni,8,16,8:02,16:05,15
|
||||
3,,Duży,8,16,8:05,16:01,15
|
||||
3,T,Średni,7,15,7:13,15:13,15
|
||||
3,,Średni,8,16,7:36,16:00,15
|
||||
3,T,Średni,7,15,6:55,15:11,15
|
||||
3,,Średni,9,17,9:09,17:14,15
|
|
7
Assets/Data/Tablica1.csv.meta
Normal file
7
Assets/Data/Tablica1.csv.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0c5faf62b0aec144841274fbf661fa5
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Parking
|
||||
@ -18,6 +19,9 @@ namespace Parking
|
||||
var counter = 0;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if(line == "")
|
||||
continue;
|
||||
|
||||
if (counter == 0)
|
||||
{
|
||||
counter++;
|
||||
@ -27,11 +31,11 @@ namespace Parking
|
||||
var lineData = line.Trim().Split(',');
|
||||
var preference = lineData[0] == ""
|
||||
? ParkingPreference.Any
|
||||
: lineData[0] == "P"
|
||||
: lineData[1] == "P"
|
||||
? ParkingPreference.Front
|
||||
: ParkingPreference.Back;
|
||||
Size size;
|
||||
switch (lineData[1])
|
||||
switch (lineData[2])
|
||||
{
|
||||
case "Mały":
|
||||
size = Size.A;
|
||||
@ -50,11 +54,19 @@ namespace Parking
|
||||
break;
|
||||
}
|
||||
|
||||
DateTime realArrival = DateTime.Parse(lineData[4].Contains(':') ? lineData[4] : lineData[4] + ":00", CultureInfo.InvariantCulture);
|
||||
DateTime realDeparture = DateTime.Parse(lineData[5].Contains(':') ? lineData[5] : lineData[5] + ":00", CultureInfo.InvariantCulture);
|
||||
DateTime realArrival = DateTime.Parse(lineData[5].Contains(':') ? lineData[5] : lineData[5] + ":00", CultureInfo.InvariantCulture);
|
||||
DateTime realDeparture = DateTime.Parse(lineData[6].Contains(':') ? lineData[6] : lineData[6] + ":00", CultureInfo.InvariantCulture);
|
||||
DateTime plannedArrival = DateTime.Parse(lineData[3].Contains(':') ? lineData[3] : lineData[3] + ":00", CultureInfo.InvariantCulture);
|
||||
DateTime plannedDeparture = DateTime.Parse(lineData[4].Contains(':') ? lineData[4] : lineData[4] + ":00", CultureInfo.InvariantCulture);
|
||||
|
||||
Driver driver = new Driver(size, counter, preference);
|
||||
driver.Times = new[] {realArrival, realDeparture};
|
||||
if (!Int32.TryParse(lineData[0], out var priority))
|
||||
priority = 3;
|
||||
|
||||
if (!Int32.TryParse(lineData[7], out var updateInterval))
|
||||
updateInterval = 3;
|
||||
|
||||
Driver driver = new Driver(size, counter, preference, priority, updateInterval);
|
||||
driver.Times = new[] {plannedArrival, plannedDeparture, realArrival, realDeparture};
|
||||
Drivers.Add(driver);
|
||||
|
||||
counter++;
|
||||
|
@ -14,12 +14,16 @@ namespace Parking
|
||||
public bool Parked = false;
|
||||
public GameObject GameObject;
|
||||
public bool Rejected = false;
|
||||
public int Priority;
|
||||
public int UpdateInterval;
|
||||
|
||||
public Driver(Size size, int number, ParkingPreference parkingPreference)
|
||||
public Driver(Size size, int number, ParkingPreference parkingPreference, int priority, int updateInterval)
|
||||
{
|
||||
Size = size;
|
||||
Number = number;
|
||||
ParkingPreference = parkingPreference;
|
||||
Priority = priority;
|
||||
UpdateInterval = updateInterval;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
@ -41,7 +45,7 @@ namespace Parking
|
||||
public GameObject GameObject;
|
||||
public bool Free = true;
|
||||
public bool Reserved = false;
|
||||
public Driver ReservedDriver = null;
|
||||
public int ReservedPriority = 0;
|
||||
public ParkingPreference ParkingDirection = ParkingPreference.Any;
|
||||
|
||||
public Spot(Size size, bool flipped)
|
||||
@ -50,6 +54,10 @@ namespace Parking
|
||||
Flipped = flipped;
|
||||
}
|
||||
|
||||
public Spot()
|
||||
{
|
||||
|
||||
}
|
||||
public int CompareTo(Spot obj)
|
||||
{
|
||||
return Size.CompareTo(obj.Size);
|
||||
|
@ -51,9 +51,9 @@ namespace Parking
|
||||
// counts[(int) Size.D] += 1;
|
||||
var fixedCarSpots = 0;
|
||||
foreach (var c in counts) fixedCarSpots += c;
|
||||
Debug.Log($"Fixed car spots: {fixedCarSpots}");
|
||||
// Debug.Log($"Fixed car spots: {fixedCarSpots}");
|
||||
|
||||
Debug.Log("Calculating required spot counts...");
|
||||
// Debug.Log("Calculating required spot counts...");
|
||||
for (var i = 0; i < DataImporter.Drivers.Count && i + fixedCarSpots < carsToPlace; i++)
|
||||
counts[(int) DataImporter.Drivers[i].Size]++;
|
||||
|
||||
@ -63,7 +63,7 @@ namespace Parking
|
||||
Debug.Log(countsString);
|
||||
|
||||
|
||||
Debug.Log("Printing top 5 combinations...");
|
||||
// Debug.Log("Printing top 5 combinations...");
|
||||
foreach (var comb in Combinations)
|
||||
{
|
||||
var res = TestCombination(comb.ToArray(), spotCountsPerpendicular, spotCountsParallel, counts,
|
||||
@ -77,7 +77,7 @@ namespace Parking
|
||||
|
||||
private void PreProcessCombinations(out int[] spotCountsPerpendicular, out int[,] spotCountsParallel)
|
||||
{
|
||||
Debug.Log("Calculating spot counts...");
|
||||
// Debug.Log("Calculating spot counts...");
|
||||
float[] spotLengthsParallel = {4f, 4.5f, 5f}; //, 7.5f};
|
||||
spotCountsPerpendicular = new[] {0, 0, 0, 0};
|
||||
spotCountsPerpendicular[0] = Mathf.FloorToInt((ParkingManager.Width - 5.5f) / _spotWidth);
|
||||
@ -92,10 +92,10 @@ namespace Parking
|
||||
for (var j = 0; j < spotLengthsParallel.Length; j++)
|
||||
spotCountsParallel[3, j] =
|
||||
Mathf.FloorToInt((ParkingManager.Width - 5.5f - 3.6f * 2 - 2.5f * 4) / spotLengthsParallel[j]);
|
||||
Debug.Log("" +
|
||||
$"P1: {spotCountsPerpendicular[0]}/ P2: {spotCountsPerpendicular[1]} " +
|
||||
$"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " +
|
||||
$"Sum: {spotCountsPerpendicular.Sum()}");
|
||||
// Debug.Log("" +
|
||||
// $"P1: {spotCountsPerpendicular[0]}/ P2: {spotCountsPerpendicular[1]} " +
|
||||
// $"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " +
|
||||
// $"Sum: {spotCountsPerpendicular.Sum()}");
|
||||
|
||||
Debug.Log("Generating combinations...");
|
||||
int[] arr = {0, 1, 2, 3, 4};
|
||||
|
@ -13,6 +13,10 @@ namespace Parking
|
||||
|
||||
public static ParkingManager Instance;
|
||||
|
||||
private static readonly TimeSpan StartTime = TimeSpan.FromHours(5) + TimeSpan.FromMinutes(45);
|
||||
private static readonly TimeSpan EndTime = TimeSpan.FromHours(17) + TimeSpan.FromMinutes(15);
|
||||
private static TimeSpan _currentTime = StartTime;
|
||||
|
||||
[SerializeField] private int stepTime = 15;
|
||||
[SerializeField] private TextMeshProUGUI timeText;
|
||||
[SerializeField] public TextMeshProUGUI countsText;
|
||||
@ -25,14 +29,13 @@ namespace Parking
|
||||
|
||||
private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f};
|
||||
|
||||
public readonly List<List<Spot>> SpotMap = new()
|
||||
private readonly List<List<Spot>> _spotMap = new()
|
||||
{new List<Spot>(), new List<Spot>(), new List<Spot>(), new List<Spot>()};
|
||||
|
||||
private static readonly TimeSpan StartTime = TimeSpan.FromHours(5) + TimeSpan.FromMinutes(45);
|
||||
private static readonly TimeSpan EndTime = TimeSpan.FromHours(17) + TimeSpan.FromMinutes(15);
|
||||
private static TimeSpan _currentTime = StartTime;
|
||||
private int _initialConfigurationSpotCount;
|
||||
private int[] _rejectedDrivers = {0, 0, 0, 0};
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
@ -43,97 +46,141 @@ namespace Parking
|
||||
timeText.text = _currentTime.ToString();
|
||||
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
||||
$"Duże: {_rejectedDrivers[2]}";
|
||||
DataImporter.ReadFile("Assets/Data/v1.csv");
|
||||
Debug.Log(DataImporter.Drivers);
|
||||
DataImporter.ReadFile("Assets/Data/Tablica1.csv");
|
||||
InitialConfigurationGenerator generator = new();
|
||||
ArrangeSpots(generator.FindSolution());
|
||||
ReserveInitialSpots();
|
||||
}
|
||||
|
||||
private void ReserveInitialSpots()
|
||||
{
|
||||
for (var i = 0; i < Math.Min(DataImporter.Drivers.Count, _initialConfigurationSpotCount); i++) {
|
||||
bool found = false;
|
||||
// Find spot
|
||||
for (var j = 3; j >= 0 && !found; j--)
|
||||
foreach (Spot spot in _spotMap[j])
|
||||
if (spot.Size == DataImporter.Drivers[i].Size && !spot.Reserved) {
|
||||
spot.Reserved = true;
|
||||
spot.ReservedPriority = DataImporter.Drivers[i].Priority;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Find spot
|
||||
for (var j = 3; j >= 0; j--)
|
||||
foreach (Spot spot in _spotMap[j])
|
||||
if (!spot.Reserved && spot.Size != Size.D)
|
||||
Debug.Log("Spot not reserved");
|
||||
}
|
||||
|
||||
public void AdvanceTime()
|
||||
{
|
||||
// Update time
|
||||
_currentTime += TimeSpan.FromMinutes(stepTime);
|
||||
if (_currentTime > EndTime)
|
||||
{
|
||||
if (_currentTime > EndTime) {
|
||||
_currentTime = StartTime;
|
||||
// TODO: Reset spot reservations
|
||||
ResetDrivers();
|
||||
_rejectedDrivers = new int[]{0, 0,0 ,0};
|
||||
_rejectedDrivers = new[] {0, 0, 0, 0};
|
||||
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
||||
$"Duże: {_rejectedDrivers[2]}";
|
||||
timeText.text = _currentTime.ToString();
|
||||
return;
|
||||
}
|
||||
|
||||
timeText.text = _currentTime.ToString();
|
||||
foreach (Driver driver in DataImporter.Drivers)
|
||||
if (_currentTime <= driver.Times[1].TimeOfDay && _currentTime > driver.Times[0].TimeOfDay &&
|
||||
!driver.Parked && !driver.Rejected)
|
||||
{
|
||||
if (!PlaceCarOnParking(driver))
|
||||
{
|
||||
|
||||
|
||||
foreach (Driver driver in DataImporter.Drivers) {
|
||||
// TODO: Check if car can stay before other reservation
|
||||
var triesToPark = _currentTime <= driver.Times[3].TimeOfDay && _currentTime > driver.Times[2].TimeOfDay;
|
||||
var leftTheParking = _currentTime > driver.Times[3].TimeOfDay && driver.Parked;
|
||||
if (triesToPark && !driver.Parked && !driver.Rejected) {
|
||||
if (!PlaceCarOnParking(driver)) {
|
||||
Debug.Log($"Placing failed for car {driver.Number}");
|
||||
driver.Rejected = true;
|
||||
_rejectedDrivers[(int)driver.Size]++;
|
||||
_rejectedDrivers[(int) driver.Size]++;
|
||||
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
||||
$"Duże: {_rejectedDrivers[2]}";
|
||||
}
|
||||
}
|
||||
else if (_currentTime > driver.Times[1].TimeOfDay &&
|
||||
driver.Parked)
|
||||
{
|
||||
else if (leftTheParking) {
|
||||
driver.Spot.Reserved = false;
|
||||
driver.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetDrivers()
|
||||
{
|
||||
foreach (Driver driver in DataImporter.Drivers)
|
||||
{
|
||||
driver.Reset();
|
||||
}
|
||||
|
||||
private bool FindReservedSpot(Driver driver, out Spot spot)
|
||||
{
|
||||
foreach (var list in _spotMap)
|
||||
foreach (Spot spot1 in list)
|
||||
if (spot1.Reserved && spot1.ReservedPriority == driver.Priority) {
|
||||
spot = spot1;
|
||||
return true;
|
||||
}
|
||||
|
||||
spot = new Spot();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool PlaceCarOnParking(Driver driver)
|
||||
{
|
||||
for (var i = 0; i < SpotMap.Count; i++)
|
||||
foreach (Spot spot in SpotMap[i])
|
||||
if (spot.Size == driver.Size && spot.Free &&
|
||||
(spot.ParkingDirection == driver.ParkingPreference ||
|
||||
spot.ParkingDirection == ParkingPreference.Any))
|
||||
{
|
||||
spot.Free = false;
|
||||
driver.Spot = spot;
|
||||
driver.Parked = true;
|
||||
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
driver.GameObject.transform.position = spot.GameObject.transform.position;
|
||||
driver.GameObject.transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
|
||||
if (FindReservedSpot(driver, out Spot reservedSpot)) {
|
||||
if (reservedSpot.Free) {
|
||||
PlaceDriverOnSpot(driver, reservedSpot);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
Debug.Log("Spot should be reserved but is taken");
|
||||
}
|
||||
|
||||
for (var i = 0; i < SpotMap.Count; i++)
|
||||
foreach (Spot spot in SpotMap[i])
|
||||
if (spot.Size == driver.Size && spot.Free)
|
||||
{
|
||||
spot.Free = false;
|
||||
driver.Spot = spot;
|
||||
driver.Parked = true;
|
||||
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
driver.GameObject.transform.position = spot.GameObject.transform.position;
|
||||
driver.GameObject.transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
|
||||
foreach (var t in _spotMap)
|
||||
foreach (Spot spot in t) {
|
||||
var spotAvailable = spot.Size == driver.Size && spot.Free &&
|
||||
(spot.ParkingDirection == driver.ParkingPreference ||
|
||||
spot.ParkingDirection == ParkingPreference.Any)
|
||||
&& !spot.Reserved;
|
||||
if (spotAvailable) {
|
||||
PlaceDriverOnSpot(driver, spot);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var t in _spotMap)
|
||||
foreach (Spot spot in t)
|
||||
if (spot.Size == driver.Size && spot.Free && !spot.Reserved) {
|
||||
PlaceDriverOnSpot(driver, spot);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void PlaceDriverOnSpot(Driver driver, Spot spot)
|
||||
{
|
||||
spot.Free = false;
|
||||
spot.Reserved = false;
|
||||
driver.Spot = spot;
|
||||
driver.Parked = true;
|
||||
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
|
||||
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
driver.GameObject.transform.position = spot.GameObject.transform.position;
|
||||
driver.GameObject.transform.rotation =
|
||||
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
||||
}
|
||||
|
||||
public void UpdateText(string text)
|
||||
{
|
||||
countsText.text = text;
|
||||
@ -141,47 +188,43 @@ namespace Parking
|
||||
|
||||
private void ReconfigureSpots()
|
||||
{
|
||||
int[] freeSpots = GetFreeSpotCount();
|
||||
List<Driver> nextCars = GetNextCars(10);
|
||||
int[] plannedSpots = new[] {0, 0, 0, 0};
|
||||
var freeSpots = GetFreeSpotCount();
|
||||
var nextCars = GetNextCars(10);
|
||||
int[] plannedSpots = {0, 0, 0, 0};
|
||||
foreach (Driver driver in nextCars)
|
||||
plannedSpots[(int)driver.Size]++;
|
||||
plannedSpots[(int) driver.Size]++;
|
||||
|
||||
int[] neededSpots = new[] {0, 0, 0, 0};
|
||||
int[] neededSpots = {0, 0, 0, 0};
|
||||
|
||||
for (int i = 0; i < neededSpots.Length; i++)
|
||||
for (var i = 0; i < neededSpots.Length; i++)
|
||||
neededSpots[i] = Math.Max(freeSpots[i] - plannedSpots[i], 0);
|
||||
if (neededSpots.Max() > 0)
|
||||
{
|
||||
if (neededSpots.Max() > 0) {
|
||||
Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}");
|
||||
Debug.Log($"Attempting reconfiguration...");
|
||||
Debug.Log("Attempting reconfiguration...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int[] GetFreeSpotCount()
|
||||
{
|
||||
int[] freeSpots = new[] {0, 0, 0, 0};
|
||||
foreach (var t in SpotMap)
|
||||
int[] freeSpots = {0, 0, 0, 0};
|
||||
foreach (var t in _spotMap)
|
||||
foreach (Spot spot in t)
|
||||
if (spot.Free)
|
||||
freeSpots[(int)spot.Size]++;
|
||||
freeSpots[(int) spot.Size]++;
|
||||
return freeSpots;
|
||||
}
|
||||
|
||||
private List<Driver> GetNextCars(int n)
|
||||
{
|
||||
List<Driver> nextCars = new List<Driver>();
|
||||
var nextCars = new List<Driver>();
|
||||
TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime);
|
||||
while (nextCars.Count < n && updatedTime < EndTime)
|
||||
{
|
||||
while (nextCars.Count < n && updatedTime < EndTime) {
|
||||
foreach (Driver driver in DataImporter.Drivers)
|
||||
if (_currentTime + updatedTime <= driver.Times[1].TimeOfDay &&
|
||||
_currentTime > driver.Times[0].TimeOfDay &&
|
||||
if (_currentTime + updatedTime <= driver.Times[3].TimeOfDay &&
|
||||
_currentTime > driver.Times[2].TimeOfDay &&
|
||||
!driver.Parked && !driver.Rejected && !nextCars.Contains(driver))
|
||||
{
|
||||
nextCars.Add(driver);
|
||||
}
|
||||
updatedTime += TimeSpan.FromMinutes(stepTime);
|
||||
}
|
||||
|
||||
@ -195,11 +238,9 @@ namespace Parking
|
||||
var maxP3 = _spotHeights[(int) spotMap[2].Max().Size];
|
||||
var maxP2 = _spotHeights[(int) spotMap[1].Max().Size];
|
||||
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
for (var i = 0; i < 4; i++) {
|
||||
float currentY;
|
||||
switch (i)
|
||||
{
|
||||
switch (i) {
|
||||
case 0:
|
||||
currentY = -Height / 2.0f + 2f;
|
||||
break;
|
||||
@ -224,12 +265,10 @@ namespace Parking
|
||||
var flipped = false;
|
||||
var parkingFromTop = i % 2 != 0;
|
||||
|
||||
for (var j = 0; j < spotMap[i].Count; j++)
|
||||
{
|
||||
for (var j = 0; j < spotMap[i].Count; j++) {
|
||||
spotMap[i][j].Flipped = flipped;
|
||||
var alignTop = i % 2 != 0;
|
||||
switch (spotMap[i][j].Size)
|
||||
{
|
||||
switch (spotMap[i][j].Size) {
|
||||
case Size.A:
|
||||
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA);
|
||||
spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0);
|
||||
@ -268,15 +307,17 @@ namespace Parking
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
for (var j = 0; j < spotsCreated.GetLength(1); j++)
|
||||
for (var k = 0; k < spotsCreated[i, j]; k++)
|
||||
SpotMap[i].Add(new Spot((Size) j, false));
|
||||
for (var k = 0; k < spotsCreated[i, j]; k++) {
|
||||
_spotMap[i].Add(new Spot((Size) j, false));
|
||||
_initialConfigurationSpotCount++;
|
||||
}
|
||||
|
||||
SpotMap[0].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
||||
SpotMap[1].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
||||
SpotMap[2].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
||||
SpotMap[3].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
||||
SpotMap[2].Add(new Spot(Size.D, false));
|
||||
return SpotMap;
|
||||
_spotMap[0].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
||||
_spotMap[1].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
||||
_spotMap[2].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
||||
_spotMap[3].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
||||
_spotMap[2].Add(new Spot(Size.D, false));
|
||||
return _spotMap;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user