C
Crirus
Well, thanks, you are right, only that I only need the first point that fir
conditions not all in a radius
Each unit of my game try to set a target as close as possible to the one
given by the player
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"José Manuel Agüero" <jmaguero_vodafone.es> wrote in message
Hello, Crirus:
I see you have solved the problem by now but, anyway, here is what I wrote
last night (in Spain):
'\\\
Private Sub GetCoordArrayAtDistance(ByVal Radius As Integer, ByRef
PointsReturned() As Point, ByRef NumberOfPointsReturned As Integer)
Dim Index As Integer 'Where in PointsReturned() to save the actual
point.
Dim n As Integer 'For use in loops.
If Radius = 0 Then
NumberOfPointsReturned = 1
ReDim PointsReturned(NumberOfPointsReturned - 1)
PointsReturned(0) = New Point(0, 0)
Else
NumberOfPointsReturned = 8 * Radius
ReDim PointsReturned(NumberOfPointsReturned - 1) 'A static
array would have better performance.
'Upper row:
For n = -Radius To Radius
PointsReturned(Index) = New Point(n, -Radius)
Index += 1
Next
'Right column:
For n = -Radius + 1 To Radius
PointsReturned(Index) = New Point(Radius, n)
Index += 1
Next
'Lower row:
For n = Radius - 1 To -Radius Step -1
PointsReturned(Index) = New Point(n, Radius)
Index += 1
Next
'Left column:
For n = Radius - 1 To -Radius + 1 Step -1
PointsReturned(Index) = New Point(-Radius, n)
Index += 1
Next
End If 'Radius=0
End Sub
Private Sub butDistancia_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butDistancia.Click
Dim RGen As New Random()
Dim StartRadius As Integer = RGen.Next(0, 6)
Dim EndRadius As Integer = StartRadius + RGen.Next(0, 6)
Dim PointArray() As Point
Dim NumberOfPoints As Integer
Dim n, s, Counter As Integer
Dim g As Graphics = Me.CreateGraphics
g.Clear(SystemColors.Control)
For n = StartRadius To EndRadius
Call GetCoordArrayAtDistance(n, PointArray, NumberOfPoints)
For s = 0 To NumberOfPoints - 1
Counter += 1
g.DrawString(Counter.ToString, _
Me.Font, _
Brushes.Black, _
Me.ClientSize.Width / 2.0F +
PointArray(s).X * 25, _
Me.ClientSize.Height / 2.0F +
PointArray(s).Y * 25)
Next
Next
End Sub
'///
You can see that it's essentially the same solution as yours (it can't be
other way), but the function only returns the array of points in a "ring" at
a given distance.
Regards.
"Crirus" <[email protected]> escribió en el mensaje
| I have this situation
|
| 25 26 ........
| 9 10 11 12 13
| 24 1 2 3 15
| 23 8 x 4 15
| 22 7 6 5 16
| 21 20 19 18 17
|
|
| I need a way to iterate through that grid in spiral order strating from 1
|
|
|
|
| --
| Cheers,
| Crirus
|
| ------------------------------
| If work were a good thing, the boss would take it all from you
|
| ------------------------------
conditions not all in a radius
Each unit of my game try to set a target as close as possible to the one
given by the player
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"José Manuel Agüero" <jmaguero_vodafone.es> wrote in message
Hello, Crirus:
I see you have solved the problem by now but, anyway, here is what I wrote
last night (in Spain):
'\\\
Private Sub GetCoordArrayAtDistance(ByVal Radius As Integer, ByRef
PointsReturned() As Point, ByRef NumberOfPointsReturned As Integer)
Dim Index As Integer 'Where in PointsReturned() to save the actual
point.
Dim n As Integer 'For use in loops.
If Radius = 0 Then
NumberOfPointsReturned = 1
ReDim PointsReturned(NumberOfPointsReturned - 1)
PointsReturned(0) = New Point(0, 0)
Else
NumberOfPointsReturned = 8 * Radius
ReDim PointsReturned(NumberOfPointsReturned - 1) 'A static
array would have better performance.
'Upper row:
For n = -Radius To Radius
PointsReturned(Index) = New Point(n, -Radius)
Index += 1
Next
'Right column:
For n = -Radius + 1 To Radius
PointsReturned(Index) = New Point(Radius, n)
Index += 1
Next
'Lower row:
For n = Radius - 1 To -Radius Step -1
PointsReturned(Index) = New Point(n, Radius)
Index += 1
Next
'Left column:
For n = Radius - 1 To -Radius + 1 Step -1
PointsReturned(Index) = New Point(-Radius, n)
Index += 1
Next
End If 'Radius=0
End Sub
Private Sub butDistancia_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butDistancia.Click
Dim RGen As New Random()
Dim StartRadius As Integer = RGen.Next(0, 6)
Dim EndRadius As Integer = StartRadius + RGen.Next(0, 6)
Dim PointArray() As Point
Dim NumberOfPoints As Integer
Dim n, s, Counter As Integer
Dim g As Graphics = Me.CreateGraphics
g.Clear(SystemColors.Control)
For n = StartRadius To EndRadius
Call GetCoordArrayAtDistance(n, PointArray, NumberOfPoints)
For s = 0 To NumberOfPoints - 1
Counter += 1
g.DrawString(Counter.ToString, _
Me.Font, _
Brushes.Black, _
Me.ClientSize.Width / 2.0F +
PointArray(s).X * 25, _
Me.ClientSize.Height / 2.0F +
PointArray(s).Y * 25)
Next
Next
End Sub
'///
You can see that it's essentially the same solution as yours (it can't be
other way), but the function only returns the array of points in a "ring" at
a given distance.
Regards.
"Crirus" <[email protected]> escribió en el mensaje
| I have this situation
|
| 25 26 ........
| 9 10 11 12 13
| 24 1 2 3 15
| 23 8 x 4 15
| 22 7 6 5 16
| 21 20 19 18 17
|
|
| I need a way to iterate through that grid in spiral order strating from 1
|
|
|
|
| --
| Cheers,
| Crirus
|
| ------------------------------
| If work were a good thing, the boss would take it all from you
|
| ------------------------------