Skip to content

Commit fc56416

Browse files
committed
Litte fix
1 parent d5a22c7 commit fc56416

File tree

7 files changed

+12
-19
lines changed

7 files changed

+12
-19
lines changed

GameOfFifteen/GameOfFifteen/AutoSolveClass.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public AutoSolveClass()
1919
minPrevIter = 0;
2020
}
2121

22-
public string GetPathIDAStar(BoardState start)
22+
public string GetSolution(BoardState start)
2323
{;
24-
if (IDAStar(start))
24+
if (isSoluted(start))
2525
return new string(map.Reverse().ToArray());
2626
return "";
2727
}
@@ -97,23 +97,22 @@ private List<BoardState> FindNeighbors(BoardState parent)
9797
return l;
9898
}
9999

100-
// IDA star algorithm
101-
private bool IDAStar(BoardState start)
100+
private bool isSoluted(BoardState start)
102101
{
103102
bool res = false;
104103
deepness = ManhattenDistance(start.boardNumArray);
105104
do
106105
{
107-
minPrevIter = 2147483647;
106+
minPrevIter = int.MaxValue;
108107
res = recSearch(0, start);
109108
deepness = minPrevIter;
110109
} while ((!res) && (deepness <= 50));
111110

112111
return res;
113112
}
114113

115-
// Recursive method wich call in IDAStar method
116-
private bool recSearch(int g, BoardState prevState)
114+
// Recursive method wich call in isSoluted method
115+
private bool recSearch(int steps, BoardState prevState)
117116
{
118117
int h = ManhattenDistance(prevState.boardNumArray);
119118
bool res;
@@ -122,7 +121,7 @@ private bool recSearch(int g, BoardState prevState)
122121
if (h == 0)
123122
return true;
124123

125-
int f = g + h;
124+
int f = steps + h;
126125

127126
if (f > deepness)
128127
{
@@ -139,21 +138,19 @@ private bool recSearch(int g, BoardState prevState)
139138
{
140139
if (!y.boardNumArray.SequenceEqual(prevState.parent.boardNumArray))
141140
{
142-
res = recSearch(g + 1, y);
141+
res = recSearch(steps + 1, y);
143142
if (res)
144143
{
145-
// myDelegate(y.move);
146144
map += y.move;
147145
return true;
148146
}
149147
}
150148
}
151149
else
152150
{
153-
res = recSearch(g + 1, y);
151+
res = recSearch(steps + 1, y);
154152
if (res)
155153
{
156-
// myDelegate(y.move);
157154
map += y.move;
158155
return true;
159156
}

GameOfFifteen/GameOfFifteen/Form1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GameOfFifteen/GameOfFifteen/Form1.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ public Form1()
3232
buttonsArray = new Button[16];
3333
numArray = new int[16];
3434
Solver = new AutoSolveClass();
35-
36-
37-
3835
InitializeComponent();
39-
4036
InitializeButtons();
4137
CreateGame();
4238

@@ -187,8 +183,8 @@ private void hardToolStripMenuItem_Click(object sender, EventArgs e)
187183
// Call Auto Solver IDA Star Algorithm
188184
private void iDAStarToolStripMenuItem_Click(object sender, EventArgs e)
189185
{
190-
//Task<String> callback = Task<String>.Factory.StartNew(() => Solver.GetPathIDAStar(startState) );
191-
string callback = Solver.GetPathIDAStar(startState);
186+
//Task<String> callback = Task<String>.Factory.StartNew(() => Solver.GetSolution(startState) );
187+
string callback = Solver.GetSolution(startState);
192188
label1.ForeColor = Color.FromArgb(54, 72, 36);
193189
if (callback != "")
194190
{
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)