2012년 3월 25일 일요일

vb] vb로 작성했던 진열대 경로 찾기.

            MartBoard(ox + 3, oy).Status = 42
flagIsNotEmpty = False
End If

'*************
'알고리즘 부분
'*************

'다음 경로가 비어 있는 경우 flag 세팅(가장 가까운 곳으로 뻗어 나간다)
'같은 경우 아래로
If PassageBoard(oPassage + 1).top = 0 And PassageBoard(oPassage + 1).bottom = 0 Then

flagIsNotEmptyNextPassage = False '플래그 세팅 해주고

If flagStart Then
If PassageBoard(oPassage).top >= (DisplayStandY \ 2) Then
flag1Next = False
Else: flag1Next = True
End If
End If

If Not flagStart Then
If PassageBoard(oPassage).bottom >= (DisplayStandY \ 2) Then
flag1Next = False
Else: flag1Next = True
End If
End If
End If

'다음 경로가 비어있지 않고 지금 통로도 비어있지 않는 경우
If flagIsNotEmptyNextPassage And flagIsNotEmpty Then
If flagStart Then
o1 = PassageBoard(oPassage).top + PassageBoard(oPassage + 1).bottom - 1
o2 = 2 * (DisplayStandY - 2) - PassageBoard(oPassage + 1).top - PassageBoard(oPassage + 1).top
Else
o1 = PassageBoard(oPassage).bottom + PassageBoard(oPassage + 1).bottom - 1
o2 = 2 * (DisplayStandY - 2) - PassageBoard(oPassage + 1).bottom - PassageBoard(oPassage + 1).top
End If


End If

test3.Caption = test3.Caption & vbCr & oPassage & "통로 " & o1 & " " & o2


'***********
'그리기 부분
'***********

'#############
'통로 시작이 올라가는 부분.
If flagStart And flagIsNotEmpty Then

'꺽고
MartBoard(ox, oy).Status = 41

'올려준다.
For oy = oy - 1 To PassageBoard(oPassage).top Step -1
MartBoard(ox, oy).Status = 13
Next oy
' MartBoard(ox, oy).Status = 32
oy = oy + 1


'다음이 내려가면
If Not flag1Next Then
MartBoard(ox + 1, oy).Status = 43
For oy = oy + 1 To DisplayStandY - 2
MartBoard(ox + 1, oy).Status = 13
Next oy

End If


'다음이 올라가면
If flag1Next Then
MartBoard(ox + 1, oy).Status = 41
For oy = oy - 1 To 0 Step -1
MartBoard(ox + 1, oy).Status = 13
Next oy
oy = oy + 1
End If

End If



'통로 시작이 내려가는 부분.
If Not flagStart And flagIsNotEmpty Then

'꺽고
MartBoard(ox, oy).Status = 43

'내려준다.
For oy = oy + 1 To PassageBoard(oPassage).bottom
MartBoard(ox, oy).Status = 13
Next oy
oy = oy - 1


'다음이 내려가면(위에꺼랑 같은데 밖으로 뺄수 있을지 고민 TODO )
If Not flag1Next Then
MartBoard(ox + 1, oy).Status = 43
For oy = oy To DisplayStandY - 2
MartBoard(ox + 1, oy).Status = 13
Next oy

End If


'다음이 올라가면
If flag1Next Then
MartBoard(ox + 1, oy).Status = 41
For oy = oy To 0 Step -1
MartBoard(ox + 1, oy).Status = 13
Next oy
oy = oy + 1
End If

End If


MartBoard(ox + 1, oy).Status = 42
MartBoard(ox + 2, oy).Status = 42
MartBoard(ox + 3, oy).Status = 42
ox = ox + 4

' TODO



Next oPassage




displayStand_Paint







End Sub
'##############
'폼 로드
'##############
Private Sub Form_Load()
first_defind
first_method


