private void btnResoudre_Click(object sender, EventArgs e) { lbCoupGagner.Items.Clear(); SearchTree g = new SearchTree(); NodeTaquin N0 = new NodeTaquin(Board); var watch = System.Diagnostics.Stopwatch.StartNew(); List <GenericNode> Lres = g.RechercheSolutionAttrapay(N0); watch.Stop(); TimeSpan ts = watch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10); lblTempsCalculRes.Text = elapsedTime; if (Lres.Count != 0) { foreach (GenericNode N in Lres) { lbCoupGagner.Items.Add(N); } lblNbNoeudsOuvertsRes.Text = g.CountInOpenList().ToString(); lblNbNoeudsFermesRes.Text = g.CountInClosedList().ToString(); g.GetSearchTree(trArbreExploration); } }
/// <summary> /// Cette méthode est sans doute la plus importante. Elle doit retourner la liste exhaustive de tous les noeuds successeurs du noeud courant. /// Il faut pour cela identifier toutes les transitions possibles, /// créer à chaque fois le noeud successeur qui correspond à l’état qui serait atteint et renvoyer la liste obtenue. /// </summary> /// <returns></returns> public override List <GenericNode> GetListSucc() { List <GenericNode> possibilities = new List <GenericNode>(); for (int i = 0; i < SizeTaquin; i++) { for (int j = 0; j < SizeTaquin; j++) { if (state[i, j] == -1) { if (i > 0) { NodeTaquin n1 = new NodeTaquin(switch2numbers(i, j, i - 1, j)); // n1.ParentNode = this; possibilities.Add(n1); // Enfants.Add(n1); } if (i < SizeTaquin - 1) { NodeTaquin n2 = new NodeTaquin(switch2numbers(i, j, i + 1, j)); // n2.ParentNode = this; possibilities.Add(n2); // Enfants.Add(n2); } if (j > 0) { NodeTaquin n3 = new NodeTaquin(switch2numbers(i, j, i, j - 1)); // n3.ParentNode = this; possibilities.Add(n3); // Enfants.Add(n3); } if (j < SizeTaquin - 1) { NodeTaquin n4 = new NodeTaquin(switch2numbers(i, j, i, j + 1)); // n4.ParentNode = this; possibilities.Add(n4); // Enfants.Add(n4); } //then navigates the adjacent existing cells to create new NodeTaquins //then add it to the possibilities list } } } return(possibilities); }
/// <summary> /// Returns false if the compared node isn't a NodeTaquin or is a different state than this node. Else, returns true. /// </summary> /// <param name="N2"></param> /// <returns></returns> public override bool IsEqual(GenericNode N2) { if (N2 is NodeTaquin) { NodeTaquin toCompare = (NodeTaquin)N2; for (int i = 0; i < SizeTaquin; i++) { for (int j = 0; j < SizeTaquin; j++) { if (state[i, j] != toCompare.state[i, j]) { return(false); } } } return(true); } else { return(false); } }