JavaScript (Node.js), 483483 426 bytes
-57 bytes thanks to @emanresu A
Takes a list of strings as input and indexes from 0.
s=a=>a=>{a=a.map(p=>pp=>[.split("")..p]);e=[];t=[];o=[];i=0;g=a.length;m=n=>(n%g+g)%g;r=_=>[...a.keys()].filter(x=>!d(x));d=x=>o.includes(x);q=_=>JSON.stringify([o,i,a,e]);for(;;){if(!d(i)){t.push(q&&());l=el=e.length==e.unshift(a[i].shift(t.push(q()))||e.pop());if(e[0]==e[1]&&e[1]){e&&!a.reversefilter(p=>p[0]);a[i][0],(e[0]==e[1]&&e[1]&&(i=m(i-1,a[i].push(...e);i=m.reverse(i-1);e=[];o)),e=[],o.push(...a.mapflatMap((p,j)=>p.length||d=>p[0]||d(j)?-1e:j).filter(x=>x>=0));if(o.length+1==g+1==g)return r(||l)}else if(l&&!a.filter(p=>p.length).length)return l?r()}i=m:r(i+1);if[0];if(t.includes(q(i=m(i+1))))return r()}} s = (a) => { a = a.map((p) => p[.split("")..p]); e = []; t = []; o = []; i = 0; g = a.length; m = (n) => ((n % g) + g) % g; r = (_) => [...a.keys()].filter((x) => !d(x)); d = (x) => o.includes(x); q = (_) => JSON.stringify([o, i, a, e]); for (;;) { if (!d(i)) { t.push(q!d()i); && ((l = e.length == e.unshift(a[i].shift(t.push(q())) || e.pop()); if&& !a.filter(e[0] == e[1](p) &&=> e[1]p[0]) {[0]), e.reverse(); e[0] == e[1] && e[1] && ((i = m(i - 1, a[i].push(...e); i = m.reverse(i - 1); ))), (e = []; []), o.push(...a.mapflatMap((p, j) => (p.lengthp[0] || d(j) ? -1e : j)).filter((x) =>+ x1 >=== 0g)); || l) if (o.length + 1 == g) return r(); } else ifreturn (l &&? !a.filter(r(p) => p.length).length) return: r();[0]; } if (t.includes(q((i = m(i + 1); if (t.includes(q()))) return r(); } };