Counting laps and lap times

fmfm20j

Member
Joined
Dec 31, 2006
Messages
5
Programming Experience
10+
I've been driving myself mad trying to come up with some suitable code in VB.net to sort out the race order of 6 slot cars on a digital scalextric track. So far, whatever I have tried seems to have failed. Here is what I have and what I want to get:

Up to 6 cars can race on the track at any one time. The control unit sends out a timestamp each time the car crosses the start/finish line. My existing software counts the the number of times a time stamp has occurred for each car and this gives me the lap number that each car is on. The timestamp for each car is also saved.

What I want as a result is an array (or something like an array) telling me the race order.

So, if I had the following data for the car name, the current lap number and the last timestamp:

Car 1 is on lap 10 and the last timestamp was 100.32
Car 2 is on lap 9 and the last timestamp was 101.02
Car 3 is on lap 11 and the last timestamp was 101.22
Car 4 is on lap 8 and the last timestamp was 102.10
Car 5 is on lap 7 and the last timestamp was 103.31
Car 6 is on lap 12 and the last timestamp was 99.12

<this could be in the form of a structure type or three arrays
car# , Lap #, last timestamp#>

I could sort the race order quite easily based purely upon the lap number and I could ignore the timestamp

Car 6 is on lap 12 and the last timestamp was 99.12
Car 3 is on lap 11 and the last timestamp was 101.22
Car 1 is on lap 10 and the last timestamp was 100.32
Car 2 is on lap 9 and the last timestamp was 101.02
Car 4 is on lap 8 and the last timestamp was 102.10
Car 5 is on lap 7 and the last timestamp was 103.31

However, if 3 of the 6 cars were on the same lap. I would need to first sort the results based upon the highest lap number and then I would need to sub sort these three results based upon the lowest valued timestamp:

Car 1 is on lap 10 and the last timestamp was 100.32
Car 2 is on lap 9 and the last timestamp was 101.02
Car 3 is on lap 10 and the last timestamp was 101.22
Car 4 is on lap 8 and the last timestamp was 102.10
Car 5 is on lap 7 and the last timestamp was 103.31
Car 6 is on lap 10 and the last timestamp was 99.12

the result would be:

Car 6 is on lap 10 and the last timestamp was 99.12
Car 1 is on lap 10 and the last timestamp was 100.32
Car 3 is on lap 10 and the last timestamp was 101.22
Car 2 is on lap 9 and the last timestamp was 101.02
Car 4 is on lap 8 and the last timestamp was 102.10
Car 5 is on lap 7 and the last timestamp was 103.31

Obviously, having three cars on the same lap is just a typical situation. All 6 cars could be on the same lap, 2 cars could be on the same lap, 2 others on a different lap, and the final two on different laps again.

So, please could you suggest a way for me to sort the data by way of an algorithm, to present the data to the algorithm in a suitable way and to preserve the car number throughout (by this, I mean, I don't simply want to know that 3 cars are on lap 10, I need to know which 3 of the 6 cars are on lap 10 and in which order).

There's probably a very simple way to do this in VB.net. I'm very much a beginner and I get easily confused by terminology. Any simple to understand code without too many difficult to understand terminology would be very much appreciated.

Then , once I have this working I can enjoy the slot car racing hobby once again and have some decent race timing software to use with it!

Many thanks for you help.
 
This is the sort of thing we use databases for...

SELECT * FROM raceTimes ORDER BY lapNumber DESC, timeStamp
 
Thanks for the reply,
I don't understand what the code would look like. Is it as you have described or could you give me a simple snippet?
 
I dont really know, other than writing the whole thing for you.. The scope of the project is beyond this forum im afraid! Have a go at storing the lap data in a database (read the DW2 link in my signature) and then we can help you with dragging it into a represented format
 
Or you could create a DataTable.

Give each car an ID number, and treat that as the primary key of the datatable.

Then to get the results out in a sorted manner, you would use

For each dr as datarow in dtCars.Select("*","LapNumber, Timestamp")

Good luck!
 
Back
Top