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.
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.