We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to create a parking lot simulator for my first year engineering class. You can find the details for the assignment here: http://docdro.id/7ZyzCEF. I'm now trying to complete the third milestone. The cars are supposed to randomly enter the lot and then random stalls should become occupied (turn red) when the car enters. The stalls should be occupied for a random amount of time before the car leaves the lot out the exit. I managed to make the cars enter the lot randomly, however from there I don't know how to make them randomly occupy stalls and stay there only for a specific time before leaving again. Does anyone know how I would do this?
[ code in comments ]
Answers
Third time we've seen this so search the forum.
Edit post, highlight code, press Ctrl-o to format. We can't read the code you've posted the way it is.
When a car enters the lot, pick one of the parking lot sections for it to park in. Keep picking sections until you find one that has a free space. There must be one because the car was allowed into the lot, right? Then pick a parking spot in that lot. Keep picking them until you find a free space. There must be one because you picked a section that had a space!
Then generate a random number that will represent the total time that car is going to be parked in that space for. Add that amount of time to the current simulation time to get the time the car will exit. You can store this value with the car, or you could associate it with the parking space instead. In either case, every time the simulation time changes, you should be checking all the spots to see if it is time for any of their cars to leave.
Yeah, but you could've edited the original post rather than posting again...
Sorry, this is my first post on this forum, any help with the question would be greatly appreciated.