| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:帮看看该怎样改
只看楼主 加入收藏
二吾
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2010-7-7
结帖率:88.89%
收藏
已结贴  问题点数:20 回复次数:2 
帮看看该怎样改
Public Board(7, 7) As Integer
Public HTry1 As Variant
Public HTry2 As Variant
Type Stack
   i As Integer
   j As Integer
   director As Integer
End Type
Public sta(63) As Stack
Public top As Integer
  
Sub main()
    HTry1 = Array(-2, -1, 1, 2, 2, 1, -1, -2)
    HTry2 = Array(1, 2, 2, 1, -1, -2, -2, -1)
    top = -1
    Dim i As Integer
    Dim j As Integer
    For i = 0 To 7
      For j = 0 To 7
        Board(i, j) = 0
      Next j
    Next i
    Form1.Show
End Sub
Sub Display(m As Integer)
    Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\horse.jpg")
End Sub
Sub black(m As Integer)
    Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\black.jpg")
End Sub
Sub white(m As Integer)
    Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\white.jpg")
End Sub

Sub InitLocation(xi As Integer, yj As Integer)
    Dim x As Integer
    Dim y As Integer
    top = top + 1
    sta(top).i = xi
    sta(top).j = yj
    sta(top).director = -1
    Board(xi, yi) = top + 1
    x = sta(top).i
    y = sta(top).j
    Call TryPath(x, y)
End Sub
Sub TryPath(i As Integer, j As Integer)
    Dim find%, director%, number%, min%
    Dim i1%, j1%, h%, k%, s%
    Dim a%(7), b1%(7), b2%(7), d%(7)
    While top > -1
       For h = 0 To 7
         number = 0
         i = sta(top).i + HTry1(h)
         j = sta(top).j + HTry1(h)
         b1(h) = i
         b2(h) = j
         If Board(i, j) = 0 And i >= 0 And i < 8 And j >= 0 And j < 8 Then '越界了
          For k = 0 To 7
            i1 = b1(h) + HTry1(k)
            j1 = b2(h) + HTry2(k)
            If Board(i1, j1) = 0 And i1 >= 0 And i1 < 8 And j1 >= 0 And j1 < 8 Then  '越界了
               number = number + 1
            End If
          Next k
          a(h) = number
         End If
       Next h
       For h = 0 To 7
         min = 9
         For k = 0 To 7
           If min > a(k) Then
            min = a(k)
            d(h) = k
            s = k
           End If
         Next k
         a(s) = 9
       Next h
       director = sta(top).director
       If top >= 63 Then DoEvents
       find = 0
       For h = director + 1 To 7
         i = sta(top).i + HTry1(d(h))
         j = sta(top).j + HTry2(d(h))
         If Board(i, j) = 0 And i >= 0 And i < 8 And j >= 0 And j < 8 Then '越界了
           find = 1
           Exit For
         End If
       Next h
       If find = 1 Then
         sta(top).director = director
         top = top + 1
         sta(top).i = i
         sta(top).j = j
         Call Display(i * 8 + j)
         sta(top).director = -1
         Board(i, j) = top + 1
       Else
         Board(sta(top).i, sta(top).j) = 0
         If sta(top).i Mod 2 = 0 And sta(top).j Mod 2 = 0 Then
           Call white(sta(top).i * 8 + sta(top).j)
         ElseIf sta(top).i Mod 2 = 0 And sta(top).j Mod 2 <> 0 Then
           Call black(sta(top).i * 8 + sta(top).j)
         ElseIf sta(top).i Mod 2 <> 0 And sta(top).j Mod 2 = 0 Then
           Call black(sta(top).i * 8 + sta(top).j)
         ElseIf sta(top).i Mod 2 <> 0 And sta(top).j Mod 2 <> 0 Then
           Call white(sta(top).i * 8 + sta(top).j)
         End If
         top = top - 1
       End If
    Wend
End Sub


   
   
2010-09-25 17:22
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:14 
改什么?

无知
2010-09-26 01:12
二吾
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2010-7-7
收藏
得分:0 
回复 2楼 Artless
不用了 谢谢 我已经找到答案了

坚定目标,义无反顾的走下去
2010-09-26 13:27
快速回复:帮看看该怎样改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024450 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved