private string print_n_queen_result(int[] result) { int n = result.Length; string pr = n + "-Queen problem:\r\n"; for (int i = 0; i < n; i++) { pr += "|"; for (int j = 0; j < n; j++) { if (result[i] == j) { pr += "Q"; } else { pr += " . "; } } pr += "|\r\n"; } n_queens_problem nqp = new n_queens_problem(); if (!nqp.total_satisfaction(result)) { pr += ("Algorithm trapped in local optimum!!"); } return(pr); }
private void button3_Click(object sender, EventArgs e) { textBox1.Text = "searching..."; textBox1.Refresh(); int[] a; ILocal_Search <int[]> h = new first_choise <int[]>(); n_queens_problem nqp = new n_queens_problem(); int[] result; do { a = helper.generate_random_array(number_of_queen()); result = h.solve(nqp, a); } while (!nqp.total_satisfaction(result)); textBox1.Text = print_n_queen_result(result); }