partial void test_ai_nodes_npuzzleToolStripMenuItem_Click(object sender, EventArgs e) { string test = ""; NPuzzle p = NPuzzle.Next(4); p.Fitness = NPuzzle.Evaluate(p); NPuzzle q = new NPuzzle(null, p.ToArray()); q.Fitness = NPuzzle.Evaluate(q); // tests IsEqual method int n = p.IsEqual(q); test += "\np IsEqual to q returns " + n; test += "\nroot:" + p.ToString(); IList <ITreeNode> c = NPuzzle.GenerateChild(p); for (int i = 0; i < c.Count; i++) { c[i].Fitness = NPuzzle.Evaluate((NPuzzle)c[i]); test += "\n\nchild[" + i.ToString("00") + "]:" + ((NPuzzle)c[i]).ToString(); test += "\np IsEqual to child[" + i.ToString("00") + "]: " + p.IsEqual(c[i]); } richTextBox.Text = test; }
private void TestNPuzzleManhattanDistance(int nrows, int ncols, string initialState, int expected) { var state = new NPuzzle(nrows, ncols, initialState); var score = NPuzzle.ManhattanDistance(state); Assert.Equal(expected, score); }
private void TestNPuzzleIsSolvable(int nrows, int ncols, string initialState, bool expected) { var state = new NPuzzle(nrows, ncols, initialState); var sol = state.IsSolvable(); //output.WriteLine(initialState); //output.WriteLine("inversions: " + sol.Item1); Assert.Equal(expected, sol.Item2); }
partial void test_ai_search_bestfirstToolStripMenuItem_Click(object sender, EventArgs e) { const int s = 3; // size of n puzzle board GreedyBestFirst alg = new GreedyBestFirst(); alg.Alpha = 1.0; alg.Beta = 2.0; alg.Initialize(NPuzzle.Next(s)); Tree <ICanGenerateChild> t = alg.GenerateChild(); richTextBox.Text = alg.ToString(); }
public void TestInitializationParsing(int nrows, int ncols, string stateString) { var flat = stateString.Split(' ').Select(int.Parse).ToArray(); var puzzle3 = new NPuzzle(nrows, ncols, stateString); int i = 0; for (int row = 0; row < nrows; row++) { for (int col = 0; col < ncols; col++) { Assert.Equal(flat[i], puzzle3[row, col]); i++; } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); NPuzzle editorObj = target as NPuzzle; if (editorObj == null) { return; } if (GUILayout.Button("Update Grid")) { editorObj.UpdateGrid(); } }
partial void test_ai_core_queueToolStripMenuItem_Click(object sender, EventArgs e) { const int n = 10, s = 4; Queue q0 = new Queue(null); NPuzzle np; for (int i = 0; i < n; i++) { np = NPuzzle.Next(s); np.Fitness = NPuzzle.Evaluate(np); q0.Enqueue(np); } richTextBox.Text = q0.ToString(); }
public void TestDefaultInitialization(int nrows, int ncols) { var puzzle3 = new NPuzzle(nrows, ncols); Assert.True(puzzle3.IsGoal()); }