def _name(state):
    """Makes a unique string for a given state"""
    (x, y), d, c = state
    a = ('X%d' if d & 1 else 'x%d') % x
    b = ('Y%d' if d & 2 else 'y%d') % y
    return b + a if c else a + b
