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 / a sorting problem...

Author
Message
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 12th Apr 2004 07:17
Hiya guys! how's everyone doing?

Oh well...while i'm trying to solve my RTS problem i've tried to make a small game and now it's 80% finished. It's secret so I can't say anything about it until I release it (no big deal ) but I'm blocked with this problem (I'm full of them, right?):

It's basically about a sorting problem. I have a file that stores the high scores of the game, like this:

DARKGuy
100000
Binary Moon
80000
You
60000

And so on. The first line is the name and the second line is the score. I can read them and store them in arrays and then display them. The problem is that I can't sort them. You know, a sort function. I don't know how to make one, and i'm sure that someone would have to do one for his game, so I ask that please someone could give me a hand with this, or at least a code snippet, or if there's already a code snippet for it (DBC) then help me and put the url here please.

I'm gonna look right now the code snippets.

Thanks in advance

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 12th Apr 2004 07:22
I found 2 sort functions, one from Atom Software and other from John James, I'm gonna see if I can convert them to DBC...

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 12th Apr 2004 17:06
mmmm ok, I converted the Mighty Atom Software Quicksort function. But now I have another problem.....oh god. Well....I can sort the high scores, but how I do to link the names to their respective scores?

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 12th Apr 2004 20:01
if you have the names in one array and the scores in the corresponding array then just slave one to the other, ie

name$(i)=name$(dest)
score(i)=score(dest)

(or however the sort you are using swaps the values over, just mimick the actual number swap on you names array so thet the name makes the same moves as the number, or just memorise the position the number started from and the position it ends up at and then swap the names round to match, cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 13th Apr 2004 00:39
hmmmmm I tried to do that before you replied, linking the name to his respective score, but it didn't work, I always get an error, like if I'm using wrong values, mixing numbers with strings, and I wasn't doing that.....I'm using this function:



the GeneralArray is for the numbers, and I'm using a new array (Name$) to put the names and just doing with it what GeneralArray does, but when it comes to GeneralArray(Left) = pivot I can't do that with the Name$ array, so how can I do it then?

Thanks for your reply

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 13th Apr 2004 23:51
:bump: umm anyone here?

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 14th Apr 2004 05:51 Edited at: 14th Apr 2004 05:56
Your best method will probably be the brute force method.



I am just comparing and swaping values. nothing fancy here.
I did have to cheat to get the check routine to work from the last array element and work our way to the top.

You can also add acheck to make it jump out of the loop when Highscore is no longer larger than the checked array element but I had a little trouble figuring out why my checks and swaps were not being done.

hope this helped.

Wasting CPU Cycles since the 286 was a hot machine.
Joe Cooning
22
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 14th Apr 2004 18:11
I made tutorials earlier for DBC. They include to sort methods that you can use. Get the tutorials here=>http://www.angelfire.com/games5/joecooning/tutorials.zip

"The greatest oxymoron . . . ever, 'Microsoft Works'."
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 15th Apr 2004 19:10
@DBoy780: wow that code is just what I needed! I'm gonna see if I can implement it to my own code. Thanks!!!!!!!!

@Joe Cooning: how generous of you good tutorials indeed I'm gonna see what sorting method I'm gonna use for my game, also your tutorials look interesting though

Thanks all you guys

:: Pentium 300 Mhz, old 8Mb video card, 64Mb RAM, 5 gb & 1.6 gb HD's, W98 SE, Sound Blaster AWE 32 ::
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 16th Apr 2004 02:47
Just glad I could help for a change.

Just a note though.
This sorting method is brute force and will not be the fastest method and will not work as written with an unsorted list but if you start with an empty list or a presorted it wont be to difficult to make it work for your needs.

Wasting CPU Cycles since the 286 was a hot machine.

Login to post a reply

Server time is: 2025-05-24 03:05:46
Your offset time is: 2025-05-24 03:05:46