Given four maps open time and their last time(the unit is day):
NAME | AVAILABLE_TIME | LAST_TIME
mapA | 8 | 3
mapB | 11 | 3
mapC | 15 | 3
mapD | 35 | 3
This means:
The 1th day is server open day.
On 8th day, the mapA becomes available;
On 11th day, the mapB becomes available;
On 14th day, the mapC becomes available;
On 35th day , the mapD becomes available;
If any of the map is opened, it will last LAST_TIME days. When the opened map is finished, at 00:00 AM, the system will check if the next map exists and is available, if it is, the system will close the current map and open the next map, otherwise the system will open available maps from the begning.
For example, from 1th day to 7th day, none of the maps is available, thus there's no map to open.
At the 8th day, the mapA becomes available so it would be opened and will last 3 days.
On the 11th day, the system will close mapA and find the next mapB is available now, so it will open mapB. The mapB will last 3 days.
On 14th day, mapB is closed and the system find the next mapC is not available, so it then opens the available maps from the begining, which is to open mapA this day.
On 17th day, the system close mapA and open mapB. On 20th day, mapC becomes opened.
I don't know how to convert the whole process into a method, by entering a number of days and obtaining the map that should be opened on that day. My mind always feels confused when try to code it, especially the cycle that opens the map. Could someone teach me how to code this logic(If you write some code, any language or pseudo code is okay), or just a little bit of thinking is also welcome.
After some thinking, I find a solution: