コード例 #1
0
        public double update(int temps, Grille grille)
        {
            OldDirection = carActualDirection;
            updateAvailableDirection(grille);
            Asphalte myActualCell = (Asphalte)grille.getCellule(CoordonneeXInt, CoordonneeYInt);

            if (actualRoute != null && myActualCell.ListeRoute.Contains(actualRoute))
            {
                speed = actualRoute.Vitesse;
            }
            else
            {
                foreach (Route route in myActualCell.ListeRoute)
                {
                    actualRoute = route;
                    speed       = route.Vitesse;
                    break;
                }
            }

            if (updateToMyBestDirectionIfPossible(grille))
            {
                return(speed);
            }

            return(speed);
        }
コード例 #2
0
ファイル: Simulation.cs プロジェクト: jmprovencher/SPTR
        public void RemplirGrille()
        {
            //Ajout des routes
            foreach (Route r in ListeRoutes)
            {
                int startX = 0, startY = 0, stopX = 0, stopY = 0;

                if (r.XDebut == r.XFin)
                {
                    startX = r.XDebut;
                    stopX = startX;
                    if (r.YDebut < r.YFin)
                    {
                        startY = r.YDebut;
                        stopY = r.YFin;
                    }
                    else
                    {
                        startY = r.YFin;
                        stopY = r.YDebut;
                    }
                }
                else if (r.YDebut == r.YFin)
                {
                    startY = r.YDebut;
                    stopY = startY;
                    if (r.XDebut < r.XFin)
                    {
                        startX = r.XDebut;
                        stopX = r.XFin;
                    }
                    else
                    {
                        startX = r.XFin;
                        stopX = r.XDebut;
                    }
                }
                
                for (int i = startX; i <= stopX; i++)
                {
                    for (int j = startY; j <= stopY; j++)
                    {
                        if (GrilleSimulation.getCellule(i, j).GetType() != typeof(Asphalte))
                        {
                            Asphalte asphalte = new Asphalte(i, j, GrilleSimulation.TailleCellules);
                            GrilleSimulation.setCellule(i,j,asphalte);
                            if (i > 0 && GrilleSimulation.getCellule(i - 1, j).GetType() == typeof(Asphalte))
                            {
                                asphalte.addLeftRightLine();
                            }

                            if (j > 0 && GrilleSimulation.getCellule(i , j - 1).GetType() == typeof(Asphalte))
                            {
                                asphalte.addUpDownLine();
                            }
                        }
                        ((Asphalte)GrilleSimulation.getCellule(i, j)).ListeRoute.Add(r);

                    }
                }
                
            }
            // Ajout des feux
            for (int i = 0; i<ListeFeux.Count;i++)
            {
                Feu f = ListeFeux[i];
                int offsetX = 0, offsetY = 0;
                switch (f.Position)
                {
                    case "N":
                        offsetY = -1;
                        offsetX = -1;
                        break;
                    case "S":
                        offsetY = 1;
                        offsetX = 1;
                        break;
                    case "E":
                        offsetX = 1;
                        offsetY = -1;
                        break;
                    case "O":
                        offsetX = -1;
                        offsetY = 1;
                        break;
                }
                f.CoordonneeX += offsetX;
                f.CoordonneeY += offsetY;
                Feu nouveauFeu = new Feu(GrilleSimulation.TailleCellules, f);
                GrilleSimulation.setCellule(f.CoordonneeX,f.CoordonneeY,  nouveauFeu);
                ListeFeux[i] = nouveauFeu;
            }

            //Ajout de la voiture
            int initialVoitureX = ParametresSimulation.XDepart;
            int initialVoitureY = ParametresSimulation.YDepart;
            int endVoitureX = ParametresSimulation.XArrivee;
            int endVoitureY = ParametresSimulation.YArrivee;

            if (GrilleSimulation.getCellule(initialVoitureX, initialVoitureY).GetType() == typeof(Asphalte))
            {
                Asphalte start = (Asphalte)GrilleSimulation.getCellule(initialVoitureX, initialVoitureY);
                MaVoiture  = new VoitureIntelligente(start.CoordonneeX, start.CoordonneeY, start.TailleCellule, "O", endVoitureX, endVoitureY);
            }
            
        }
コード例 #3
0
ファイル: Simulation.cs プロジェクト: jmprovencher/SPTR
        public void RemplirGrille()
        {
            //Ajout des routes
            foreach (Route r in ListeRoutes)
            {
                int startX = 0, startY = 0, stopX = 0, stopY = 0;

                if (r.XDebut == r.XFin)
                {
                    startX = r.XDebut;
                    stopX  = startX;
                    if (r.YDebut < r.YFin)
                    {
                        startY = r.YDebut;
                        stopY  = r.YFin;
                    }
                    else
                    {
                        startY = r.YFin;
                        stopY  = r.YDebut;
                    }
                }
                else if (r.YDebut == r.YFin)
                {
                    startY = r.YDebut;
                    stopY  = startY;
                    if (r.XDebut < r.XFin)
                    {
                        startX = r.XDebut;
                        stopX  = r.XFin;
                    }
                    else
                    {
                        startX = r.XFin;
                        stopX  = r.XDebut;
                    }
                }

                for (int i = startX; i <= stopX; i++)
                {
                    for (int j = startY; j <= stopY; j++)
                    {
                        if (GrilleSimulation.getCellule(i, j).GetType() != typeof(Asphalte))
                        {
                            Asphalte asphalte = new Asphalte(i, j, GrilleSimulation.TailleCellules);
                            GrilleSimulation.setCellule(i, j, asphalte);
                            if (i > 0 && GrilleSimulation.getCellule(i - 1, j).GetType() == typeof(Asphalte))
                            {
                                asphalte.addLeftRightLine();
                            }

                            if (j > 0 && GrilleSimulation.getCellule(i, j - 1).GetType() == typeof(Asphalte))
                            {
                                asphalte.addUpDownLine();
                            }
                        }
                        ((Asphalte)GrilleSimulation.getCellule(i, j)).ListeRoute.Add(r);
                    }
                }
            }
            // Ajout des feux
            for (int i = 0; i < ListeFeux.Count; i++)
            {
                Feu f = ListeFeux[i];
                int offsetX = 0, offsetY = 0;
                switch (f.Position)
                {
                case "N":
                    offsetY = -1;
                    offsetX = -1;
                    break;

                case "S":
                    offsetY = 1;
                    offsetX = 1;
                    break;

                case "E":
                    offsetX = 1;
                    offsetY = -1;
                    break;

                case "O":
                    offsetX = -1;
                    offsetY = 1;
                    break;
                }
                f.CoordonneeX += offsetX;
                f.CoordonneeY += offsetY;
                Feu nouveauFeu = new Feu(GrilleSimulation.TailleCellules, f);
                GrilleSimulation.setCellule(f.CoordonneeX, f.CoordonneeY, nouveauFeu);
                ListeFeux[i] = nouveauFeu;
            }

            //Ajout de la voiture
            int initialVoitureX = ParametresSimulation.XDepart;
            int initialVoitureY = ParametresSimulation.YDepart;
            int endVoitureX     = ParametresSimulation.XArrivee;
            int endVoitureY     = ParametresSimulation.YArrivee;

            if (GrilleSimulation.getCellule(initialVoitureX, initialVoitureY).GetType() == typeof(Asphalte))
            {
                Asphalte start = (Asphalte)GrilleSimulation.getCellule(initialVoitureX, initialVoitureY);
                MaVoiture = new VoitureIntelligente(start.CoordonneeX, start.CoordonneeY, start.TailleCellule, "O", endVoitureX, endVoitureY);
            }
        }