End Sub
'##############
'처음 시작 묶음
'##############
Private Sub first_method()
Dim i, j, k As Integer
Dim c As Integer
Dim StatusCount As Integer
Dim NumCount As Integer

'displaystand 지움
displayStand.Cls


'카트판 데이터 메모리 할당
ReDim MartBoard(0 To DisplayStandX - 1, _
0 To DisplayStandY - 1)


'수평 수직 숫자 데이터 메모리 할당
ReDim GameNumH(0 To DisplayStandY - 1)
ReDim GameNumV(0 To DisplayStandX - 1)


'진열대 크기 초기화
displayStand.Width = DisplayStandX * TileSizeX + 2 * 2
displayStand.Height = DisplayStandY * TileSizeY + 2 * 2

'통로 정보 초기화
ReDim PassageBoard(0 To Passage - 1)


path_setting
displayStand_Paint
End Sub
'################
'새작업 버튼 클릭
'################

Private Sub cmdChangeDisp_Click()

Form_Load
cmdRandomSetting.Enabled = True
cmdReturn1.Enabled = True
cmdTraversal.Enabled = True



End Sub
'##############
'랜덤 세팅 설정
'##############
Private Sub cmdRandomSetting_Click()
Dim i, j, k As Integer
Dim c As Integer
Dim StatusCount As Integer
Dim NumCount As Integer



For i = 0 To DisplayStandY - 1
For j = 0 To DisplayStandX - 1
If Int(Rnd() * 1.1) = 0 Then c = 0 Else c = 1
MartBoard(j, i).Status = c
MartBoard(j, i).Disp = 0
Next j
Next i





passageSetting
path_setting
'displayStand.Refresh
'picBoard.Refresh
displayStand_Paint
'cmdRandomSetting.Enabled = False


End Sub

'#############
'Return policy
'#############
Private Sub cmdReturn1_Click()

'Dim MartBoard_copy() As TBoard
'MartBoard_copy() = MartBoard()
path_setting
passageSetting
displayStand_Paint

Dim i, j, k As Integer
Dim x, y As Integer

x = 1

For i = 0 To (DisplayStandX - 1)
If MartBoard(i, DisplayStandY - 2).Status = 0 Or MartBoard(i, DisplayStandY - 2).Status = 1 Then
MartBoard(i, DisplayStandY - 1).Status = 42
End If
Next i

For i = 0 To Passage - 1
If PassageBoard(i).isEmpty Then
MartBoard(x, DisplayStandY - 1).Status = 42
MartBoard(x + 1, DisplayStandY - 1).Status = 42
Else
MartBoard(x, DisplayStandY - 1).Status = 41
MartBoard(x + 1, DisplayStandY - 1).Status = 12
MartBoard(x, PassageBoard(i).top).Status = 32
MartBoard(x + 1, PassageBoard(i).top).Status = 43
For j = DisplayStandY - 2 To PassageBoard(i).top + 1 Step -1
MartBoard(x, j).Status = 13
MartBoard(x + 1, j).Status = 13
Next j

End If
x = x + 4
Next i

displayStand_Paint
'MartBoard() = MartBoard_copy()

' cmdRandomSetting.Enabled = False
' cmdReturn1.Enabled = False
' cmdTraversal.Enabled = False
End Sub
'################
'Traversal policy
'################
Private Sub cmdTraversal_Click()
path_setting
passageSetting
displayStand_Paint
Dim i As Integer, j, k As Integer
Dim x, y As Integer
Dim isBottom, isNeedChange As Boolean
Dim passageNum As Integer

Dim test1, test2

isBottom = True
isNeedChange = False
passageNum = 0
x = 1

isBottom = True

For i = 0 To Passage - 1

If PassageBoard(i).isEmpty Then
If isBottom Then
MartBoard(x - 1, DisplayStandY - 1).Status = 42
MartBoard(x, DisplayStandY - 1).Status = 42
MartBoard(x + 1, DisplayStandY - 1).Status = 42
MartBoard(x + 2, DisplayStandY - 1).Status = 42
Else
MartBoard(x - 1, 0).Status = 42
MartBoard(x, 0).Status = 42
MartBoard(x + 1, 0).Status = 42
MartBoard(x + 2, 0).Status = 42
End If
Else

