2017-03-01 12:13:39 +01:00
|
|
|
import matplotlib.pyplot as plt; plt.rcdefaults()
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
|
TailleGrilleX = 15
|
|
|
|
TailleGrilleY = 15
|
|
|
|
GrilleInitiale = 0
|
|
|
|
HistoriqueGrille = list()
|
|
|
|
StratsResultats = list()
|
|
|
|
|
|
|
|
|
|
|
|
def recup_mat(matrice, param):
|
|
|
|
""" array*str-> array
|
|
|
|
Récupère la matrice avec seulement le paramètre (état,strat,années de prison) voulu afin de pouvoir avoir les stats plus facilement"""
|
|
|
|
|
|
|
|
|
|
|
|
matR = np.random.randint(0,1,TailleGrilleX,TailleGrilleY)
|
|
|
|
|
|
|
|
for ligne in range (0,TailleGrilleX): #int ligne
|
|
|
|
for colonne in range (0, TailleGrilleY): #int colonne
|
|
|
|
for p in matrice[ligne,colonne]:
|
|
|
|
if p==param:
|
|
|
|
matR[ligne,colonne]=dict[param]
|
|
|
|
return matR
|
|
|
|
|
|
|
|
def bar_chart():
|
|
|
|
"""array->graph
|
2017-03-01 12:15:08 +01:00
|
|
|
Retourne le diagramme en baton qui met en évidence le nombre d'années de prison en fonction de la stratégie.
|
|
|
|
Il est mis à jour à chaque fos que tous les éléments de la grille ont fait leur 8 parties locales"""
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
matStrat=recup_mat(matrice,'strategie')
|
|
|
|
matGain=recup_mat(matrice,'annees_de_prison')
|
|
|
|
|
|
|
|
#initialisation des paramètres
|
2017-03-01 19:51:06 +01:00
|
|
|
#list gain
|
|
|
|
gain=[]
|
|
|
|
#list strat
|
|
|
|
strat=[]
|
|
|
|
|
|
|
|
for i range (6):
|
|
|
|
gain[i]=0
|
|
|
|
strat[i]=0
|
|
|
|
gain.append(gain[i])
|
|
|
|
strat.append(strat[i])
|
|
|
|
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
for ligne in range (0,TailleGrilleX):
|
|
|
|
for colonne in range(0, TailleGrilleY):
|
|
|
|
|
|
|
|
if matStrat[ligne,colonne]==0:
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
elif matStrat[ligne,colonne]==1:
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
elif matStrat[ligne,colonne]==2:
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
elif matStrat[ligne,colonne]==3:
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
elif matStrat[ligne,colonne]==4:
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
else :
|
2017-03-01 19:51:06 +01:00
|
|
|
strat[i]=strat[i]+1
|
|
|
|
gain[i]=gain[i]+matGain[ligne,colonne]
|
2017-03-01 12:13:39 +01:00
|
|
|
|
|
|
|
Strat=('1','2', '3','4' ,'5','6')
|
|
|
|
|
|
|
|
x_pos = np.arange(len(Strat))
|
|
|
|
|
2017-03-01 19:51:06 +01:00
|
|
|
|
|
|
|
|
2017-03-01 12:13:39 +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-01 12:15:08 +01:00
|
|
|
|