Exemplo n.º 1
0
        List <MoveDirection> build_route(Stack <GridPoint> points)
        {
            List <MoveDirection> l    = new List <MoveDirection>();
            GridPoint            init = new GridPoint(new Vector2(meX, meY));
            float nx = meX;
            float ny = meY;

            foreach (GridPoint p in points)
            {
                if (nx > p.Position.X)
                {
                    l.Add(MoveDirection.North);
                    nx = p.Position.X;
                    ny = p.Position.Y;

                    continue;
                }
                if (nx < p.Position.X)
                {
                    l.Add(MoveDirection.South);
                    nx = p.Position.X;
                    ny = p.Position.Y;
                    continue;
                }
                if (ny > p.Position.Y)
                {
                    l.Add(MoveDirection.East);
                    nx = p.Position.X;
                    ny = p.Position.Y;
                    continue;
                }
                if (ny < p.Position.Y)
                {
                    l.Add(MoveDirection.West);
                    nx = p.Position.X;
                    ny = p.Position.Y;
                    continue;
                }
            }
            foreach (MoveDirection m in l)
            {
                Console.WriteLine(m);
            }

            return(l);
        }
Exemplo n.º 2
0
        List <MoveDirection> find_route_astar(GridPoint target, List <List <GridPoint> > map)
        {
            Astar             as_Path  = new Astar(map);
            Stack <GridPoint> solution = new Stack <GridPoint>();

            solution = as_Path.FindPath(new Vector2(meX, meY), new Vector2(target.Position.X, target.Position.Y));
            // Reverse path (from start to end...)
            Stack <GridPoint> rsolution = new Stack <GridPoint>();

            foreach (GridPoint p in solution)
            {
                Console.WriteLine($"[ROUTE] {p.Position.X},{p.Position.Y}");
            }
            Console.WriteLine($"[ROUTE] {meX},{meY}");


            route = build_route(solution);

            return(route);
        }
Exemplo n.º 3
0
        GridPoint find_nearest_energy(List <GridPoint> pliste)
        {
            // Let's compute distance & find the nearest Energy point
            // pour chaque nrjtpoint appelé 'p' de nrj_list :
            // distance = valeur absolue (meX - GridPoint.posx)+ abs(meY-GridPoint.posy)
            GridPoint target  = new GridPoint(new Vector2(0, 0));
            float     mindist = 9999;

            foreach (GridPoint p in pliste)
            {
                float d = p.get_distance(meX, meY);
                if (d < mindist)
                {
                    target  = p;
                    mindist = d;
                    Console.WriteLine($"[TGT] mindist = {mindist}");
                }
            }
            Console.WriteLine($"[TGT] position {target.Position.X} {target.Position.Y} ");
            return(target);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Résultat du scan
        /// </summary>
        /// <param name="distance">Distance.</param>
        /// <param name="informations">Informations.</param>
        /// Compte les energies et defini si une case est "walkable" ou non
        public void AreaInformation(byte distance, byte[] informations)
        {
            if (distance <= 1)
            {
                return;
            }

            int radar_nrj = 0;
            List <GridPoint>         NRJ_list = new List <GridPoint>();
            List <List <GridPoint> > ScanMap  = new List <List <GridPoint> >();

            Console.WriteLine($"Area: {distance}");
            int index = 0;

            for (int i = 0; i < distance; i++)
            {
                List <GridPoint> lineCells = new List <GridPoint>();
                for (int j = 0; j < distance; j++)
                {
                    GridPoint p = new GridPoint(new Vector2(i, j));
                    // IF point is energy :
                    if (informations[index] == (byte)CaseState.Energy)
                    {
                        radar_nrj++;
                        NRJ_list.Add(p);
                        p.Walkable = true;
                    }
                    // If point point is Ennemy
                    if (informations[index] == (byte)CaseState.Ennemy)
                    {
                        meX        = j;
                        meY        = i;
                        p.Walkable = true;
                    }
                    if (informations[index] == (byte)CaseState.Wall)
                    {
                        p.Walkable = false;
                    }
                    if (informations[index] == (byte)CaseState.Empty)
                    {
                        p.Walkable = true;
                    }
                    index++;
                    lineCells.Add(p);
                }
                ScanMap.Add(lineCells);
            }

            // Find route for each nrgpoint :

            /*
             * List<List<MoveDirection>> routes = new List<List<MoveDirection>>();
             * foreach (GridPoint p in NRJ_list)
             * {
             *  //route = find_route(p);
             *  route = find_route_astar(p,ScanMap);
             *
             *  if (check_route(route))
             *  {
             *      routes.Add(route);
             *  }
             *
             * }
             */
            mytarget = find_nearest_energy(NRJ_list);
            route    = find_route_astar(mytarget, ScanMap);
        }