Ejemplo n.º 1
0
        public bool RunTrajectory(Trajectory traj)
        {
            TrajectoryRunning = traj;
            TimeSpan  estimatedDuration = traj.GetDuration(this);
            Stopwatch sw = Stopwatch.StartNew();

            TrajectoryCutOff = false;
            TrajectoryFailed = false;

            foreach (IAction action in traj.ConvertToActions(this))
            {
                if (!Execution.Shutdown)
                {
                    action.Executer();

                    if (TrajectoryCutOff || TrajectoryFailed)
                    {
                        break;
                    }

                    if (action is ActionAvance || action is ActionRecule)
                    {
                        Historique.Log("Noeud atteint " + TrajectoryRunning.Points[0].X.ToString("0") + ":" + TrajectoryRunning.Points[0].Y.ToString("0"), TypeLog.PathFinding);
                        TrajectoryRunning.RemovePoint(0);
                    }
                }
            }

            if (!Execution.Shutdown)
            {
                TrajectoryRunning = null;

                if (!TrajectoryCutOff && !TrajectoryFailed)
                {
                    Historique.Log("Trajectoire parcourue en " + (sw.ElapsedMilliseconds / 1000.0).ToString("0.0") + "s (durée théorique : " + (estimatedDuration.TotalSeconds).ToString("0.0") + "s)", TypeLog.PathFinding);

                    return(true);
                }

                if (TrajectoryFailed)
                {
                    Historique.Log("Echec du parcours de la trajectoire (dérapage, blocage...)", TypeLog.PathFinding);

                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool GoToPosition(Position dest)
        {
            Historique.Log("Lancement pathfinding pour aller en " + dest.ToString(), TypeLog.PathFinding);

            Trajectory traj = PathFinder.ChercheTrajectoire(Graph, GameBoard.ObstaclesAll, GameBoard.ObstaclesOpponents, Position, dest, Radius, Robots.MainRobot.Width / 2);

            if (traj == null)
            {
                return(false);
            }

            RunTrajectory(traj);

            return(!TrajectoryCutOff && !TrajectoryFailed);
        }
Ejemplo n.º 3
0
        public bool OpponentsTrajectoryCollision(IEnumerable <IShape> opponents)
        {
            bool ok = true;

            if (TrajectoryCutOff)
            {
                ok = false;
            }

            if (ok)
            {
                try
                {
                    // Teste si le chemin en cours de parcours est toujours franchissable
                    if (TrajectoryRunning != null && TrajectoryRunning.Lines.Count > 0)
                    {
                        List <Segment> segmentsTrajectoire = new List <Segment>();
                        // Calcule le segment entre nous et notre destination (permet de ne pas considérer un obstacle sur un tronçon déjà franchi)
                        Segment toNextPoint = new Segment(Position.Coordinates, new RealPoint(TrajectoryRunning.Lines[0].EndPoint));
                        segmentsTrajectoire.Add(toNextPoint);

                        for (int iSegment = 1; iSegment < TrajectoryRunning.Lines.Count; iSegment++)
                        {
                            segmentsTrajectoire.Add(TrajectoryRunning.Lines[iSegment]);
                        }

                        foreach (IShape opponent in opponents)
                        {
                            foreach (Segment segment in segmentsTrajectoire)
                            {
                                // Marge de 30mm pour être plus permissif sur le passage et ne pas s'arreter dès que l'adversaire approche
                                if (!IsFarEnough(toNextPoint, opponent, -30))
                                {
                                    // Demande de génération d'une nouvelle trajectoire
                                    Historique.Log("Trajectoire coupée, annulation", TypeLog.PathFinding);
                                    TrajectoryCutOff  = true;
                                    TrajectoryRunning = null;

                                    if (IsInLineMove)
                                    {
                                        Stop();
                                    }
                                    ok = false;
                                    break;
                                }
                            }

                            if (!ok)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    ok = false;
                }
            }

            return(ok);
        }