I need help with following Car race Algorithm.
I am writing a simple car race program.
In a race, the LeaderBoard tracks the current order of the cars, who
is in first place, etc. We have 10 Cars in the race and we want to know
what order the cars are in. So we will periodically call UpdateLeaderBoard.
Assume that we have a record or a structure, Car, in pseudo-code:
Car
Name: String;
StartPos: Int;
CurPos: Int;
Speed: Int;
end;
You can make it into an object if you want.
Assume for now that the track is straight, don't have to take
laps into account. I am only concerned with distance from some
0 point. To make it interesting, not all the cars start at the same point.
Position, here, refers to location on the track, not ranking on
the LeaderBoard.
Assume that we can initialize the cars by reading data in from a
file.
Something like
proc InitCars
begin
I = 0;
while I < 10 do
begin
ReadXML(Cars[I]);
Next(I)
end
end
The routine that calculates the leaders should be called several
times throughout the race to find the current ranking.
Show me, in pseudo-code or language of your choice, what that
overall program would look like. I'm especially interested in
the details of UpdateLeaderBoard and how it is called.
I've purposely not been very precise in my problem statement.
Assume this is the just the beginning of the program and we
will be adding lots of features to it, so we want it to be
maintainable.
Please offer your help.
Thank you.
Ratnayake

