@@ -12,17 +12,15 @@ public class AutoSolveClass
1212 {
1313 private int deepness , minPrevIter ;
1414 private string map ;
15- Form1 . MyDelegate myDelegate ;
1615
1716 public AutoSolveClass ( )
1817 {
1918 deepness = 0 ;
2019 minPrevIter = 0 ;
2120 }
2221
23- public string GetPathIDAStar ( BoardState start , Form1 . MyDelegate myDelegate )
24- {
25- this . myDelegate = myDelegate ;
22+ public string GetPathIDAStar ( BoardState start )
23+ { ;
2624 if ( IDAStar ( start ) )
2725 return new string ( map . Reverse ( ) . ToArray ( ) ) ;
2826 return "" ;
@@ -31,13 +29,12 @@ public string GetPathIDAStar(BoardState start, Form1.MyDelegate myDelegate)
3129 // Calculate Manhatten distance for current board state
3230 private int ManhattenDistance ( int [ ] b )
3331 {
34- int i , j , res = 0 ;
35-
36- for ( i = 0 ; i < 16 ; i ++ )
32+ int res = 0 ;
33+ for ( int i = 0 ; i < 16 ; i ++ )
3734 {
3835 if ( b [ i ] == 0 )
3936 continue ;
40- for ( j = 0 ; j < 16 ; j ++ )
37+ for ( int j = 0 ; j < 16 ; j ++ )
4138 {
4239 if ( j == b [ i ] - 1 )
4340 {
@@ -64,7 +61,7 @@ private List<BoardState> FindNeighbors(BoardState parent)
6461 break ;
6562 }
6663 }
67-
64+
6865 for ( i = 0 ; i < 16 ; i ++ )
6966 {
7067 if ( Math . Abs ( zeroIndex - i ) == 1 || Math . Abs ( zeroIndex - i ) == 4 )
@@ -105,7 +102,6 @@ private bool IDAStar(BoardState start)
105102 {
106103 bool res = false ;
107104 deepness = ManhattenDistance ( start . boardNumArray ) ;
108-
109105 do
110106 {
111107 minPrevIter = 2147483647 ;
@@ -120,7 +116,7 @@ private bool IDAStar(BoardState start)
120116 private bool recSearch ( int g , BoardState prevState )
121117 {
122118 int h = ManhattenDistance ( prevState . boardNumArray ) ;
123- bool res = false ;
119+ bool res ;
124120 List < BoardState > Neighbors ;
125121
126122 if ( h == 0 )
@@ -146,6 +142,7 @@ private bool recSearch(int g, BoardState prevState)
146142 res = recSearch ( g + 1 , y ) ;
147143 if ( res )
148144 {
145+ // myDelegate(y.move);
149146 map += y . move ;
150147 return true ;
151148 }
@@ -156,13 +153,13 @@ private bool recSearch(int g, BoardState prevState)
156153 res = recSearch ( g + 1 , y ) ;
157154 if ( res )
158155 {
156+ // myDelegate(y.move);
159157 map += y . move ;
160158 return true ;
161159 }
162160 }
163161 }
164162 return false ;
165163 }
166-
167164 }
168165}
0 commit comments