|
-
Jul 25th, 2010, 04:52 PM
#1
Thread Starter
New Member
find line sequence
hi, i'm designing a game in vb.net
my consists on many hexagons, fit together, each haxagon has some lines on it, the point of the game is for you to make the hexagons lines to conect with other hexagon's lines, in order to create one continuous line that starts in an edge of the game, and ends in another.
i already have the hexagons, the lines inside, and am even able to detect where a line conects with another.
my problem is in followingfrom on edge, until the last line, wich has no conection with anything.
the hexagons are a class, and are arranged in a list. each hexagon has one or two lines, defined by the start and end points.
can any one help me designing this sub, wich detects continuous lines ?
-
Jul 27th, 2010, 08:52 AM
#2
Re: find line sequence
Do you have a generator that figures out what your solution is yet? I'm assuming before you even start the puzzle, the computer created your pieces based on a generated solution and then scrambled their orientation so the player can put them into proper sequence forming the line. You don't want the computer to generate an impossible puzzle. Every time the player makes a move, check the current board status against your solution.
If you have the potential of many solutions (such as if the player doesn't have to use ALL the hexagons to win the puzzle), then after every move, do a trace from the start to see if you end up at the end.
-
Jul 28th, 2010, 05:19 PM
#3
Thread Starter
New Member
Re: find line sequence
no.. there are 4 kinds of hexagons, each with different lines inside them, in the begining, the computer randomly spreads some of each around, and we have to play with them until this line is form.
through several and several loops, i have been able to do this, but it is my thinking that the code is really rubbish...
here it is what i have done:
[code]
Sub find_consecutive_lines2()
update_lines_list()
Dim curren_line_streak As New List(Of line)
Dim current_formal_streak As New line_streak
Dim wanted_point As Point
Dim complete_streaks As New List(Of line_streak)
Dim found_a_line As Boolean
For i = 0 To all_lines.Count - 1
current_formal_streak = New line_streak
curren_line_streak.Clear()
If is_point_on_edge(all_lines(i).point1) Or is_point_on_edge(all_lines(i).point2) Then
If 2 = 3 Then
Timer1.Enabled = False
g.DrawLine(Pens.Green, all_lines(i).point1.X, all_lines(i).point1.Y, all_lines(i).point2.X, all_lines(i).point2.Y)
PictureBox1.Image = screen
MsgBox("c")
Timer1.Enabled = True
End If
'primeiro ponto, numa beira encontrado
curren_line_streak.Add(all_lines(i))
If is_point_on_edge(all_lines(i).point1) Then
wanted_point = all_lines(i).point2
Else
wanted_point = all_lines(i).point1
End If
'ja foi iniciada a minha streak
For j = 0 To all_lines.Count - 1
found_a_line = False
If point_equals(all_lines(j).point1, wanted_point) Or point_equals(all_lines(j).point2, wanted_point) Then
If is_repeated(curren_line_streak, all_lines(j)) = False Then
'esta linha encaixa!!!
'ver qual o ponto que encaixa
If point_equals(all_lines(j).point1, wanted_point) Then
'e o ponto 1 que encaixa
wanted_point = all_lines(j).point2
Else
wanted_point = all_lines(j).point1
End If
curren_line_streak.Add(all_lines(j))
found_a_line = True
End If
End If
If found_a_line = True Then
j = -1
End If
Next
'a linha esta completa agora
If curren_line_streak.Count > 2 Then
'a linha tem tamanho suficiente
If is_point_on_edge(curren_line_streak(curren_line_streak.Count - 1).point1) Or is_point_on_edge(curren_line_streak(curren_line_streak.Count - 1).point2) Then
'a linha final toca numa edge!!!!!
'construir a minha streak
For z = 0 To curren_line_streak.Count - 1
current_formal_streak.add_element(New line_streak_element(find_correspondent_hex(curren_line_streak(z)), curren_line_streak(z)))
Next
complete_streaks.Add(current_formal_streak)
End If
End If
End If
Next
[\code]
it is way too long for the task it is.
i keep believing that a simpler better way exists to achive the same goal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|