I started out today by adding two more states to a user:
abandon, cutoff,
Abandon means that the user gives up on the line and leaves. Cut off means the user wanted to use a system for longer, but didn't.
Neither of these is affected by the tick method. Once a user has left the line or been kicked off the system, it doesn't matter how much time passes for them.
So, what does the tick method for each of the three methods accomplish?
Here is DataUser.tick:
public void tick (int thisTick)
{
if (thisTick [LESSTHAN] queueUpTime) return;
if (state == State.sitting) { desiredTime--; }
else if (state == State.waiting) { patienceTime--; }
#if DEBUG
if (queueUpTime [LESSTHAN] 0) { throw new Exception(); }
if (patienceTime [LESSTHAN] 0) { throw new Exception(); }
if (desiredTime [LESSTHAN] 0) { throw new Exception(); }
#endif
}
This method is exited immediately if a user is not, yet, in the line.
After that, the desired time and patience time decrease when the user is in the relevant state.
Here's Seat.tick:
public void tick()
{
if (occupied) {
useTime--;
if (useTime [LESSTHAN] 0) useTime = 0;
}
}
If a seat is occupied, its use time is cut by one tick each tick.
Here's Simulation.tick:
public void tick()
{
simTick++;
}
Well, this one needs the most work. How about this:
public void tick()
{
simTick++;
foreach (DataUser a in computerQueue) {
a.tick(simTick);
}
foreach (Seat b in seats) {
b.tick();
}
}
After I caught a typo, this compiled fine. That is, it didn't break any tests.
Still, there aren't any tests that it could hurt much.
Several things have to happen: there needs to be a pass through the seats to see if there are any empty seats and then each empty seat needs to be filled, if possible.
I'm going to start this by adding a field for a current user:
private DataUser currentUser = null;
I want the seat to be able to poll it's individual user to see if the user is done.
If I remove a user from the computer queue list after associating it with the seat, then, later, when I delete it from the seat, it will be ready for garbage collection.
And that will be for tomorrow – I will start working on assigning the user to the seat when the seat is empty.
No comments:
Post a Comment