Results 1 to 6 of 6

Thread: Sorting

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    Sorting

    I'm making a game called The Weakest Link. If anyone is unfamiliar with it, 8 players answer questions and after each round of questioning, one player is voted off. The voting part is what I have the most trouble with. First, I need to find out the statistical Weakest Link and Strongest Link. This means the person who answered the least and most questions correct, respectively. So...say a person has played a couple rounds, voted off a few players, and there are only 4 Players left. After another round of questions, I need to be able to sort these 4 Players by how many questions they got right. So, say P1 answered 1 question right, P2 answered 1 question right, P3 answered 1 question right, and P4 answered 3 questions right. Since P4 answered the most questions right, he would go at the top of the list. Since there is a tie with the other three, I would need to sort those three by themselves, based on the amount of time they spent answering their questions. Say P1 used 10 seconds, P2 used 15, and P3 also used 15 seconds. Since P1 tied P2 and P3 in the questions category but used less time, P1 would be second place. Then I would need to sort P2 and P3 by the amount of money earned in the round. Say P2 earns $500 and P3 earns $100. Then P2 would go next in the list, and P3 would be the weakest link. This makes it so that P4 is first place with 3 questions right (time and money earned unnecessary since questions correct is top priority); P1 second place with 1 right, 10 seconds used (money earned unnecessary since time used more important than money earned); P2 third place with 1 right, 15 seconds used, and $500 earned; and finally P3 is the Weakest Link with 1 question right, 15 seconds of time used, and only $100 earned. I would then need the program to return which player is the Strongest Link and which is the Weakest Link. I would also need this to work with 8,7,6,5,4,and 3 players, depending on the current round. If a player is voted out already then the statistical Weakest Link is the lowest person in the list that is still in (since a person eliminated would have no questions answered correctly, that would usually make them last place, so I would need the Weakest Link that is still in the game). How could I go about sorting people like this using Visual Basic 6?

  2. #2
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well there is a bunch of sorting algorithms. (look for quicksort or bubble sort on this forum). Quicksort and bubble sort are both pretty simple, (Bubble sort might be slow but for only 5 values it really does not matter...) but I think for you it would be enough to add the players to a listbox that is sorted...
    just add them like

    VB Code:
    1. for i = 0 to playercount
    2.   List1.AddItem Str(player(i).Time) + player(i).Name
    3. next
    4. List1.Sorted = True

    now the list box will sort them for you...
    Sanity is a full time job

    Puh das war harter Stoff!

  3. #3
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well I forgot: you need to set the sorted property at design time..

    VB Code:
    1. 'to get the first player:
    2.  
    3.   List1.ListIndex = 0
    4.   MsgBox List1.Text
    5.  
    6. 'to get the last player:
    7.  
    8.   List1.ListIndex = List1.ListCount - 1
    9.   msgbox List1.Text
    Sanity is a full time job

    Puh das war harter Stoff!

  4. #4
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375
    Did you know there is already a licensed legal version of this game on the market?
    -Show me on the doll where the music touched you.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    Yes...

    I'm doing this for school. My teacher's out helping his sick mother for the last 2 weeks or so and our substitutes know nothing. This is the only way I can get help.

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    I strongly recommend using an array to store details about each of the contestants, then sorting them is a lot simpler, as when you sort 1 person, all their details move together...

    First create a Player type and set up the variables

    VB Code:
    1. Private Type typPlayer
    2.     Name as string 'Players Name
    3.     Correct as Integer 'Questions they got correct
    4.     TimeTaken as Long 'Time they took to answer
    5. End Type
    6.  
    7. Dim Player(1 To 8) as typPlayer 'For each contestant
    8. Dim Temp as typPlayer
    9. Dim Flag as Boolean
    10. Dim Count as Integer
    11. Dim N as Integer

    to enter their name do this

    VB Code:
    1. Player(1).Name = "Tim"
    2. Player(2).Name = "SLH"

    To sort them, having got how long they took, and the number they got correct do this:

    VB Code:
    1. N = Ubound(Player)
    2. Do While flag = False And n > 0
    3.     flag = False
    4.     For Count = LBound(Player) To n
    5.         If Player(Count).Correct < Player(Count + 1).Correct Then
    6.             Temp = Player(Count)
    7.             Player(Count) = Player(Count + 1)
    8.             Player(Count + 1) = Temp
    9.             flag = True
    10.         End If
    11.  
    12.         If Player(Count).Correct = Player(Count + 1).Correct Then
    13.             If Player(Count).TimeTaken > Player(Count+1).TimeTaken
    14.                 Temp = Player(Count)
    15.                 Player(Count) = Player(Count + 1)
    16.                 Player(Count + 1) = Temp
    17.                 flag = True
    18.             End If
    19.         End If
    20.     Next Count
    21.     n = n - 1
    22. Loop

    That should sort them by answers correct, then timetaken
    Last edited by SLH; Apr 18th, 2002 at 12:01 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width