public void showstate(state currentstate) { Point pt; Button B; if (currentstate.lastaction == "failure") { MessageBox.Show("failure"); return; } if (currentstate.lastaction == "fring is out of memory") { MessageBox.Show("fring is full"); return; } string[,] K = currentstate.getk(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { pt = new Point(100 * j + 50, 100 * i + 50); B = ((Button)firststate.GetChildAtPoint(pt)); B.Text = K[i, j]; B.BackColor = Control.DefaultBackColor; } } int[] a = AStar.whereisblock("-", K); pt = new Point(100 * a[1] + 50, 100 * a[0] + 50); B = ((Button)firststate.GetChildAtPoint(pt)); B.BackColor = Color.Yellow; }
private void Solve_Click(object sender, EventArgs e) { state first = new state(3); string[,] k = new string[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Point pt = new Point(100 * j + 50, 100 * i + 50); k[i, j] = ((Button)firststate.GetChildAtPoint(pt)).Text; } } first.setk(k); state goal = new state(3); string[,] g = new string[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Point pt = new Point(100 * j + 50, 100 * i + 50); g[i, j] = ((Button)Goalstate.GetChildAtPoint(pt)).Text; } } goal.setk(g); p = new problem(first, goal, 3); if (p.whichset(first.getk()) != p.whichset(goal.getk())) { MessageBox.Show("the sets didnt match"); } else { AStar AS = new AStar(p); try { state[] solution = AS.AS(); MessageBox.Show("I found the solution now i will show it : "); foreach (state s in solution) { showstate(s); this.Refresh(); Thread.Sleep(1000); } } catch (OutOfMemoryException) { MessageBox.Show("SYSTEM IS OUT OF MEMORY"); } } }