Skip to content
Snippets Groups Projects
Select Git revision
  • 1991c911b5d7525da2d6045a5efda2eb113d58b8
  • main default protected
  • variant
3 results

BoardFirefighterProperties.class

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    examen.py 2.27 KiB
    #Imports éventuels
    from itertools import chain
    import matplotlib.pyplot as plt
    #Déclaration des classes et des fonctions
    
    class TabletteChocolat:
        """
        m: nombres de lignes int
        n : nombres de colonnes int
        """
        def __init__(self, m, n):
            if type(m) != int or type(n) != int:
                raise TypeError
            self.m = m
            self.n = n
        def __str__(self):
            """
            Doc de String
            :return: Tablette de chocolat de mxn
            """
            return 'Tablette de chocolat de ' + str(self.m) + 'x' + str(self.n)
        def __repr__(self):
            """
            Doc de __repr__
            :return: Tablette de chocolat de mxn
            """
            print('Tablette de chocolat de ' + str(self.m) + 'x' + str(self.n))
        def coups_possibles(self):
            """
            Doc de coups_possibles
            :return: generator
            """
            i = 0
            j= 0
            while i < self.m -1:
                i +=1
                yield (i,j)
            i=0
            while j < self.n -1:
                j +=1
                yield (i,j)
            return chain(i,j)
        def est_possible(self, i, j):
            if (i,j) in self.coups_possibles():
                return True
            else:
                return False
        def coupe(self, i, j):
            """
            Doc de coupe
            :param i: int nombre de ligne enlevé
            :param j: int nombre de colonne enlevé
            :return: TabletteChocolat
            """
            if self.est_possible(i,j):
                return TabletteChocolat(self.m - i, self.n - j)
            else:
                raise ValueError('Coup impossible')
        def plot(self):
            m=self.m
            n=self.n
            plt.fill([0,m,m,0,0],[0,0,n,n,0], color='#D5B799')
            for i in range(m):
                for j in range(n):
                    X = [i+0.1, i+0.1, i+0.9, i+0.9, i+0.1]
                    Y = [j+0.1, j+0.9, j+0.9, j+0.1, j+0.1]
                    plt.plot(X,Y, color='#000')
            n = 0
            m -=1
            plt.fill([m+0.1, m+0.1, m+0.9, m+0.9, m+0.1], [n+0.1, n+0.9, n+0.9, n+0.1, n+0.1], color='#000')
            plt.gca().set_aspect('equal')
            plt.axis('off')
            plt.show()
            plt.close()
    
    
    #Programme Principal
    
    Tablette = TabletteChocolat(4,3)
    print(Tablette)
    g= Tablette.coups_possibles()
    print(list(g))
    print(Tablette.est_possible(1,0))
    biscuit = Tablette.coupe(1,0)
    Tablette.plot()