def lookToSide(self,desc,side,recFn):
     try: tmpVC = self.rotate(side)
     except KeyError: raise ValueError('Unknown side %r', side)
     if tmpVC[0] == observation([tuple([Unknown]*6)]): return False
     tmpDesc = copy.deepcopy(desc)
     tmpDesc.side = [desc.value.ViewPosition]
     return recFn(tmpDesc,tmpVC)
Exemple #2
0
 def lookToSide(self, desc, side, recFn):
     try:
         tmpVC = self.rotate(side)
     except KeyError:
         raise ValueError('Unknown side %r', side)
     if tmpVC[0] == observation([tuple([Unknown] * 6)]): return False
     tmpDesc = copy.deepcopy(desc)
     tmpDesc.side = [desc.value.ViewPosition]
     return recFn(tmpDesc, tmpVC)
Exemple #3
0
    def update(self, direction, obs):
        obs = observation(obs)
        if direction == Left:
            # Rotate off right side, replace former leftmost
            self._cache = [obs] + self._cache[0:self._len - 1]
        elif direction == Right:
            # Rotate off left side, replace former rightmost
            self._cache = [obs] + self._cache[2:self._len] + [self._cache[0]]
        elif direction == Front:
            oldL, oldM, oldR, oldFL, oldP, oldFR = self._cache[0].view[0]
            l, m, r, fl, p, fr = obs[0].view[0]
            if r == Wall: FL = FR = End
            else: FL = FR = Unknown
            rightV = [(p, m, oldP, FL, r, FR)]
            backV = [(r, m, l, oldFR, oldP, oldFL)] + self._cache[-2].view[:]
            if l == Wall: FL = FR = End
            else: FL = FR = Unknown
            leftV = [(oldP, m, p, FL, l, FR)]
            self._cache = [
                obs,
                observation(rightV),
                observation(backV),
                observation(leftV)
            ]
        elif direction == At:
            oldL, oldM, oldR, oldFL, oldP, oldFR = self._cache[0].view[0]
            l, m, r, fl, p, fr = obs[0].view[0]

            R_oldL, R_oldM, R_oldR, R_oldFL, R_oldP, R_oldFR = self._cache[
                1].view[0]
            if r == Wall:
                R_oldFL = R_oldFR = End
            rightV = [(p, m, R_oldP, R_oldFL, r, R_oldFR)
                      ] + self._cache[1].view[1:]

            B_oldL, B_oldM, B_oldR, B_oldFL, B_oldP, B_oldFR = self._cache[
                -2].view[0]
            backV = [(r, m, l, B_oldFR, B_oldP, B_oldFL)
                     ] + self._cache[-2].view[1:]

            L_oldL, L_oldM, L_oldR, L_oldFL, L_oldP, L_oldFR = self._cache[
                -1].view[0]
            if l == Wall:
                L_oldFL = L_oldFR = End
            leftV = [(p, m, L_oldP, L_oldFL, l, L_oldFR)
                     ] + self._cache[-1].view[1:]

            self._cache = [
                obs,
                observation(rightV),
                observation(backV),
                observation(leftV)
            ]
        else:
            raise ValueError('Unknown turn direction %r', direction)
 def reset(self,obs=None,cache=None):
     if cache:
         self._cache = cache
         self._len = len(cache)
     elif obs:
         l,m,r,fl,p,fr = obs[0]
         if r == Wall: FL = FR = End
         else:  FL = FR = Unknown
         rightV = [(p,m,Unknown,FL,r,FR)]
         reverseV = [(r,m,l,Unknown,Unknown,Unknown)]
         if l == Wall: FL = FR = End
         else:  FL = FR = Unknown
         leftV = [(Unknown,m,p,FL,l,FR)]
         self._cache = [obs, rightV, reverseV, leftV]
     else:
         self._cache = [[tuple([Unknown]*6)]] * self._len
     self._cache = [observation(v) for v in self._cache]
Exemple #5
0
 def reset(self, obs=None, cache=None):
     if cache:
         self._cache = cache
         self._len = len(cache)
     elif obs:
         l, m, r, fl, p, fr = obs[0]
         if r == Wall: FL = FR = End
         else: FL = FR = Unknown
         rightV = [(p, m, Unknown, FL, r, FR)]
         reverseV = [(r, m, l, Unknown, Unknown, Unknown)]
         if l == Wall: FL = FR = End
         else: FL = FR = Unknown
         leftV = [(Unknown, m, p, FL, l, FR)]
         self._cache = [obs, rightV, reverseV, leftV]
     else:
         self._cache = [[tuple([Unknown] * 6)]] * self._len
     self._cache = [observation(v) for v in self._cache]
 def update(self,direction,obs):
     obs = observation(obs)
     if direction == Left:
         # Rotate off right side, replace former leftmost
         self._cache = [obs] + self._cache[0:self._len-1]
     elif direction == Right:
         # Rotate off left side, replace former rightmost
         self._cache = [obs]+ self._cache[2:self._len] + [self._cache[0]]
     elif direction == Front:
         oldL,oldM,oldR,oldFL,oldP,oldFR = self._cache[0].view[0]
         l,m,r,fl,p,fr = obs[0].view[0]
         if r == Wall: FL = FR = End
         else: FL = FR = Unknown
         rightV = [(p,m,oldP,FL,r,FR)]
         backV = [(r,m,l,oldFR,oldP,oldFL)] + self._cache[-2].view[:]
         if l == Wall: FL = FR = End
         else: FL = FR = Unknown
         leftV = [(oldP,m,p,FL,l,FR)]
         self._cache = [obs, observation(rightV), observation(backV), observation(leftV)]
     elif direction == At:
         oldL,oldM,oldR,oldFL,oldP,oldFR = self._cache[0].view[0]
         l,m,r,fl,p,fr = obs[0].view[0]
         
         R_oldL,R_oldM,R_oldR,R_oldFL,R_oldP,R_oldFR = self._cache[1].view[0]
         if r == Wall:
             R_oldFL = R_oldFR = End
         rightV = [(p,m,R_oldP,R_oldFL,r,R_oldFR)] + self._cache[1].view[1:]
         
         B_oldL, B_oldM, B_oldR, B_oldFL, B_oldP, B_oldFR = self._cache[-2].view[0]
         backV = [(r,m,l,B_oldFR,B_oldP,B_oldFL)] + self._cache[-2].view[1:]
         
         L_oldL,L_oldM,L_oldR,L_oldFL,L_oldP,L_oldFR = self._cache[-1].view[0]
         if l == Wall:
             L_oldFL = L_oldFR = End
         leftV = [(p,m,L_oldP,L_oldFL,l,L_oldFR)] + self._cache[-1].view[1:]
         
         self._cache = [obs, observation(rightV), observation(backV), observation(leftV)]
     else: raise ValueError('Unknown turn direction %r', direction)