class Cafe:

    def actions(self):
        """ definit l'ensemble d'actions possibles """
        return(['tournerG','tournerD','prendre','poser','avancer'])

    def etats(self):
        """
        definit l'ensemble d'etats possibles (pos,orientation,cafe)
        orientation ==> 0 = nord, 1 = est, ....
        """
        etats=[]
        for pos in range(1,4):
            for orientation in range(0,4):
                for cafe in range(0,2):
                    etats+=[(pos,orientation,cafe)]
        return(etats)

    def transition(self,s,a):
        """ definit les consequences d'une action """
        pos=s[0];
        orientation=s[1]
        cafe=s[2];

        # tourner a gauche
        if (a=='tournerG'):
            orientation=(orientation+3)%4;

        #tourner a droite
        if (a=='tournerD'):
            orientation=(orientation+1)%4;

        #prendre le cafe
        if (a=='prendre'):
            if (pos==3):
                cafe=1

        #poser cafe
        if (a=='poser'):
            cafe=0

        # avancer
        if (a=='avancer'):
            #orientation est
            if (orientation==1) and (pos<3):
                pos=pos+1
            if (orientation==3) and (pos>1):
                pos=pos-1

        return(pos,orientation,cafe);


    def recompense(self,s,a,sarr):
        """ definit les recompenses obtenues """
        if (s[0]==1) and (s[2]==1) and (a=='poser'):
            return(100)
        return(-1)

    def afficherEtat(self,s):
        print ("pos:",s[0]," orientation: ",s[1]," cafe:",s[2])


# ##########################################################################
# EXEMPLE
# ##########################################################################
# ##########################################################################

# TEST cafeOrientation
pb = Cafe()
print(pb.etats())
# regarder
s=(1,0,0)
pb.afficherEtat(s)

#liste actions Ã  tester
actions=['avancer','tournerD',"avancer","avancer","avancer","prendre","tournerG","tournerG","avancer","avancer","poser"]

for a in actions:
    s=pb.transition(s,a)
    print (a)
    pb.afficherEtat(s)

