import matplotlib.pyplot as plt import pylab as pp def dessiner_grille(): for k in range(7): plt.plot([0, 7], [k, k], color = 'grey') for k in range(8): plt.plot([k,k], [0,6], color = 'grey') def dessiner_les_jetons(g): for i in range(len(g)): for j in range(len(g[0])): if g[i][j] == 1: plt.scatter( 0.5 + i , 0.5 + j, s = 1000, marker = 'o', color = "yellow") elif g[i][j] == 2: plt.scatter( 0.5 + i , 0.5 + j, s = 1000, marker = 'o', color = "red") # question 13 def humain_vs_machine(w:list, p:int): ''' gère une partie interactive (au clavier) entre un humain et l'algorithme min-max (liste de poids w, profondeur d'analyse p) ''' humain = 1+randrange(2) # tirage au sort du numéro du joueur humain print("Le tirage au sort vous a désigné comme le joueur numéro",humain) G = init() joueur = 1 # joueur courant for i in range(42): # print("position actuelle:") # display(G) dessiner_grille() dessiner_les_jetons(G) plt.show() pp.pause(1) if joueur==humain: ok = False while not ok: col = input("dans quelle colonne (1 à 7) voulez-vous jouer ? ") x = int(col)-1 ok = x>=0 and x<=6 and G[x][5]==0 y = 5 while y>0 and G[x][y-1]==0: y -= 1 else: U,c = minmax(G,joueur,w,p) x,y = c print("L'ordinateur joue dans la colonne",x+1) print("score estimé:",U) G[x][y] = joueur f = fini(G) if f!=0: break joueur = 3-joueur print() if f==0: print("Match nul !") elif f==humain: print("Vous avez gagné !") else: print("L'ordinateur a gagné !") # print() # print("position finale:") # display(G) dessiner_grille() dessiner_les_jetons(G) plt.show() pp.pause(1) print() tous = tous_alignements() w = [0,1,10,30,float('inf')] humain_vs_machine(w,5)