2017-03-08 10:32:11 +01:00
|
|
|
import matplotlib.pyplot as plt; plt.rcdefaults()
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from pylab import *
|
2017-03-15 10:16:14 +01:00
|
|
|
import matplotlib.animation as animation
|
2017-03-08 10:32:11 +01:00
|
|
|
|
|
|
|
|
2017-03-08 10:56:11 +01:00
|
|
|
TailleGrilleX = 15
|
|
|
|
TailleGrilleY = 15
|
2017-03-08 10:32:11 +01:00
|
|
|
GrilleInitiale = 0
|
|
|
|
HistoriqueGrille = list()
|
|
|
|
StratsResultats = list()
|
|
|
|
ListeStrategies = list()
|
|
|
|
|
2017-03-15 12:24:06 +01:00
|
|
|
def matRecup(i, param):
|
|
|
|
"""array*str-> array
|
|
|
|
Récupère la matrice avec seulement le paramètre stratégie pour chaque joueur , à litération i voulue"""
|
|
|
|
matR = np.random.randint(0,1,(TailleGrilleX,TailleGrilleY))
|
|
|
|
|
|
|
|
|
|
|
|
matrice = HistoriqueGrilles[i]
|
|
|
|
|
2017-03-15 09:53:15 +01:00
|
|
|
|
2017-03-15 12:24:06 +01:00
|
|
|
for ligne in range (0,TailleGrilleX): #int ligne
|
|
|
|
for colonne in range (0, TailleGrilleY): #int colonne
|
|
|
|
matR[ligne][colonne]=matrice[ligne][colonne][param]
|
|
|
|
|
|
|
|
return matR
|
2017-03-15 10:16:00 +01:00
|
|
|
|
|
|
|
|
2017-03-15 09:53:15 +01:00
|
|
|
fig=plt.figure()
|
|
|
|
fig.suptitle('Animation des stratégies')
|
2017-03-15 12:24:06 +01:00
|
|
|
cmap = mpl.colors.ListedColormap(["black","green" ,"red" ,"blue" ,"yellow"])
|
|
|
|
bounds=[0,1,2,3,4,5]
|
2017-03-15 09:53:15 +01:00
|
|
|
norm=mpl.colors.BoundaryNorm(bounds, cmap.N)
|
2017-03-15 12:24:06 +01:00
|
|
|
img=plt.imshow(matRecup(0, 'strategie'), interpolation = "nearest", cmap = cmap , norm = norm)
|
|
|
|
|
|
|
|
cb=plt.colorbar(img , cmap=cmap , norm=norm , boundaries = bounds , ticks=bounds)
|
|
|
|
labels = np.arange(1, 6, 1)
|
|
|
|
cb.set_ticklabels(labels)
|
|
|
|
|
2017-03-15 10:16:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update(next_iteration,*args):
|
2017-03-15 12:24:06 +01:00
|
|
|
img.set_array(matRecup(next_iteration , 'strategie'))
|
|
|
|
return [img]
|
2017-03-15 10:16:00 +01:00
|
|
|
|
2017-03-15 12:24:06 +01:00
|
|
|
anim = animation.FuncAnimation(fig, update, frames=range(MaxIterations), interval=1000, repeat = False)
|
2017-03-15 09:33:54 +01:00
|
|
|
plt.show()
|
2017-03-08 10:32:11 +01:00
|
|
|
|
2017-03-15 10:33:56 +01:00
|
|
|
|
|
|
|
|
2017-03-08 12:07:10 +01:00
|
|
|
|
2017-03-08 12:26:00 +01:00
|
|
|
|
2017-03-08 12:00:03 +01:00
|
|
|
|
2017-03-15 12:24:06 +01:00
|
|
|
|
|
|
|
def affichage_strats_resultats_totaux():
|
2017-03-08 10:32:11 +01:00
|
|
|
"""array->graph
|
2017-03-08 11:56:06 +01:00
|
|
|
Retourne les diagrammes en baton qui mettent en évidence le nombre d'années
|
2017-03-08 12:26:00 +01:00
|
|
|
de prison en fonction de la stratégie et le nombre d'utilisation de chaque stratégies """
|
2017-03-08 11:56:06 +01:00
|
|
|
|
2017-03-08 10:32:11 +01:00
|
|
|
|
2017-03-09 12:26:24 +01:00
|
|
|
|
2017-03-08 10:32:11 +01:00
|
|
|
#initialisation des paramètres
|
|
|
|
#list gain
|
|
|
|
gain=[]
|
|
|
|
#list strat
|
2017-03-09 12:26:24 +01:00
|
|
|
stratUtili=[]
|
2017-03-08 10:32:11 +01:00
|
|
|
|
|
|
|
for i in range(5):
|
|
|
|
|
|
|
|
gain.append(0)
|
2017-03-09 12:26:24 +01:00
|
|
|
stratUtili.append(0)
|
2017-03-08 10:32:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-08 11:45:12 +01:00
|
|
|
for i in range(0,len(ListeStrategies)):
|
2017-03-15 12:24:06 +01:00
|
|
|
stratUtili[i]=StratsResultats[i][0]
|
|
|
|
gain[i]=StratsResultats[i][1]
|
|
|
|
|
|
|
|
#Diviser nb années de prison par le nb d'utilisatons de le stratégi (moyenne)
|
|
|
|
|
2017-03-08 10:32:11 +01:00
|
|
|
Strat=('1','2', '3','4' ,'5')
|
|
|
|
|
|
|
|
x_pos = np.arange(len(Strat))
|
|
|
|
|
|
|
|
plt.subplot(221)
|
2017-03-15 12:24:06 +01:00
|
|
|
plt.bar(x_pos, stratUtili, align='center' , color='r')
|
|
|
|
plt.xlabel("Stratégies")
|
|
|
|
plt.ylabel("Nombre individus ayant adopté stratégie")
|
|
|
|
|
2017-03-08 10:32:11 +01:00
|
|
|
|
2017-03-15 12:24:06 +01:00
|
|
|
plt.xticks(x_pos,Strat)
|
|
|
|
|
|
|
|
|
|
|
|
plt.subplot(222)
|
2017-03-08 10:32:11 +01:00
|
|
|
plt.bar(x_pos, gain, align='center', color='b' )
|
|
|
|
|
|
|
|
plt.xlabel("Stratégies")
|
|
|
|
plt.ylabel("Nombre d'années de prison")
|
|
|
|
plt.xticks(x_pos,Strat)
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-08 10:56:11 +01:00
|
|
|
|