public override double GetArcCost(GenericNode N) { double distance = Math.Sqrt(2); Node4 N2 = (Node4)N; if ((N2.x == this.x + 1 || N2.x == this.x - 1) && N2.y == this.y) { distance = 1; } if ((N2.y == this.y + 1 || N2.y == this.y - 1) && N2.x == this.x) { distance = 1; } return(distance); }
private void buttonCheckpoint_Click(object sender, EventArgs e) { //vérifier valeurs remplies if (textBoxDepartCheckpoint.Text == "" || textBoxCheckpoint1.Text == "" || textBoxCheckpoint2.Text == "" || textBoxCheckpoint3.Text == "" || textBoxCheckpoint4.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || !int.TryParse(textBoxDepartCheckpoint.Text, out celluleDepartCheck[0]) || !int.TryParse(textBoxCheckpoint1.Text, out check1[0]) || !int.TryParse(textBoxCheckpoint2.Text, out check2[0]) || !int.TryParse(textBoxCheckpoint3.Text, out check3[0]) || !int.TryParse(textBoxCheckpoint4.Text, out check4[0]) || !int.TryParse(textBox3.Text, out celluleDepartCheck[1]) || !int.TryParse(textBox4.Text, out check1[1]) || !int.TryParse(textBox5.Text, out check2[1]) || !int.TryParse(textBox6.Text, out check3[1]) || !int.TryParse(textBox7.Text, out check4[1])) { MessageBox.Show("Entrez 2 nombres dont les 2 chiffres sont respectivement la ligne puis la colonne."); return; } //L'utilisateur entre les coordonnées sur la grille qui commence à 1 contrairement à la matrice //donc il faut enlever 1 à chaque coordonnée celluleDepartCheck[0]--; check1[0]--; check2[0]--; check3[0]--; check4[0]--; celluleDepartCheck[1]--; check1[1]--; check2[1]--; check3[1]--; check4[1]--; if (!dansLaGrille(celluleDepartCheck[0], celluleDepartCheck[1]) || !dansLaGrille(check1[0], check1[1]) || !dansLaGrille(check2[0], check2[1]) || !dansLaGrille(check3[0], check3[1]) || !dansLaGrille(check4[0], check4[1])) { MessageBox.Show("Entrez un nombre valable : pas hors limite et pas sur un obstacle"); return; } //changer les valeurs matrice[celluleDepartCheck[0], celluleDepartCheck[1]] = 2; matrice[check1[0], check1[1]] = 3; matrice[check2[0], check2[1]] = 3; matrice[check3[0], check3[1]] = 3; matrice[check4[0], check4[1]] = 3; //On applique l'algo pour les checkpoints List <GenericNode> solution = graph.RechercheSolutionAEtoile(new Node4(celluleDepartCheck[0], celluleDepartCheck[1], false, false, false, false)); foreach (GenericNode n in solution) { Node4 node = (Node4)n; if (!((node.x == celluleDepartCheck[0] && node.y == celluleDepartCheck[1]) || (node.x == check1[0] && node.y == check1[1]) || (node.x == check2[0] && node.y == check2[1]) || (node.x == check3[0] && node.y == check3[1]) || (node.x == check4[0] && node.y == check4[1]))) { matrice[node.x, node.y] = 5; } } graph.GetSearchTree(treeView1); //montrer différents chemins ? //montrer chemin fini coloriageGraphique(); string solu = ""; foreach (GenericNode item in solution) { solu += (((Node4)item).x + 1).ToString() + " " + (((Node4)item).y + 1).ToString() + "\n"; } MessageBox.Show(solu); }
public override bool IsEqual(GenericNode N) { Node4 N2 = (Node4)N; return(this.x == N2.x && this.y == N2.y && this.c1 == N2.c1 && this.c2 == N2.c2 && this.c3 == N2.c3 && this.c4 == N2.c4); }