def jouer(self, couleur): if self.graphe == None: Graphe(couleur, B_NO).ajoutSommet(self) elif self.graphe.couleur == LIBRE: self.graphe.couleur = couleur self.couleur = couleur for i in range(len(self.listeVoisin)): if self.listeVoisin[i].couleur == couleur and self.listeVoisin[ i].graphe != self.graphe: self.listeVoisin[i].graphe.fusion(self.graphe)
def planning_cours(canvas, matiere, notion): global graphe global niveau print("niveau 24453", niveau) graphe = Graphe() graphe.cal_parcours(niveau) graphe.defintion_exercice(niveau, "normal", "") for k in range(len(L_dipso)): canvas.itemconfig(L_dipso[k] + 1, text=graphe.parcour_avec_exo[k].nom) canvas.tag_bind(L_dipso[k], '<ButtonPress-1>', onObjectClick2)
def __init__(self): self.taille = None self.joueurs = { } #Stocke la configuration (IA ou joueur) de chacun des joueurs self.menu() self.coups = 0 #matrice de sommets utilisée dans les graphes et taille n*n self.matriceSommets = [] for i in range(self.taille): self.matriceSommets.append([]) #on ajoute nos sommets for i in range(self.taille): for j in range(self.taille): self.matriceSommets[i].append(Sommet(i, j)) #ici on ajoute pour tous les sommets qui touchent un bord dans un graphe avec son bord Graphe(LIBRE, B_HAUT_BLEU | B_GAUCHE_ROUGE).ajoutSommet( self.matriceSommets[0][0]) Graphe(LIBRE, B_HAUT_BLEU | B_DROIT_ROUGE).ajoutSommet( self.matriceSommets[0][self.taille - 1]) Graphe(LIBRE, B_BAS_BLEU | B_GAUCHE_ROUGE).ajoutSommet( self.matriceSommets[self.taille - 1][0]) Graphe(LIBRE, B_BAS_BLEU | B_DROIT_ROUGE).ajoutSommet( self.matriceSommets[self.taille - 1][self.taille - 1]) for i in range(self.taille): if i == 0: for j in range(1, self.taille - 1): Graphe(LIBRE, B_HAUT_BLEU).ajoutSommet(self.matriceSommets[i][j]) elif i == self.taille - 1: for j in range(1, self.taille - 1): Graphe(LIBRE, B_BAS_BLEU).ajoutSommet(self.matriceSommets[i][j]) else: Graphe(LIBRE, B_GAUCHE_ROUGE).ajoutSommet(self.matriceSommets[i][0]) Graphe(LIBRE, B_DROIT_ROUGE).ajoutSommet( self.matriceSommets[i][self.taille - 1]) #on va ajouter tous les voisins de tous les sommets for x in range(self.taille): for y in range(self.taille): if x != 0: self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x - 1][y]) if y != 0: self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x][y - 1]) if x != self.taille - 1: self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x + 1][y - 1]) if x != self.taille - 1: self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x + 1][y]) if y != self.taille - 1: if x != 0: self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x - 1][y + 1]) self.matriceSommets[x][y].ajoutVoisin( self.matriceSommets[x][y + 1]) self.grille = Grille(Point(10, 30), self.taille, 40, self.matriceSommets) self.tourActuel = ROUGE self.plateaux = {} if (self.taille <= 4): self.genererPlateaux() self.canvas = 0 self.fenetre = 0 self.commencer()