def next(state,radeau): l,d,s = state l2 = l+radeau[0]*(1-2*s) d2 = d+radeau[1]*(1-2*s) s2 = 1-s if l2<0 or d2<0 or l2>3 or d2>3: return state if l2>0 and d2>l2: return state if l2<3 and d2