28 Replies - 1144 Views - Last Post: 21 October 2010 - 03:45 AM
#1
some advice on grouping numbers
Posted 16 October 2010 - 06:28 AM
348,325,734,12,97,457,264,390,909
and so on... now im looking for some way to make random gruops with this numbers in....
this is for a racing game... it is to make random races with differnt racers in.. so it makes a set of "heats" and then winners go into a final....
how could i do this in vb.net?
Kev
Replies To: some advice on grouping numbers
#2
Re: some advice on grouping numbers
Posted 16 October 2010 - 06:50 AM
#3
Re: some advice on grouping numbers
Posted 16 October 2010 - 06:58 AM
now there could be from 30 to 130 numbers
at the mo we have to make the groups ourselves... IE: take each number and just putit in a goup... but some racers see it as we make the groups unfair... so i would like to make a application that makes the gruops for me that way i have no control on what racer is in what group with other racers
hops this helps abit
thanks for the reply
Kev
#4
Re: some advice on grouping numbers
Posted 17 October 2010 - 01:37 AM
TADS, on 16 October 2010 - 05:58 AM, said:
now there could be from 30 to 130 numbers
at the mo we have to make the groups ourselves... IE: take each number and just putit in a goup... but some racers see it as we make the groups unfair... so i would like to make a application that makes the gruops for me that way i have no control on what racer is in what group with other racers
hops this helps abit
thanks for the reply
Kev
Not sure about if this will create randoms correct
Anyway you can try it
(not tested extensively)
Public Sub CreateRandomGrous()
Using sw As StreamWriter = New StreamWriter("C:\Test\groups.txt") '<-- change the full path here
Dim rnd = New Random()
Dim c As Integer = 0
Dim arr = Array.CreateInstance(GetType(Int32), 100)
For i As Integer = 30 To 129
arr(i - 30) = i
Next
Dim numbers = From n In arr
Let i = n
Where (n >= 30 And n <= 130)
Let Racer = rnd.Next(30, 130)
Select New With {Racer}
Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To numbers.Count() - 1 Step 15
Dim group As New ArrayList()
For j As Integer = 0 To 14
group.Add(numbers(i))
Next
groups.Add(group)
Next
Dim cnt As Integer = 1
For i As Integer = 0 To groups.Count - 1
sw.WriteLine("=== Group {0} ===", cnt)
For j As Integer = 0 To groups.Item(0).Count - 1
sw.WriteLine(vbTab & groups.Item(i)(j).Racer)
Next
cnt = cnt + 1
Next
sw.Close()
End Using
End Sub
~'J'~
#5
Re: some advice on grouping numbers
Posted 17 October 2010 - 12:13 PM
#6
Re: some advice on grouping numbers
Posted 18 October 2010 - 09:37 AM
sorry if his seams a silly question but i have been looking at this and cant work it out
thanks
Kev
#7
Re: some advice on grouping numbers
Posted 18 October 2010 - 01:51 PM
TADS, on 18 October 2010 - 08:37 AM, said:
sorry if his seams a silly question but i have been looking at this and cant work it out
thanks
Kev
Sorry, Kev
Now is too late here
I'll post my response tomorrow
CU
~'J'~
#8
Re: some advice on grouping numbers
Posted 18 October 2010 - 02:00 PM
#9
Re: some advice on grouping numbers
Posted 18 October 2010 - 02:41 PM
TADS, on 18 October 2010 - 01:00 PM, said:
Ah, can't sleep without solution
Here you go
Add 2 richtexboxes and drop button on form
Here is event on click (your first richtextbox
must be filled with racers before)
Private Sub btnGrouping_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrouping.Click
Dim rnd = New Random()
Dim RacerIds As ArrayList = New ArrayList(Me.RichTextBox1.Lines)
Dim Racers = From n In RacerIds
Let i = RacerIds.IndexOf(n)
Where (i >= 0 And i <= 99)
Let Position = rnd.Next(0, 99)
Let Racer = RacerIds.Item(Position)
Select New With {Position, Racer}
Dim dispGrous As ArrayList = New ArrayList
Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To Racers.Count() - 1 Step 15
Dim group As New ArrayList()
Dim line = ""
For j As Integer = 0 To 14
group.Add(Racers(i).Racer)
line = line & vbTab & Racers(i).Racer
Next
dispGrous.Add(line)
groups.Add(group)
Next
Me.RichTextBox2.Lines = dispGrous.ToArray(GetType(String))
'' you can write 'groups' in text box with code from my post above here
End Sub
~'J'~
#10
Re: some advice on grouping numbers
Posted 19 October 2010 - 05:14 AM
#11
Re: some advice on grouping numbers
Posted 19 October 2010 - 05:17 AM
#12
Re: some advice on grouping numbers
Posted 19 October 2010 - 09:41 AM
change richtextbox1 to carlist and richtexbox2 to heats...
Public Sub makegroups()
Dim rnd = New Random()
Dim RacerIds As ArrayList = New ArrayList(Me.carlist.Lines)
Dim Racers = From n In RacerIds Let i = RacerIds.IndexOf(n) Where (i >= 0 And i <= 99) Let Position = rnd.Next(0, 99) Let Racer = RacerIds.Item(Position) Select New With {Position, Racer}
Dim dispGrous As ArrayList = New ArrayList
Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To Racers.Count() - 1 Step 15
Dim group As New ArrayList()
Dim line = ""
For j As Integer = 0 To 14
group.Add(Racers(i).Racer)
line = line & vbTab & Racers(i).Racer
Next
dispGrous.Add(line)
groups.Add(group)
Next
Me.heats.Lines = dispGrous.ToArray(GetType(String))
End Sub
i get error on...
For i As Integer = 0 To Racers.Count() - 1 Step 15
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
if you could help on this that would be brill
Kev
#13
Re: some advice on grouping numbers
Posted 19 October 2010 - 09:57 AM
TADS, on 19 October 2010 - 08:41 AM, said:
For i As Integer = 0 To Racers.Count() - 1 Step 15
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
if you could help on this that would be brill
Kev
I will test it
Just I need to know what is the number of lines
in the first richtextbox (carlist)?
Perhaps need to check it on empty line before
and remove if this found in there
#14
Re: some advice on grouping numbers
Posted 19 October 2010 - 10:19 AM
i have tried it like
348,325,734,12,97,457,264,390,909
and also tried putting he numbers in like...
1
2
3
4
5
6
7
8
and so on
but both has the same outcome
Kev
#15
Re: some advice on grouping numbers
Posted 19 October 2010 - 10:44 AM
TADS, on 19 October 2010 - 09:19 AM, said:
i have tried it like
348,325,734,12,97,457,264,390,909
and also tried putting he numbers in like...
1
2
3
4
5
6
7
8
and so on
but both has the same outcome
Kev
Kev, can you try to load data by this way
(just for testing):
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As List(Of String) = New List(Of String)
Dim rnd = New Random()
For i As Integer = 0 To 99
lst.Add(rnd.Next(500, 900))
Next
Me.carlist.Lines = lst.ToArray()
End Sub
|
|

New Topic/Question
Reply




MultiQuote





|