Main Menu

who's winning?

Started by dangerousbrian, June 30, 2005, 01:39:05 PM

Previous topic - Next topic

dangerousbrian

This may seem a thick question but I'm gonna ask it anway...................

I've seen some examples of sorting a list of six (or lots more!) numbers, but can't work out what to do if 2 or more of the numbers equal the same. How do you place one above the other? (without letting it = one of the other numbers)

(I've only spent a day puzzling over this one!)

dangerousbrian

kevin

if their equal, then it's a dead heat.

if your sorting a list of random values (well race results :) ), there may well be times when two or more players have the same time.

I assume your trying to detect from the sorted list which result belongs to what player ?

dangerousbrian

#2
I'm enjoying myself with the ostriches! (but my version will never be useable, it's just a learning experience for me)

I'm sorting variables (trying to use the swap if higher command) so I know that variable posa (for example) will always relate to runner one. Its just that when runner one is in the same place as runner 2 the obvious answer is to inc one of them, but then the problem arises that runner 1 may now be in the same position as runner 3, so I'm back to square one...
dangerousbrian

kevin

yeah if you adjust a dead heat result to ensure their unqiue, then you'll have to check that your adjustment doesn't clash and created more.

Rather than using variables, you might find this taska  lot easier using array's

kevin

Here's an quick example using of a Type Array.    Arrays allow us to store all the characters together.   This allows us to loop through and locate/display/sort them.. It's a lot easier than controlling everything using variables






Type MyHorse
   CompleteFlag
 Xpos#
 Ypos#
   COlour
   Time
   Place
EndType


; create an array to hold the horses (well circles ni this example)
Dim Horses(6) as Myhorse


; init the 6 hourses


y=100
Starttime=timer()
For obj=1 to 6
   horses(obj).CompleteFlag=false
   horses(obj).xpos=20
   horses(obj).ypos=y
   horses(obj).Colour=rndrgb()
   horses(obj).time=starttime
   horses(obj).place=0
   y=y+40
next


setfps 30

CurrentPLace=1

Do
CLs rgb(30,40,50)



; update all 6 horses
 ; ======================
   
 For obj=1 to 6
      x#=horses(obj).xpos+(rnd(200)/rndrange(50,100))
    y#=horses(obj).ypos
    colour=horses(obj).Colour

  if x#>700
   x#=700
   colour=rndrgb()

    if  horses(obj).CompleteFlag=false
    horses(obj).CompleteFlag=true
      horses(obj).time=starttime
      horses(obj).place=CurrentPlace
      inc CurrentPlace
     
   else
    text x#+30,y#,"place:"+str$(horses(obj).place)
      endif
   
  endif

 ; draw the horse/circle
  circlec x#,y#,20,1,Colour
  centertext x#,y#-5,obj  

 ; Store the horse new position after moving
    horses(obj).xpos=x#

 next


Sync
loop



dangerousbrian

[thanks Kevin, I'm going to spend a few days working this out!

dangerousbrianError Missing Closing Square Bracket