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.

AppGameKit Classic Chat / Sorting Typed Array (and .Swap)

Author
Message
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 04:04 Edited at: 28th Mar 2020 04:09
the following code is suppose to
1) "initiallize" a typed array under GenerateScores() (just filling it with -1 values for now - not the issue).
2) generate a random score, # of seconds it took the achieve the score, and add a date (using Timer() vs date for now to try and sort the issue) as a Type (ScoreData).
3) then CheckScore() to see if it makes the Top Ten list (i'll deal with return of any new rank later)



the desired sorting results aren't quite right where, if a score is equal to one already in the list, the seconds are checked. if the seconds are <= to that score and seconds, i want it to go on top. IE, as it climbs up from the bottom, it should be swapped.

since the scores are timestamped, for any new score and seconds that are duplicates, the most-recent one should rank above the other.

ie, the bottom 4 (which are identical in score and seconds) should be sorted newest to old (9, 7, 6, 8) but aren't:



neither are ranks 3-5, while ranks 0-2 are... something's amiss.


meanwhile, i'm attempting a manual swap using HoldScore, HoldSeconds, HoldDate$ where Scores.Swap(x,x-1) didn't seem to be swapping all values of the type?

any guidance is appreciated

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Mar 2020 05:36 Edited at: 28th Mar 2020 05:36
Quote: "the desired sorting results aren't quite right where, if a score is equal to one already in the list, the seconds are checked"

It only uses the first field. I would add a field at the start that is say "key as float" and make key = (score * 1000 ) + seconds
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 15:31
Quote: "It only uses the first field"

i think you're talking about .sort and .insertsorted behavior, which i'm not using.

otherwise, this line:
If AboveScore = -1 or IndexScore < AboveScore or IndexScore = AboveScore and IndexSeconds <= AboveSeconds

is almost doing what it's supposed to. the scores|seconds part is right in the results (graphic above) but if the score and seconds match, the most-recent score should be above the older score which means the time (3rd field) should end up sorted (large to small, decending) on it's own.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 16:56
here's simpler test code where the score and seconds ALWAYS match:


you'll see that the Timer() element (3rd column) is properly sorted (new to old). IE, the same logic works as i'd like it to so, something is wrong in my logic:

If AboveScore = -1 or IndexScore < AboveScore or IndexScore = AboveScore and IndexSeconds <= AboveSeconds


nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 28th Mar 2020 17:24
Out of habit, I always evaluate logic gates atomically to avoid compound issues (varies from language to language)
It's not clear for instance if you intend the AND part to apply just to "IndexScore = AboveScore" or the whole condition.

thus:



nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 28th Mar 2020 17:29
Just for reference, I had 6 or more highscore lists with multiple ordering possibilities in Refender.
For simplicity, I added a potential new score/whatever to the array and sorted the array on required field (not using the inbuilt one, just a flag sort) and just dropped off the lowest one.

If you run your own generic sort over 2 or more columns individually, then the same rule applies.
I found this approach easier, as I wrote a sorter that did all the different tables in any order or ruleset.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 18:03 Edited at: 28th Mar 2020 18:05
i want:
if (AboveScore = -1) or (IndexScore < AboveScore) or ( (IndexScore = AboveScore) and (IndexSeconds <= AboveSeconds) ) i think?

or:


does that help explain?

meanwhile the updated function works if the score and seconds match. but if the new score matches and the new seconds don't, it doesn't (it seems 50/50 whether or not they get swapped).

IE, changing:

to:

...breaks it/doesn't work:


why is 3.210794 in the middle instead of the bottom where it's the oldest matching score and seconds entry?

Attachments

Login to view attachments
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 28th Mar 2020 18:43 Edited at: 28th Mar 2020 18:43
I can't see where the float column is ever being checked so how can it ever influence the sort order?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 18:53 Edited at: 28th Mar 2020 18:55
Quote: " can't see where the float column is ever being checked"

it isn't/shouldn't. i'm using it to determine WHEN the entries based on Score and Seconds are entered. if the scores and seconds match, the most-recent one should rank above the other just as they do for all BUT 3.210794 which should be on the bottom (oldest matching score and seconds).
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Mar 2020 19:30 Edited at: 28th Mar 2020 19:39
if i change to sorting from the top:


...it works as i'd like it (and it's less convoluted) so i'll go with that but i would still like to know why climbing from the bottom doesn't work (where the idea was to stop the loop if the new score didn't climb/out of efficiency).

i guess i can still do that (no, i can't...)
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 28th Mar 2020 19:34
Oh, you mean because the larger the number, the most recently it was added, so it should be at the end of the array?

Another thing I see is that you are doing potential multiple swaps in each iteration of X (doing swaps on things that may have been swapped if you get my meaning)
Another reason to do this in passes?

Login to post a reply

Server time is: 2024-11-22 04:07:03
Your offset time is: 2024-11-22 04:07:03