-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
529 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#!/usr/bin/env python3 | ||
## Codifieur.py for mastermind in /home/laloge_h/Documents/ISN/Mastermind | ||
## | ||
## Made by Hugo Laloge | ||
## Login <[email protected]> | ||
## | ||
## Started on Fri Feb 20 18:01:57 2015 Hugo Laloge | ||
## Last update Fri Feb 20 18:02:07 2015 Hugo Laloge | ||
## | ||
|
||
#-----------Import des modules---------# | ||
|
||
from tkinter import * | ||
from random import randint | ||
|
||
|
||
#-------Definition des fonctions-------# | ||
|
||
def genererCode(): | ||
global couleurs, code, grille | ||
couleurs = ['ivory', 'black', 'blue', 'red', 'green', 'yellow'] # 6 Couleurs possibles, tableau de 0 à 5 | ||
grille = [] | ||
reponse = [] | ||
tour = 0 | ||
for i in range(10): | ||
grille.append(['', '', '', '']) | ||
reponse.append(['', '', '', '']) | ||
code = [] | ||
|
||
for i in range(4): | ||
code.append(couleurs[randint(0,5)]) | ||
|
||
def afficherCode(): | ||
global code, canevas, codeAffiche | ||
for i in range(4): | ||
couleur=code[i] | ||
canevas.create_oval(i*20+20, 220, i*20+40, 240, fill=couleur) | ||
|
||
def changerCouleur(event): | ||
global couleurs, canevas, grille, tour | ||
x = int((event.x-20)/20) | ||
if x >= 0: | ||
couleurSuivante = {'ivory':'black', 'black':'blue', 'blue':'red', 'red':'green', 'green':'yellow', 'yellow':'ivory', '':'ivory'} | ||
couleur = couleurSuivante[grille[tour][x]] | ||
grille[tour][x] = couleur | ||
canevas.create_oval(x*20+20, tour*20, x*20+40, tour*20+20, fill=couleur) | ||
|
||
def valider(): | ||
global tour, grille, code, reponse | ||
nbPion = True | ||
couleurCorrect = 0 | ||
couleurPlace = 0 | ||
recoCode = [] | ||
for i in range(4): #On recopie le code | ||
recoCode.append(code[i]) | ||
|
||
for i in range(4): | ||
if grille[tour][i] == '': | ||
nbPion = False | ||
|
||
for essai in grille[tour]: #Boucle pour vérifier les couleurs | ||
for i in range(len(recoCode)): | ||
if essai == recoCode[i]: | ||
couleurCorrect += 1 | ||
recoCode.pop(i) | ||
break | ||
|
||
for i in range(4): #Boucle pour vérifier les couleurs bien placées | ||
if grille[tour][i] == code[i]: | ||
couleurPlace += 1 | ||
|
||
afficherRep(couleurCorrect, couleurPlace) | ||
print('couleurCorrect =', couleurCorrect, 'et couleurPlacé =', couleurPlace) | ||
|
||
if tour < 9 and nbPion: | ||
tour += 1 | ||
elif tour == 9: | ||
terminer() | ||
|
||
def afficherRep(couleurCorrect, couleurPlace): | ||
global canevas, tour | ||
for i in range(couleurCorrect): | ||
if i == 0: | ||
canevas.create_oval(0, tour*20, 10, tour*20+10, fill ='white') | ||
if i == 1: | ||
canevas.create_oval(10, tour*20, 20, tour*20+10, fill ='white') | ||
if i == 2: | ||
canevas.create_oval(0, tour*20+10, 10, tour*20+20, fill ='white') | ||
if i == 3: | ||
canevas.create_oval(10, tour*20+10, 20, tour*20+20, fill ='white') | ||
|
||
for i in range(couleurPlace): | ||
if i == 0: | ||
canevas.create_oval(0, tour*20, 10, tour*20+10, fill ='black') | ||
if i == 1: | ||
canevas.create_oval(10, tour*20, 20, tour*20+10, fill ='black') | ||
if i == 2: | ||
canevas.create_oval(0, tour*20+10, 10, tour*20+20, fill ='black') | ||
if i == 3: | ||
canevas.create_oval(10, tour*20+10, 20, tour*20+20, fill ='black') | ||
terminer() | ||
|
||
def terminer(): | ||
global canevas, valider | ||
afficherCode() | ||
canevas.unbind('<Button-1>') | ||
valider.destroy() | ||
|
||
|
||
#---------Création de la fenetre-------# | ||
|
||
fenetre = Tk() | ||
fenetre.wm_title('Master Mind - Codifieur') | ||
|
||
canevas = Canvas(fenetre, width=100, height=240, bg='dark grey') | ||
canevas.bind('<Button-1>', changerCouleur) | ||
for i in range(10): | ||
canevas.create_line(0, (i+1)*20, 100, (i+1)*20, fill='black') | ||
canevas.create_rectangle(0, 200, 100, 215, fill='black') | ||
canevas.create_line(20, 0, 20, 200, fill='black') | ||
canevas.pack(side=LEFT) | ||
|
||
valider = Button(fenetre, text='Valider ligne', command=valider) | ||
valider.pack(side=TOP) | ||
|
||
afficher = Button(fenetre, text='Afficher code', command=afficherCode) | ||
afficher.pack(side=TOP) | ||
|
||
generer = Button(fenetre, text='Recommencer', command=genererCode) | ||
generer.pack(side=TOP) | ||
|
||
quitter = Button(fenetre, text='Quitter', command=fenetre.destroy) | ||
quitter.pack(side=BOTTOM) | ||
|
||
genererCode() | ||
for i in range(4): | ||
canevas.create_oval(i*20+20, 220, i*20+40, 240, fill='grey') | ||
|
||
tour = 0 | ||
|
||
fenetre.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/usr/bin/env python3 | ||
## Decodeur.py for mastermind in /home/laloge_h/Documents/ISN/Mastermind | ||
## | ||
## Made by Hugo Laloge | ||
## Login <[email protected]> | ||
## | ||
## Started on Fri Feb 20 18:03:29 2015 Hugo Laloge | ||
## Last update Fri Feb 20 18:56:09 2015 Hugo Laloge | ||
## | ||
|
||
#-----------Import des modules---------# | ||
|
||
from tkinter import * | ||
from random import randint | ||
from IA import * | ||
|
||
|
||
#-------Definition des fonctions-------# | ||
|
||
def changerCouleur(event): | ||
global couleurs, canevas, grille, tour | ||
x = int((event.x - 20) / 20) | ||
if x >= 0: | ||
couleur = couleurs[(reponse[x] + 1) % 6] | ||
reponse[x] = (reponse[x] + 1) % 6 | ||
canevas.create_oval(x*20+20, 220, x*20+40, 240, fill=couleur) | ||
|
||
def afficherEval(hypot, reponse): | ||
global tour | ||
couleurCorrect = 0 | ||
couleurPlace = 0 | ||
recoCode = [] | ||
for i in range(4): #On recopie le code | ||
recoCode.append(reponse[i]) | ||
|
||
for i in range(4): | ||
if grille[tour][i] == '': | ||
nbPion = False | ||
|
||
for essai in hypot: #Boucle pour vérifier les couleurs | ||
for i in range(len(recoCode)): | ||
if essai == recoCode[i]: | ||
couleurCorrect += 1 | ||
recoCode.pop(i) | ||
break | ||
|
||
for i in range(4): #Boucle pour vérifier les couleurs bien placées | ||
if reponse[i] == hypot[i]: | ||
couleurPlace += 1 | ||
afficherRep(couleurCorrect, couleurPlace) | ||
|
||
def valider(): | ||
global grille, reponse, score, tour, couleurs | ||
while (tour < 10) : | ||
hypot = hypothese(tour, grille, score) | ||
print(hypot, reponse) | ||
grille.append(hypot) | ||
for x in range(4): | ||
canevas.create_oval(x*20+20, tour*20, x*20+40, tour*20 + 20, fill=couleurs[hypot[x]]) | ||
score.append(evaluer(hypot, reponse)) | ||
afficherEval(hypot, reponse) | ||
if (hypot == reponse): | ||
break | ||
tour += 1 | ||
print('Fini') | ||
|
||
def afficherRep(couleurCorrect, couleurPlace): | ||
global canevas, tour | ||
for i in range(couleurCorrect): | ||
if i == 0: | ||
canevas.create_oval(0, tour*20, 10, tour*20+10, fill ='white') | ||
if i == 1: | ||
canevas.create_oval(10, tour*20, 20, tour*20+10, fill ='white') | ||
if i == 2: | ||
canevas.create_oval(0, tour*20+10, 10, tour*20+20, fill ='white') | ||
if i == 3: | ||
canevas.create_oval(10, tour*20+10, 20, tour*20+20, fill ='white') | ||
|
||
for i in range(couleurPlace): | ||
if i == 0: | ||
canevas.create_oval(0, tour*20, 10, tour*20+10, fill ='black') | ||
if i == 1: | ||
canevas.create_oval(10, tour*20, 20, tour*20+10, fill ='black') | ||
if i == 2: | ||
canevas.create_oval(0, tour*20+10, 10, tour*20+20, fill ='black') | ||
if i == 3: | ||
canevas.create_oval(10, tour*20+10, 20, tour*20+20, fill ='black') | ||
terminer() | ||
|
||
def terminer(): | ||
global canevas, valider | ||
canevas.unbind('<Button-1>') | ||
valider.destroy() | ||
|
||
score = [] | ||
grille = [] | ||
reponse = [0,0,0,0] | ||
tour = 0 | ||
couleurs = ['ivory', 'black', 'blue', 'red', 'green', 'yellow'] | ||
|
||
#---------Création de la fenetre-------# | ||
|
||
fenetre = Tk() | ||
fenetre.wm_title('Master Mind - Codifieur') | ||
|
||
canevas = Canvas(fenetre, width=100, height=240, bg='dark grey') | ||
canevas.bind('<Button-1>', changerCouleur) | ||
for i in range(10): | ||
canevas.create_line(0, (i+1)*20, 100, (i+1)*20, fill='black') | ||
canevas.create_rectangle(0, 200, 100, 215, fill='black') | ||
canevas.create_line(20, 0, 20, 200, fill='black') | ||
canevas.pack(side=LEFT) | ||
|
||
valider = Button(fenetre, text='Valider reponse', command=valider) | ||
valider.pack(side=TOP) | ||
|
||
quitter = Button(fenetre, text='Quitter', command=fenetre.destroy) | ||
quitter.pack(side=BOTTOM) | ||
|
||
for i in range(4): | ||
canevas.create_oval(i*20+20, 220, i*20+40, 240, fill='ivory') | ||
|
||
fenetre.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def geneCouleur(gene, nbCouleur=6): | ||
"""Retourne un tableau de couleur à partir d'un numero de gene""" | ||
couleur = [] | ||
for i in range(4): #Il génère un tableau de couleur | ||
couleur.append(gene % nbCouleur) | ||
gene = gene // nbCouleur | ||
return couleur | ||
|
||
def couleurGene(couleur, nbCouleur=6): | ||
gene = 0 | ||
for i in range(4): | ||
gene += couleur[i]*nbCouleur**(i) | ||
return gene | ||
|
||
def inverseFitness(fitness): | ||
score = [0, 0] | ||
score[0] = fitness / 6 | ||
score[1] = fitness % 6 | ||
return score | ||
|
||
print(couleurGene([0,1,2,3])) | ||
print(couleurGene([2,1,0,0])) | ||
print(couleurGene([2,0,2,1])) | ||
print(couleurGene([0,4,3,1])) |
Oops, something went wrong.