If isBottom Then

MartBoard(x - 1, DisplayStandY - 1).Status = 42
MartBoard(x, DisplayStandY - 1).Status = 41
MartBoard(x + 1, 0).Status = 42
MartBoard(x + 2, 0).Status = 42
MartBoard(x, 0).Status = 32
For j = DisplayStandY - 2 To 1 Step -1
MartBoard(x, j).Status = 13
Next j
Else
MartBoard(x - 1, 0).Status = 42
MartBoard(x, DisplayStandY - 1).Status = 12
MartBoard(x + 1, DisplayStandY - 1).Status = 42
MartBoard(x + 2, DisplayStandY - 1).Status = 42
MartBoard(x, 0).Status = 43

For j = DisplayStandY - 2 To 1 Step -1
MartBoard(x, j).Status = 13
Next j
End If
isBottom = Not isBottom
End If
x = x + 4
Next i
'*************************************************
'변경된 스펙:위에서 끝나는 경우 아래쪽으로 내린다.
' 지우고 다시 그리기
'
'*************************************************

Dim f1, f2, k2

If MartBoard(DisplayStandX - 1, 0).Status = 42 Then


For i = 0 To DisplayStandX - 1
If MartBoard(i, 0).Status = 32 Then
j = i
End If
Next i

'j 지우는 곳의 마지막 X좌표를 가지고 있다.

'지워보세~
For k = DisplayStandX - 1 To j Step -1
MartBoard(k, 0).Status = 2
Next k

'양쪽에 물건 검사
For f1 = DisplayStandY - 1 To 1 Step -1
If MartBoard(j - 1, f1).Status = 1 Or MartBoard(j + 2, f1).Status = 1 Then
f2 = f1
End If
Next f1
'f2 지우는 곳의 마지막 y 좌표를 가지고 있다.

'지워보세~
For k2 = 0 To f2 - 1
MartBoard(j, k2).Status = 2
Next k2

'다시 그려보세~
MartBoard(j, k2).Status = 32
MartBoard(j + 1, k2).Status = 43
For i = k2 + 1 To DisplayStandY - 1
MartBoard(j + 1, i).Status = 13
Next i

For i = j + 1 To DisplayStandX - 1
MartBoard(i, DisplayStandY - 1).Status = 42
Next i

MartBoard(j + 1, DisplayStandY - 1).Status = 12



End If '* 스펙 변경 IF문








displayStand_Paint
' cmdRandomSetting.Enabled = False
' cmdReturn1.Enabled = False
' cmdTraversal.Enabled = False


End Sub
'############################
'일반 좌표를 통로 좌표로 변환
'1000 까지 인식(아직 사용 안함).
'############################
Private Function convertToPassage(num As Integer)
Dim i, j, k As Integer

j = 1
k = 1

For i = 1 To 1000 Step 4
If num = i Or num = i + 1 Then
k = j
End If
j = j + 1
Next i


convertToPassage = k

End Function
'################################
'진열대 마운스 다운 이벤트 핸들러
'################################
Private Sub displayStand_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim IconNum As Integer

'커서를 타일 좌표로 변환
curX = x \ TileSizeX
curY = y \ TileSizeY

'범위를 벗어나면 종료
If curX < 0 Or curX >= DisplayStandX Or _
curY < 0 Or curY >= DisplayStandY Then Exit Sub

If MartBoard(curX, curY).Status = 2 Then Exit Sub
Select Case Button
Case 1: '좌측버튼
If MartBoard(curX, curY).Status = 0 Then
IconNum = 1
Else
IconNum = 0
End If
End Select

setIcon curX, curY, IconNum

End Sub


'#############
'진열대 그리기
'#############
Private Sub displayStand_Paint()

