Exemplo n.º 1
0
        private void DFS_Search(int x, int y, Path path, int direct, byte[,] visit)
        {
            //Neu la cell cuoi
            if (EndCell.tile_x == x && EndCell.tile_y == y)
            {
                path.Waypoints.Add(new Cell(EndCell));
                paths.Add(path);
            }
            int temp_x, temp_y;
            //int count = 0;
            //Du doan truoc
            bool is_turn_point = IsTurnPoint(x, y, direct);

            for (int i = 0; i < 4; i++)
            {
                //Chi xet cac huong khong nguoc voi huong da cho
                if (i + direct != 3)
                {
                    temp_x = x + Direction.dx[i]; temp_y = y + Direction.dy[i];
                    if (InBound(temp_x,temp_y) && InteractiveMap[temp_y * Width + temp_x] == PATH )
                    {
                        if (visit[temp_x, temp_y] <= path.id && path.IsPassedTurnpoint(temp_x,temp_y)){
                            return;
                        }

                        Path p;
                        //count++;
                        //if (count > 1) { path_number++; }
                        if (is_turn_point) {
                            path_number++;
                            p = new Path(path_number, path);
                            p.Turnpoints.Add(new Cell(x, y));
                        }
                        else { p = path; }

                        //Neu doi huong ma ko di thang
                        if (direct != -1 && direct != i)
                        {
                            p.Waypoints.Add(new Cell(x, y));
                        }

                        //Gan lai visit
                        visit[temp_x,temp_y] = p.id;

                        //Tiep tuc search voi o do
                        DFS_Search(temp_x, temp_y, p, i, visit);
                    }
                }
            }
        }