Skip to content
Snippets Groups Projects
Commit 8a0a09a3 authored by VALLET Armel's avatar VALLET Armel
Browse files

question 10

parent e2e074dc
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ class TabletteChocolat: ...@@ -13,6 +13,9 @@ class TabletteChocolat:
def __repr__(self): def __repr__(self):
return str(self) return str(self)
def __eq__(self, other):
return self.m == other.m and self.n == other.n
def coups_possibles(self): def coups_possibles(self):
l = [] l = []
for i in range(self.m): for i in range(self.m):
...@@ -28,10 +31,10 @@ class TabletteChocolat: ...@@ -28,10 +31,10 @@ class TabletteChocolat:
return TabletteChocolat(self.m - i, self.n - j) return TabletteChocolat(self.m - i, self.n - j)
def plot(self): def plot(self):
for i in range(self.m): for i in range(self.n):
for j in range(self.n): for j in range(self.m):
plt.plot((i, i+1, i+1, i, i), (j, j, j+1, j+1, j), color='black') plt.plot((i, i+1, i+1, i, i), (j, j, j+1, j+1, j), color='black')
if i == self.m -1 and j == 0: if i == self.n -1 and j == 0:
plt.fill((i, i + 1, i + 1, i, i), (j, j, j + 1, j + 1, j), color='black') plt.fill((i, i + 1, i + 1, i, i), (j, j, j + 1, j + 1, j), color='black')
plt.gca().set_aspect('equal') plt.gca().set_aspect('equal')
plt.axis('off') plt.axis('off')
...@@ -41,16 +44,23 @@ class TabletteChocolat: ...@@ -41,16 +44,23 @@ class TabletteChocolat:
def demander_coup(self): def demander_coup(self):
n = 0 n = 0
x = input("Couper des lignes (l) ou colonnes (c) ? -> ") x = input("Couper des lignes (l) ou colonnes (c) ? -> ")
if x == "c":
while not self.est_possible(0, int(n)):
n = input("Combien de colonnes à couper ? Choix possibles : " + str(list(range(1, self.n))) + " -> ")
return self.coupe(0, int(n))
if x == "l": if x == "l":
while not self.est_possible(int(n), 0): while not self.est_possible(int(n), 0):
n = input("Combien de lignes à couper ? Choix possibles : " + str(list(range(1, self.m))) + " -> ") n = input("Combien de lignes à couper ? Choix possibles : " + str(list(range(1, self.m))) + " -> ")
return self.coupe(int(n), 0) return self.coupe(int(n), 0)
if x == "c":
while not self.est_possible(0, int(n)):
n = input("Combien de colonnes à couper ? Choix possibles : " + str(list(range(1, self.n))) + " -> ")
return t.coupe(0, int(n))
else: else:
return "Il faut répondre l ou c !" raise ValueError("Il faut répondre l ou c !")
def jouer(m, n):
choco = TabletteChocolat(m, n)
choco.plot()
while choco != TabletteChocolat(1, 1):
choco = choco.demander_coup()
choco.plot()
# Programme principal # Programme principal
...@@ -62,3 +72,4 @@ print(t.est_possible(0, 1)) ...@@ -62,3 +72,4 @@ print(t.est_possible(0, 1))
print(t.coupe(3, 1)) print(t.coupe(3, 1))
t.plot() t.plot()
print(t.demander_coup()) print(t.demander_coup())
jouer(5, 6)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment