nus-cs2030 / 2122-s2

CS2030 repository and wiki for AY 2021/2022 Sem 2
MIT License
0 stars 0 forks source link

Level 6_2 Additional Event Class #434

Open ImAshuaige opened 2 years ago

ImAshuaige commented 2 years ago

Hi! I'm having issues(infinite loop) testing level 6 cases. image

I think the problem is with my pending class.

The approach I used for this level is: I created a pending class and do Arrive -> Serve/Wait/Leave Wait -> Serve/Pending Serve -> Done.

In My Pending class, I first check if the waiting customer is the first one in the queue by checking the customer ID the the index 0 customer in the queue(not quite sure abt this bit) my codes are smth like: this.waitingServer.getWaitingQueue().get(0).getID() == this.getCustomer().getID() If this is true, I return a serve event. else, I return a pending event passes in the updated time, which is the waiting server's next available time.

Anyone uses similar structure could kindly tell me where I went wrong? ><

ngnevan1 commented 2 years ago

Your logic sounds ok. You might want to check that the updated time you are getting is from an updated server (from the shop variable that has been passed into the execute method) not from the pending event itself.

seanpbteo commented 2 years ago

Hello, I also encountered infinite loops with my pendingEvents a lot as well. I think that the problem lies with not updating the server that's passed into the next event with the updated server from the shop. Hope this helps!

ImAshuaige commented 2 years ago

Your logic sounds ok. You might want to check that the updated time you are getting is from an updated server (from the shop variable that has been passed into the execute method) not from the pending event itself.

Thank you for your response!! May I clarify the are you referring to the updated time that will pass into the Pending event from Pending class? Also, to find the updated server is it just loop thru the pass-in Shop servers list and find the one has the same ID with the current waiting server?

WenJett commented 2 years ago

Hello,

Your logic is same as mine and it is fine. Most likely you did not use the updated version of Server in the shop to get the necessary nextAvailableTiming etc. To find the Server in the shop you can just match the ServerID as what you have mentioned.

ImAshuaige commented 2 years ago

Hello, I also encountered infinite loops with my pendingEvents a lot as well. I think that the problem lies with not updating the server that's passed into the next event with the updated server from the shop. Hope this helps!

Thank you for you response!! I'm a bit confused about update server part, do we need to update the server when creating both serve and pending event in the pending class? and how are we suppose to update it? :)

ImAshuaige commented 2 years ago

erver in the shop you can just match the ServerID as w

Hello! Thanks for replying!! Yes I tried to update the server. image I did smth like this. And i got some IndexOutOfBound exceptions error. Do we pass in the updated server to both new Serve event / another Pending event? Also which server do we use to check if the customer ID are the same? quite confused..

WenJett commented 2 years ago

Hi,

I also just matched by Server ID only but did not get that exception error, I just loop for (Server server : servers) and the if statement is the same. Not quite sure why you would get IndexOutOfBound error.

You should pass the updated server to both the new Serve and Pending event. You should use the new Server to check the customer ID as the new Server has the original customer who have been served removed, so the first customer in that new Server is the one u are trying to find and match to return the new Serve event. The new Server and old Server main difference is the nextAvailableTime and the status of ImList of Customer which would affect your flow of code.

Ohnojiso commented 2 years ago

For me my pending event is exactly the same as my wait event, except that its toString is just an empty String. For the updatedServer I simply filtered the shop's list using the serverID I have and .get(0). This should not cause the IndexOutOfBound exception as long as your serverID is valid. If this issue persists after you have done so maybe you want to check if you have accidentally dropped the server from the shop's serverList in any of your events.