Optimisation

logopolop -  
 logopolop -
Bonjour,

je poste ce message car je me retrouve bloquer car je n'arrive pas a construire une boucle... oui ca peut sembler simplet et pourtant..

voila un peu le genre de boucle que je voudrais, en fait je cherche dans une grille les cases adjacente a un pion ou il n'ay a pas d'autres pions, une cases libre quoi
mais sur toute la ligne. Et la ca coince. voila mn code pour la fonction : (code juste pour montrer la logique de la recherche)

def checkCase(i,j):
    global coordPossibleCoup
    coordPossibleCoup = []
    test = i-1
    if test in range(nb) and (test,j) != citadelle:
        if (test,j) not in coordJoueurBlanc:
            if (test,j) not in coordJoueurNoir:
                can.create_rectangle(x0+c*test,y0+c*j, x0+c*(test+1), y0+c*(j+1),outline="green", width=5)
                coordPossibleCoup += [(test,j),]
                test = test-1
                if test in range(nb) and (test,j) != citadelle:
                    if (test,j) not in coordJoueurBlanc:
                        if (test,j) not in coordJoueurNoir:
                            can.create_rectangle(x0+c*test,y0+c*j, x0+c*(test+1), y0+c*(j+1),outline="green", width=5)
                            coordPossibleCoup += [(test,j),]
    test = i+1
    if test in range(nb) and (test,j) != citadelle:
        if (test,j) not in coordJoueurBlanc:
            if (test,j) not in coordJoueurNoir:
                can.create_rectangle(x0+c*test,y0+c*j, x0+c*(test+1), y0+c*(j+1),outline="green", width=5)
                coordPossibleCoup += [(test,j),]
    test = j-1
    if test in range(nb) and (i,test) != citadelle:
        if (i,test) not in coordJoueurBlanc:
            if (i,test) not in coordJoueurNoir:
                can.create_rectangle(x0+c*i,y0+c*test, x0+c*(i+1), y0+c*(test+1),outline="green", width=5)
                coordPossibleCoup += [(i,test),]
    test = j+1
    if test in range(nb) and (i,test) != citadelle:
        if (i,test) not in coordJoueurBlanc:
            if (i,test) not in coordJoueurNoir:
                can.create_rectangle(x0+c*i,y0+c*test, x0+c*(i+1), y0+c*(test+1),outline="green", width=5)
                coordPossibleCoup += [(i,test),]
    if coordPossibleCoup == []:
        affichage.delete("0.0",END)
        affichage.insert(END,"Ce pion ne peut pas bouger.")
        return False
    return True


A voir également:

1 réponse

logopolop
 
Resolu !

la reponse si jmais ca interesse :

test = i-1
    for count in range(i):
        if test in range(nb) and (test,j) != citadelle:
            if (test,j) not in coordJoueurBlanc:
                if (test,j) not in coordJoueurNoir:
                    can.create_rectangle(x0+c*test,y0+c*j, x0+c*(test+1), y0+c*(j+1),outline="green", width=5)
                    coordPossibleCoup += [(test,j),]
                    test = test-1
0