Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Bubblesort for Racing Game - Help Reqd. Pls

Author
Message
DemonHill
17
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 4th Jun 2008 00:52
I am writting a racing game, and whilst I am comfortable with bubble sort, the complication comes because the driver laptime has to be calculated each lap, and the variable i.e position of driver variable in an array requires me to re-order the drivers back to allow laptime calculations.. Sorting is down by Racetime not laptime as such...

Anyone used bubble sort in this situation where it's not as simple as a one off table of high scores ?
DemonHill
17
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 4th Jun 2008 11:21
This is the concept

Driver(1)=Mshumacher:Laptime(1)=RND(100):Team$(1)="Ferrari":RaceTime(1)=RaceTime(1)+Laptime(1)

Driver(2)=Button:Laptime(2)=RND(200):Team$(2)="BAR"":RaceTime(2)=RaceTime(2)+Laptime(2)

Driver(3)=Webber:Laptime(3)=RND(300):Team$(3)="REDBULL"":RaceTime(3)=RaceTime(3)+Laptime(3)

These will be in a loop for each lap and the driver position will be sorted on the Racetime... trouble is because the laptime calculation needs to be different for each driver, how do I match position of driver in a sort table to allow the correct array position.... ????
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 4th Jun 2008 12:40
Hi there!

Here is the subroutine I used to determine ladder placings in a football programme ...... hope it gives you a guide. Because it contains goto's, I have included line numbers to indicate where to jump to. You will have to restructure for DB.



LANG MEY YER LUM REEK

And in the end, it's not the years in your life that count, it's the life in your years
DemonHill
17
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 5th Jun 2008 21:34
So would you use something like:-

tn$(1)="LiverpoolFC"
tn$(2)="Manchester"

using a fix location for the array.

And when you rerun the sort, after each game, do you have to unsort the teams to get the scores or just use the loop again and again ?
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jun 2008 05:37 Edited at: 6th Jun 2008 05:38
You could store every lap for each driver, start all off at 9999 seconds (or whatever they'll never reach), then replace this with the actual lap time and sort all drivers when someone completes a lap (sort by total lap times).

It is far better to complete a 10 line program than to start a 10,000 line program.
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 6th Jun 2008 05:42 Edited at: 11th Jun 2008 02:53


Hope this helps

LANG MEY YER LUM REEK

Progress is like a wheelbarrow. If you don't keep pushing it, it stops
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 11th Jun 2008 02:56
Hi DemonHill

Was the snippet of any help?

LANG MEY YER LUM REEK

Progress is like a wheelbarrow. If you don't keep pushing it, it stops

Login to post a reply

Server time is: 2025-06-05 23:42:43
Your offset time is: 2025-06-05 23:42:43