private void Revenir_a_plateforme_livraison() { // le départ est l'endroit ou est resté le chariot Emplacement depart = (Emplacement)chemin[chemin.Count() - 1]; string position = depart.GetX() + "." + depart.GetY(); // colorer le bon bouton Button btn = (Button)this.Controls.Find(position, true)[0]; btn.BackColor = Color.Blue; Program.entrepot.cell[depart.GetY(), depart.GetX()] = 0; // 2.trouver l'emplacement d'arrivée Emplacement arrivee = new Emplacement(); // si le colis est au nord, alors le chariot doit se placer sur la case en dessus soit -1 dans la matrice arrivee.SetX(0); int c = 0; double cout = 500, coutmin = 500; for (int k = 0; k < Program.entrepot.Get_largeur_entrepot(); k++) { if (Program.entrepot.cell[k, 0] != 2) { arrivee.SetY(k); nul = new Graph(arrivee, depart); chemin = nul.RechercheSolutionAEtoile(); if (chemin.Count > 0) { cout = chemin[chemin.Count() - 1].GetGCost(); } if (cout < coutmin) { coutmin = cout; c = k; } } } arrivee.SetY(c); // on fait appel à la fonction pour nous trouver nul = new Graph(arrivee, depart); chemin = nul.RechercheSolutionAEtoile(); // colorer le chemin de retour Deplacement_chariots(); Program.entrepot.cell[c, 0] = 2; Nv_colis_BTN.Visible = true; // on met le bouton du début en blanc btn.BackColor = Color.White; UnableChariots(); }
private void Deplacement_chariots() { if (chemin.Count() > 0) { Final_LBL.Text = "Une solution a été trouvée"; double cout = ((Emplacement)chemin[chemin.Count - 1]).GetGCost(); Final_LBL.Text += " avec un cout de " + cout + " secondes"; } else { Final_LBL.Text = "Pas de solution"; } for (int k = 0; k < chemin.Count() - 1; k++) { if (k != chemin.Count() - 1) { System.Threading.Thread.Sleep((int)chemin[k].GetArcCost(chemin[k + 1]) * 100); // todo : ne pas supprimer le premier avec k //On clean la position de depart Emplacement ptsDepart = (Emplacement)chemin[k]; string positionDep = ptsDepart.GetX().ToString() + "." + ptsDepart.GetY().ToString(); Button btn_3 = (Button)this.Controls.Find(positionDep, true)[0]; btn_3.Image = null; btn_3.BackColor = Color.Gold; btn_3.Text = null; btn_3.Refresh(); //On colore la position d'arrivee Emplacement ptsArrivee = (Emplacement)chemin[k + 1]; string positionArr = ptsArrivee.GetX().ToString() + "." + ptsArrivee.GetY().ToString(); Button btn_4 = (Button)this.Controls.Find(positionArr, true)[0]; btn_4.Image = Image.FromFile("../../Images/" + ptsArrivee.Get_orientation() + ".png"); btn_4.Text = Chariot_choisi.Get_cle_chariot().ToString(); btn_4.Refresh(); } } }
private void Deplacement_chariot(int k) { //1. on calcule leur trajet // la position de départ : leur position actuelle Emplacement ptsDepart = new Emplacement(Program.tab_chariot[k]._x, Program.tab_chariot[k]._y, Program.tab_chariot[k]._orientation, Program.tab_chariot[k]._hauteur); // la position de fin : calculé via le colis // quand la personne a choisi les caractéristiques de son colis Emplacement arrivee = new Emplacement(); // si le colis est au nord, alors le chariot doit se placer sur la case en dessus soit -1 dans la matrice if (Program.tab_chariot[k].chercher_un_colis) { #region Si le chariot a pris son colis et doit revenir à la plateforme // le chariot doit revenir à sa plateforme arrivee.SetX(0); int c = 0; double cout = 600, coutmin = 500; for (int kk = 0; kk < Program.entrepot.Get_largeur_entrepot(); kk++) { if (Program.entrepot.cell[kk, 0] != 2) { arrivee.SetY(kk); nul = new Graph(arrivee, ptsDepart); chemin = nul.RechercheSolutionAEtoile(); if (chemin.Count > 0) { cout = chemin[chemin.Count() - 1].GetGCost(); } if (cout < coutmin) { coutmin = cout; c = kk; } } } arrivee.SetY(c); #endregion } else { if (tab_colis[k]._orientation == "Nord") { arrivee.SetY(tab_colis[k]._y - 1); } else { arrivee.SetY(tab_colis[k]._y + 1); } // la position en x ne change pas arrivee.SetX(tab_colis[k]._x); } Graph trouver = new Graph(arrivee, ptsDepart); chemin = trouver.RechercheSolutionAEtoile(); // CHOIX 1 : quand le chariot est à l'emplacement final pour prendre le colis if (Program.tab_chariot[k]._x == tab_colis[k]._x && (Program.tab_chariot[k]._y - 1 == tab_colis[k]._y || Program.tab_chariot[k]._y + 1 == tab_colis[k]._y) && !Program.tab_chariot[k].chercher_un_colis) { #region Prendre le colis // on est arrivé au bout du chemin 1 Program.tab_chariot[k].chercher_un_colis = true; Program.tab_chariot[k].depot = true; Program.tab_chariot[k].depot_temps = 0; string positionArr = tab_colis[k]._x + "." + tab_colis[k]._y; Button btn_7 = (Button)this.Controls.Find(positionArr, true)[0]; // btn_4.Image = Image.FromFile("../../Images/" + arrivee.Get_orientation() + ".png"); btn_7.BackColor = Color.Purple; btn_7.Text = "X"; btn_7.Refresh(); // pour le chariot qui récupère le colis string position = Program.tab_chariot[k]._x + "." + Program.tab_chariot[k]._y; Button btn_6 = (Button)this.Controls.Find(position, true)[0]; // btn_4.Image = Image.FromFile("../../Images/" + arrivee.Get_orientation() + ".png"); btn_6.BackColor = Color.Yellow; btn_6.Text = "*"; btn_6.Refresh(); #endregion } // CHOIX 2 : quand le chariot est revenu à la livraison else if (Program.tab_chariot[k].chercher_un_colis && Program.tab_chariot[k]._x == 0) { // le chariot a donc pris son colis et est revenu sur la plateforme de livraison Program.tab_chariot[k].enLivraison = true; // pour le chariot qui récupère le colis string position = Program.tab_chariot[k]._x + "." + Program.tab_chariot[k]._y; Button btn_5 = (Button)this.Controls.Find(position, true)[0]; btn_5.BackColor = Color.Orange; btn_5.Text = "§"; btn_5.Refresh(); } // CHOIX 3 : quand il se déplace classiquement else if (chemin.Count > 1) { #region Deplacement d'un chariot vers une autre case //On clean la position de depart string positionDep = ptsDepart.GetX().ToString() + "." + ptsDepart.GetY().ToString(); Button btn_3 = (Button)this.Controls.Find(positionDep, true)[0]; btn_3.BackColor = Color.White; btn_3.Text = ""; btn_3.Refresh(); //On colore la position d'arrivee string positionArr = ((Emplacement)chemin[1]).GetX().ToString() + "." + ((Emplacement)chemin[1]).GetY().ToString(); Button btn_4 = (Button)this.Controls.Find(positionArr, true)[0]; // si la nouvelle case necessite un changement de direction if (ptsDepart.GetArcCost((Emplacement)chemin[1]) == 4 && Program.tab_chariot[k].rotation_temps != 0) { Program.tab_chariot[k].rotation = true; Program.tab_chariot[k].rotation_temps = 0; btn_3.BackColor = Color.Pink; btn_3.Text = Program.tab_chariot[k].Get_cle_chariot().ToString(); btn_3.Refresh(); Program.tab_chariot[k]._orientation = ((Emplacement)chemin[1]).Get_orientation(); } else { if (Program.tab_chariot[k].chercher_un_colis) { btn_4.BackColor = Color.Blue; } else { btn_4.BackColor = Color.Red; } btn_4.Text = Program.tab_chariot[k].Get_cle_chariot().ToString(); btn_4.Refresh(); // on enregistre les changements Program.entrepot.cell[Program.tab_chariot[k]._y, Program.tab_chariot[k]._x] = 0; Program.tab_chariot[k]._x = ((Emplacement)chemin[1]).GetX(); Program.tab_chariot[k]._y = ((Emplacement)chemin[1]).GetY(); Program.tab_chariot[k]._orientation = ((Emplacement)chemin[1]).Get_orientation(); Program.tab_chariot[k]._hauteur = 0; Program.entrepot.cell[((Emplacement)chemin[1]).GetY(), ((Emplacement)chemin[1]).GetX()] = 2; } #endregion } }
public override bool EndState(Emplacement final) { return(this.x == final.GetX() && this.y == final.GetY()); }