Python CodeBoot Bug NEED HELP ASAP

hi everyone I just need help with my maze py code so I’ve tested my other function with assert and it all went good but when it comes to the laby function when I have to create the waze in codeboot, the maze has no sens it doesn’t have any logical path.

the sequence function takes a non-negative integer n as a parameter and returns an array of length n containing in order the integer values ​​from 0 to n-1 inclusive. the contient function takes as parameters an array of numbers (tab) and a number x and returns a boolean indicating whether x is contained in the array. the ajouter function takes as parameters an array of numbers (tab) and a number x and returns a new array with the same content as tab except that x is added at the end if it is not already contained in tab.

the retirer function as parameters an array of numbers (tab) and a number x and returns a new array with the same content as tab except that x is removed from the array. And finaly the voisins function takes the coordinate (x,y) of a cell and the size of a grid (width=nx and height=ny) and returns an array containing the number of neighboring cells.

i’ve uploaded a picture that shows you what does the code do
Capture d’écran 2023-10-31 190946

So there is the laby function you can test it in codeboot :


    murs_horizontaux = sequence(nx * (ny + 1))
    murs_verticaux = sequence((nx + 1) * ny)
​
    cave = [1]
    front = voisins(0, 0, nx, ny)
​
    while front:   
        # Choisir une cellule aléatoire parmi les cellules de front
        num = front[int(random() * len(front))]
        x = num // nx
        y = num % nx
​
        # Ajouter la cellule choisie à cave et la retirer de front
        cave = ajouter(cave, num)
        front = retirer(front, num)
​
        # Ajouter les voisins de la cellule choisie à front
        for voisin in voisins(x, y, nx, ny):
            if not contient(cave, voisin):
                front = ajouter(front, voisin)
        
        for cell in front:
            cell_x = cell // nx
            cell_y = cell % nx
            for voisin in voisins(cell_x, cell_y, nx, ny):
                if contient(cave, voisin):
                    # Si c'est le cas, retirez le mur entre la cellule et son voisin
                    voisin_x = voisin // nx
                    voisin_y = voisin % nx
                    if voisin_x == cell_x - 1:  # Voisin à gauche
                        murs_verticaux = retirer(murs_verticaux, cell_x + cell_y * (nx + 1))
                    elif voisin_x == cell_x + 1:  # Voisin à droite
                        murs_verticaux = retirer(murs_verticaux, 1 + cell_x + cell_y * (nx + 1))
                    elif voisin_y == cell_y - 1:  # Voisin en haut
                        murs_horizontaux = retirer(murs_horizontaux, cell_x + cell_y * nx)
                    elif voisin_y == cell_y + 1:  # Voisin en bas
                        murs_horizontaux = retirer(murs_horizontaux, cell_x + (cell_y + 1) * nx)
                    # Arrêtez de vérifier les autres voisins une fois que vous avez retiré un mur
                    break
                   
                    
            
    for i in range(largeur):
        for j in range(hauteur):
            if (i % dimension == 0 or j % dimension == 0):  # Si le pixel est sur une ligne ou une colonne de la grille
                if (i // dimension + j // dimension * nx in murs_horizontaux or i // dimension + j // dimension * (nx + 1) in murs_verticaux):  # Si le pixel correspond à un mur du labyrinthe
                    set_pixel(i, j, "#000")  # On dessine un pixel noir pour le mur
                else:
                    set_pixel(i, j, "#FFF")  # On dessine un pixel blanc pour le passage
            else:
                set_pixel(i, j, "#FFF")  # On dessine un pixel blanc pour le fond du labyrinthe

Also the laby function creates a random maze (width=nx and height=ny) and draws this maze in the pixel window using a grid with pixel dimension cells of width and height and walls whose thickness is 1 pixel. The dimension value is the number of pixels between lines. All parameters are integers >= 1. The maze must be black on a white background.