def convert(cls, obs, back, forward=1):
     """
     >>> for obs,back,name in ((observation([(Wall, Empty, Honeycomb, End, Wall, End)]),Wall, 'Dead End'),
     ...      (observation([(Wall, Hatrack, Wall, Fish, Wood, Fish)]),Wood, 'No Topological Place'),
     ...      (observation([(Wall, Empty, Cement, Butterfly, Brick, Butterfly)]),Wall, 'Corner'),
     ...      (observation([(BlueTile, Empty, Wall, Eiffel, Cement, Eiffel)]),Cement, 'T'),
     ...      (observation([(Grass, Empty, Grass, Eiffel, Brick, Eiffel)]),Brick, '4-way Intersection')):
     ...      sss = SmallScaleStar.convert(obs,back)
     ...      print name,'Gateways:',sss.countGateways(),'PathFragments:',sss.countPathFragments()
     ...      print sss
     ...
     Dead End Gateways: 1 PathFragments: 1
     SmallScaleStar(gateways=[gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') )], path_fragments=[0], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(Wall, 1, True) ), small_scale_star_tuple( *(0, 0, False) ), small_scale_star_tuple( *(Wall, 1, False) )], forward=2 )
     No Topological Place Gateways: 2 PathFragments: 1
     SmallScaleStar(gateways=[gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[1], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(0, 1, True) ), small_scale_star_tuple( *(Wall, 0, False) ), small_scale_star_tuple( *(1, 1, False) )], forward=None )
     Corner Gateways: 2 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(0, 1, True) ), small_scale_star_tuple( *(1, 0, False) ), small_scale_star_tuple( *(Wall, 1, False) )], forward=2 )
     T Gateways: 3 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(-1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(0, 0, True) ), small_scale_star_tuple( *(1, 1, True) ), small_scale_star_tuple( *(Wall, 0, False) ), small_scale_star_tuple( *(2, 1, False) )], forward=2 )
     4-way Intersection Gateways: 4 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(-1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(0, 0, True) ), small_scale_star_tuple( *(1, 1, True) ), small_scale_star_tuple( *(2, 0, False) ), small_scale_star_tuple( *(3, 1, False) )], forward=2 )
     """
     if isinstance(obs, POMDP.MarkovLoc_Antie.observation):
         left, at, right, front_left, front, front_right = obs.view[0]
         gateways = []
         table = []
         for side, coords, path, dir in zip(
             (left, front, right, back),
             ((-1, 0), (0, 1), (1, 0), (0, -1)),  #Canonical positions
             (0, 1, 0, 1),
             (True, True, False, False)):
             if side.match(Flooring):
                 gateways.append(coords)
                 gateway_index = len(gateways) - 1
             else:
                 gateway_index = side
             table.append((gateway_index, path, dir))
         return cls(
             gateways=gateways,
             table=table,
             forward=forward,
             path_fragments=uniq(
                 [ssst[1] for ssst in table if ssst[0] != Wall]),
         )
     else:
         raise ValueError, 'Cannot convert %r to ' + cls.__name__ % (obs)
 def convert(cls,obs,back,forward=1):
     """
     >>> for obs,back,name in ((observation([(Wall, Empty, Honeycomb, End, Wall, End)]),Wall, 'Dead End'),
     ...      (observation([(Wall, Hatrack, Wall, Fish, Wood, Fish)]),Wood, 'No Topological Place'),
     ...      (observation([(Wall, Empty, Cement, Butterfly, Brick, Butterfly)]),Wall, 'Corner'),
     ...      (observation([(BlueTile, Empty, Wall, Eiffel, Cement, Eiffel)]),Cement, 'T'),
     ...      (observation([(Grass, Empty, Grass, Eiffel, Brick, Eiffel)]),Brick, '4-way Intersection')):
     ...      sss = SmallScaleStar.convert(obs,back)
     ...      print name,'Gateways:',sss.countGateways(),'PathFragments:',sss.countPathFragments()
     ...      print sss
     ...
     Dead End Gateways: 1 PathFragments: 1
     SmallScaleStar(gateways=[gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') )], path_fragments=[0], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(Wall, 1, True) ), small_scale_star_tuple( *(0, 0, False) ), small_scale_star_tuple( *(Wall, 1, False) )], forward=2 )
     No Topological Place Gateways: 2 PathFragments: 1
     SmallScaleStar(gateways=[gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[1], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(0, 1, True) ), small_scale_star_tuple( *(Wall, 0, False) ), small_scale_star_tuple( *(1, 1, False) )], forward=None )
     Corner Gateways: 2 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(Wall, 0, True) ), small_scale_star_tuple( *(0, 1, True) ), small_scale_star_tuple( *(1, 0, False) ), small_scale_star_tuple( *(Wall, 1, False) )], forward=2 )
     T Gateways: 3 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(-1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(0, 0, True) ), small_scale_star_tuple( *(1, 1, True) ), small_scale_star_tuple( *(Wall, 0, False) ), small_scale_star_tuple( *(2, 1, False) )], forward=2 )
     4-way Intersection Gateways: 4 PathFragments: 2
     SmallScaleStar(gateways=[gateway_type( *(-1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, 1, 0, 0.0, 'TwoWalled') ), gateway_type( *(1, 0, 0, 0.0, 'TwoWalled') ), gateway_type( *(0, -1, 0, 0.0, 'TwoWalled') )], path_fragments=[0, 1], table=[small_scale_star_tuple( *(0, 0, True) ), small_scale_star_tuple( *(1, 1, True) ), small_scale_star_tuple( *(2, 0, False) ), small_scale_star_tuple( *(3, 1, False) )], forward=2 )
     """
     if isinstance(obs,POMDP.MarkovLoc_Antie.observation):
         left,at,right,front_left,front,front_right = obs.view[0]
         gateways = []
         table = []
         for side,coords,path,dir in zip((left,front,right,back),
                                         ((-1,0),(0,1),(1,0),(0,-1)), #Canonical positions
                                         (0,1,0,1),
                                         (True,True,False,False)):
             if side.match(Flooring):
                 gateways.append(coords)
                 gateway_index = len(gateways)-1
             else:
                 gateway_index = side
             table.append((gateway_index,path,dir))
         return cls(gateways=gateways, table=table, forward=forward,
                    path_fragments=uniq([ssst[1] for ssst in table if ssst[0] != Wall]), )
     else: raise ValueError, 'Cannot convert %r to '+cls.__name__ % (obs)
 def countGateways(self):
     return len(
         uniq([
             ssst.gateway_index for ssst in self.table if ssst.match(Path)
         ]))
 def countGateways(self):
     return len(uniq([ssst.gateway_index for ssst in self.table if ssst.match(Path)]))