@Zenassem,
Great minds...
Here's code that does the job, using an insertion sort:
global Players as integer
global Scores as integer
Players = 6
Scores = 6
dim Name(Players-1) as string
dim TotalScore(Players-1) as integer
dim ScoreOfShot(Players-1, Scores-1) as integer
for i = 0 to Players-1
read Name(i)
Total = 0
for j = 0 to Scores-1
read ScoreOfShot(i, j)
inc Total, ScoreOfShot(i, j)
next
TotalScore(i) = Total
next
y = 20
for i = 0 to Players-1
text 0, y, Name(i)
text 100, y, right$( " " + str$( TotalScore(i) ), 3 )
for j = 0 to SCores-1
text 130 + j * 30, y, right$( " " + str$( ScoreOfShot(i, j) ), 3 )
next
inc y, 20
next
SortScores()
inc y, 40
for i = 0 to Players-1
text 0, y, Name(i)
text 100, y, right$( " " + str$( TotalScore(i) ), 3 )
for j = 0 to Scores-1
text 130 + j * 30, y, right$( " " + str$( ScoreOfShot(i, j) ), 3 )
next
inc y, 20
next
wait key
end
function CompareItems(a as integer, b as integer)
` Returns
` negative if a < b
` zero if a = b
` positive if a > b
` Initial check is totalscore
if TotalScore(a) <> TotalScore(b) then exitfunction TotalScore(a) - TotalScore(b)
` If they are equal, fall back on each of the other scores
for j = 0 to Scores-1
if ScoreOfShot(a, j) <> ScoreOfShot(b, j) then exitfunction ScoreOfShot(a, j) - ScoreOfShot(b, j)
next
` If they are all equal, then fall back on the names as a tie-break
if Name(a) < Name(b) then exitfunction -1
if Name(a) > Name(b) then exitfunction 1
endfunction 0
function SwapItems(a as integer, b as integer)
Temp = TotalScore(a)
TotalScore(a) = TotalScore(b)
TotalScore(b) = Temp
for j = 0 to Scores-1
Temp = ScoreOfShot(a, j)
ScoreOfShot(a, j) = ScoreOfShot(b, j)
ScoreOfShot(b, j) = Temp
next
Temp$ = Name(a)
Name(a) = Name(b)
Name(b) = Temp$
endfunction
` Simple intersion sort
function SortScores()
for a = 0 to Players-2
Top = a
for b = a + 1 to Players-1
` If the top item is less-than the current item, make the current item the top item
if CompareItems(Top, b) < 0 then Top = b
next
if Top <> a then SwapItems(a, Top)
next
endfunction
data "Picard", 100, 99, 100, 100, 100, 98 ` 597
data "Ivanov", 100, 100, 100, 100, 99, 100 ` 599
data "McKay", 100, 100, 99, 100, 100, 100 ` 599
data "Jones", 99, 100, 100, 99, 100, 100 ` 598
data "Mendez", 100, 99, 100, 99, 100, 99 ` 597
data "Smith", 100, 100, 99, 100, 99, 100 ` 598
I've unnecessarily complicated things by using zero-based arrays, and variables that hold the count and not the top item - sorry, I can't work up the enthusiasm to go back and fix that.
The sort itself and the 'swap' function were fairly simple and mechanical to write (I wrote them on 'auto-pilot) - it's the comparison function that you need to think about carefully when comparing multi-valued items.
Alternatively, you can use a stable sort to sort by score 1, then score 2, etc up to score 6, then sort by total score, and you'll get the same result - this is how you do it in Excel when you have more than 3 fields to sort by, as Excel also uses a stable sort (not sure which one though).