這是我遞回搜索國際象棋程式專案的代碼。我的問題是,當我回憶起“遞回搜索”功能時,由于正在計算新的國際象棋動作,串列發生了變化。我以前使用“串列 = 新串列”來創建一個新串列,但是這會使搜索在數百次搜索后需要更長的時間。所以我想要做的是傳遞串列,并在下一次搜索中使用相同的串列,當它完成 sub 并回傳到呼叫點時,我希望串列回傳到進入 sub 之前的狀態。(例如,好像我通過了一個普通的資料結構 byval),以便“For each”可以繼續,就好像資料沒有改變一樣。第一次發布所以希望這一切都有意義,我知道我的代碼可能不是最好的,但現在它可以作業,我只需要停止制作新串列,因為它會大大減慢程式的速度。
Sub recurvive_search(ByVal the_board(,) As theboardclass, ByVal depth As Integer, ByRef depth_count() As Integer, ByVal whosgo__ As Integer, ByVal all_moves_list As List(Of A_Move))
If depth = 3 Then
depth_count(4) = 1
Else
all_moves_list = calculate_all_moves(the_board, whosgo__, all_moves_list)
For Each M In all_moves_list
If IsNothing(M.sym_of_moving_piece) = False Then
depth_count(depth) = 1
the_board = Me.change_board(the_board, the_board(M.From_x, M.From_Y).getsym, the_board(M.From_x, M.From_Y).getteam, M.New_x, M.New_Y, M.From_x, M.From_Y)
whosgo__ = switchgoes(whosgo__)
recurvive_search(the_board, depth 1, depth_count, whosgo__, all_moves_list)
whosgo__ = switchgoes(whosgo__)
the_board = Me.undo_move(the_board, M)
End If
Next
End If
End Sub
我正在使用 Visual basic 2010 for School
uj5u.com熱心網友回復:
嘗試這個:
Sub recurvive_search(ByVal the_board(,) As theboardclass, ByVal depth As Integer, ByRef depth_count() As Integer, ByVal whosgo__ As Integer, ByRef all_moves_list As List(Of A_Move))
If depth = 3 Then
depth_count(4) = 1
Else
all_moves_list = calculate_all_moves(the_board, whosgo__, all_moves_list)
For Each M In all_moves_list
If IsNothing(M.sym_of_moving_piece) = False Then
depth_count(depth) = 1
the_board = Me.change_board(the_board, the_board(M.From_x, M.From_Y).getsym, the_board(M.From_x, M.From_Y).getteam, M.New_x, M.New_Y, M.From_x, M.From_Y)
whosgo__ = switchgoes(whosgo__)
recurvive_search(the_board, depth 1, depth_count, whosgo__, all_moves_list)
whosgo__ = switchgoes(whosgo__)
the_board = Me.undo_move(the_board, M)
End If
Next
End If
End Sub
uj5u.com熱心網友回復:
有兩種簡單的方法可以創建與現有串列具有相同內容的新串列。
一種是使用帶有 anIEnumerable(Of T)的建構式來填充構造的串列,例如
Dim newList = New List(Of A_Move)(oldList)
另一種是使用擴展方法從現有序列IEnumerable(Of T).ToList()創建一個新List(Of T)的:
Dim newList = oldList.ToList()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/348904.html
標籤:网络
上一篇:如何在VB.NET中創建日志歷史并將其保存到mysqlworkbench資料庫中?
下一篇:多維陣列中的第一個最低密度陣列
