This proved to be rather easy MUCH to my surprise. It
became clear to me that the only time my train would hit a photocell
was if that cell was allocated to me already. So, if a cell
got covered up and it was not allocated to the train, the allocation
array[cell#] would be set to 2. 2 meant that something other
than the train had the cell. It could be a shadow of someone
leaning over the track or a hand or a tree. If when the train
requested the next cell, the allocation for that cell was already 2,
then the train would be blocked. A flag was set in the train
object that it was blocked and the OS kept track of what cell blocked
it. This way, when there was a departure on a cell that was
allocated to 2, a check could be made to see if the train was
blocked on that cell. If so, the train would become
unblocked and it would be granted that photocell as a resource. If the
train was not blocked on that cell, then the allocation table simply
de-allocated it. As long as a train was blocked, it is unable
to move.
I originally had intentions of making a small language for the
train to obey that would have a simple if blocked statement.
This way, the train would be able to follow an alternate path if it
was blocked. But the scope of this project ruled that
possibility out.