示例#1
0
 def printE(self,environment):
     for i in environment:
         for j in i:
             if type(j) is Yard:
                 print(Yard().symbol,end=" ")
             elif type(j) is Empty:
                 print(Empty().symbol,end=" ")
             elif type(j) is Robot:
                 print(Robot().symbol,end=" ")
             elif type(j) is Dirtiness:
                 print(Dirtiness().symbol,end=" ")
             elif type(j) is Obstacle:
                 print(Obstacle().symbol,end=" ")
             elif type(j) is Children:
                 print(Children().symbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Yard and len(j) == 2:
                 if type(j[1]) is Children:
                     print(Yard().childrenSymbol,end=" ")
                 else:
                     print(Yard().robotSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Yard and len(j) > 2:
                 print(Yard().childrenSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Robot:
                 print(Robot().childrenSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Dirtiness:
                 print(Robot().dirtinessSymbol,end=" ")
             else:
                 print('!')
         print()
     print('next turn')
示例#2
0
 def movWithoutChildren(self,environment,posRobot):
     possibleMoves = self.getPossibleMoves(environment,posRobot[0],posRobot[1],len(environment),len(environment[0]))
     if len(possibleMoves) > 0:
         if type(environment[posRobot[0]][posRobot[1]]) is tuple and len(environment[posRobot[0]][posRobot[1]]) > 2 and type(environment[posRobot[0]][posRobot[1]][1]) is Robot:
             environment[posRobot[0]][posRobot[1]] = (Yard(),Children(),self)
         elif not (self.typeCheck(possibleMoves,Children,environment) == (-1,-1)):
             pos = self.typeCheck(possibleMoves,Children,environment)
             environment[pos[0]][pos[1]] = (self,environment[pos[0]][pos[1]])
             if type(environment[posRobot[0]][posRobot[1]]) is Robot:
                 environment[posRobot[0]][posRobot[1]] = Empty()
             elif type(environment[posRobot[0]][posRobot[1]]) is tuple:
                 if type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                     environment[posRobot[0]][posRobot[1]] = Dirtiness()
                 elif len(environment[posRobot[0]][posRobot[1]]) > 2:
                     environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                 else:
                     environment[posRobot[0]][posRobot[1]] = Yard()
         elif not (self.typeCheck(possibleMoves,Dirtiness,environment) == (-1,-1)):
             if type(environment[posRobot[0]][posRobot[1]]) is tuple and type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                 environment[posRobot[0]][posRobot[1]] = self
             else:
                 pos = self.typeCheck(possibleMoves,Dirtiness,environment)
                 environment[pos[0]][pos[1]] = (environment[pos[0]][pos[1]],self)
                 if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                     if len(environment[posRobot[0]][posRobot[1]]) > 2:
                         environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                     else:
                         environment[posRobot[0]][posRobot[1]] = Yard()
                 else:
                     environment[posRobot[0]][posRobot[1]] = Empty()
         else:
             if type(environment[posRobot[0]][posRobot[1]]) is tuple and type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                     environment[posRobot[0]][posRobot[1]] = self
             else:
                 pos = self.chosePosition(self.getChildrenPosition(environment),possibleMoves)
                 if pos[0] == 1000000:
                     pos = self.chosePosition(self.getDirtinessPosition(environment),possibleMoves)
                 if pos[0] == 1000000:
                     return
                 if type(environment[pos[0]][pos[1]]) is Empty:
                     environment[pos[0]][pos[1]] = self
                     if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                         if len(environment[posRobot[0]][posRobot[1]]) > 2:
                             environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                         else:
                             environment[posRobot[0]][posRobot[1]] = Yard()
                     else:
                         environment[posRobot[0]][posRobot[1]] = Empty()
                 else:
                     environment[pos[0]][pos[1]] = (Yard(),self)
                     if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                         if len(environment[posRobot[0]][posRobot[1]]) > 2:
                             environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                         else:
                             environment[posRobot[0]][posRobot[1]] = Yard()
                     else:
                         environment[posRobot[0]][posRobot[1]] = Empty()
示例#3
0
    def movWithChildren2(self,environment,posRobot):
        boolean = True
        possible = self.getPossibleMoves(environment,posRobot[0],posRobot[1],len(environment),len(environment[0]))
        possibleMoves = []
        for i in possible:
            if not (type(environment[i[0]][i[1]]) is Children):
                possibleMoves.append(i)
        yardPosition = self.getYardPosition(environment)
        # print(posRobot)
        # print(environment[posRobot[0]][posRobot[1]])
        # print(possibleMoves)
        pos = self.chosePosition(yardPosition,possibleMoves)
        if pos[0] == 1000000:
            return (pos,False)
        # print(pos)
        # print(environment[pos[0]][pos[1]])
        if type(environment[pos[0]][pos[1]]) is Dirtiness:
            environment[pos[0]][pos[1]] = (self,Children(),Dirtiness())
        elif type(environment[pos[0]][pos[1]]) is Empty:
            environment[pos[0]][pos[1]] = (self,Children())
        elif type(environment[pos[0]][pos[1]]) is Yard:
            environment[pos[0]][pos[1]] = (Yard(),self,Children)
            boolean = False

        if len(environment[posRobot[0]][posRobot[1]]) == 2 and type(environment[posRobot[0]][posRobot[1]][0]) is Robot:
            environment[posRobot[0]][posRobot[1]] = Empty()
        else:
            environment[posRobot[0]][posRobot[1]] = Dirtiness()
        
        return (pos,boolean)