Dim i, j As Integer

For i = 0 To DisplayStandY - 1
For j = 0 To DisplayStandX - 1
If MartBoard(j, i).Status = 0 Then
displayStand.PaintPicture imgIcon, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 1 Then
displayStand.PaintPicture imgIconChecked, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 2 Then
displayStand.PaintPicture imgIconPath, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 43 Then
displayStand.PaintPicture imgIconLeftToDown, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 42 Then
displayStand.PaintPicture imgIconFlat, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 41 Then
displayStand.PaintPicture imgIconLeftToUp, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 32 Then
displayStand.PaintPicture imgIconDownToRight, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 12 Then
displayStand.PaintPicture imgIconUpToRight, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY
ElseIf MartBoard(j, i).Status = 13 Then
displayStand.PaintPicture imgIconVertical, j * TileSizeX, i * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(j, i).Disp * TileSizeY, _
TileSizeX, TileSizeY


End If

Next j
Next i

End Sub
'################
'진열대 경로 세팅
'- empty_path -
'################
Private Sub path_setting()
Dim i, j, k As Integer

'경로 끝나는 부분의 X좌표
k = 2

'첫줄, 마지막줄 세팅
For i = 0 To DisplayStandX - 1
MartBoard(i, 0).Status = 2
MartBoard(i, DisplayStandY - 1).Status = 2
Next i

'진열대 사이 세팅
For i = 1 To DisplayStandX - 1
For j = 0 To DisplayStandY - 1
MartBoard(i, j).Status = 2

Next j

If i = k Then
k = k + 4
i = i + 2
End If
Next i

End Sub
'###########
'아이콘 세팅
'###########
Private Sub setIcon(x As Integer, y As Integer, IconNum As Integer)

MartBoard(x, y).Status = IconNum

If MartBoard(x, y).Status = 0 Then
displayStand.PaintPicture imgIcon, x * TileSizeX, y * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(x, y).Disp * TileSizeY, _
TileSizeX, TileSizeY
Else
displayStand.PaintPicture imgIconChecked, x * TileSizeX, y * TileSizeY, _
TileSizeX, TileSizeY, 0, MartBoard(x, y).Disp * TileSizeY, _
TileSizeX, TileSizeY
End If




End Sub

'#################
'passage 정보 세팅
'-----------------
'진열대 좌/우 정보를 읽어서 통로의 정보를 세팅한다.
Private Sub passageSetting()
Dim a, b, c As Integer
Dim i, j As Integer
Dim top, bottom As Integer

b = 0
c = b + 3
top = 0
bottom = 0

'top 정보 세팅
For a = 0 To Passage - 1
For i = (DisplayStandY - 2) To 1 Step -1
If MartBoard(b, i).Status = 1 Then top = i
If MartBoard(c, i).Status = 1 Then top = i
Next i
If top = 0 Then
PassageBoard(a).top = top
PassageBoard(a).isEmpty = True
Else
PassageBoard(a).top = top
PassageBoard(a).isEmpty = False
End If
top = 0
b = b + 4
c = b + 3
Next a


'bottom 정보 세팅
b = 0
c = b + 3

For a = 0 To Passage - 1

For i = 1 To (DisplayStandY - 2) Step 1
If MartBoard(b, i).Status = 1 Then bottom = i
If MartBoard(c, i).Status = 1 Then bottom = i
Next i

If PassageBoard(a).isEmpty = False Then
PassageBoard(a).bottom = bottom
Else: PassageBoard(a).bottom = 0
End If

bottom = 0
b = b + 4
c = b + 3
Next a


'TODO: 디버깅 코드
Text1.Text = " "
For a = 0 To Passage - 1
Text1.Text = Text1.Text & " " & PassageBoard(a).top
Next a


For a = 0 To Passage - 1
Text1.Text = Text1.Text & " " & PassageBoard(a).bottom
Next a
End Sub

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...