Skip to main content
added 56 characters in body
Source Link
Ajax1234
  • 7.7k
  • 1
  • 15
  • 28

Python3, 928970 bytes:

M=[((1,0),1,3),((0,1),0,2),((-1,0),1,3),((0,-1),0,2)]
def A(c):
 q=[(c[0],i,1,[c[0]])for i,*_ in M]+[(c[0],[(i,2),(M[j][0],1)],0,[c[0]])for i,*J in M for j in J]+[(c[0],[(i,1),(M[j][0],2)],0,[c[0]])for i,*J in M for j in J]
 while q:
  (x,y),m,o,P=q.pop(0)
  if o:
   X,Y=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if T in c[1:3]:yield(1,T)
    elif T in c[-2:]:q+=[([*{*c[-2:]}-{T}][0],m,o,P+[T])]
    else:yield(0,T);q+=[(T,m,o,P+[T])]
  else:
   [(X,Y),C],*I=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if C-1==0 and[]==I:yield(T in c[1:3],T)
    else:
     if T in c[-2:]and C-1:continue
     q+=[([T,[*{*c[-2:]}-{T}][0]][T in c[-2:]],[[[(X,Y),C-1]]+I,I][C-1==0],0,P+[T])]
def f(d):
 S,*c=[(8-int(b),ord(a)-97)for a,b in d]
 q,s=[S],[S]
 while q:
  S=q.pop(0)
  for x,y in A([S]+c):
   q+=[y]
   if x==0:
    k=[[],[]]
    for X,Y in A([y]+c):k[X]+=[Y]
    if{*k[1]}=={*([1]+c)[1:3]}:return chr(97+y[1])+str(8-y[0])

Try it online!Try it online!

Python3, 928 bytes:

M=[((1,0),1,3),((0,1),0,2),((-1,0),1,3),((0,-1),0,2)]
def A(c):
 q=[(c[0],i,1,[c[0]])for i,*_ in M]+[(c[0],[(i,2),(M[j][0],1)],0,[c[0]])for i,*J in M for j in J]+[(c[0],[(i,1),(M[j][0],2)],0,[c[0]])for i,*J in M for j in J]
 while q:
  (x,y),m,o,P=q.pop(0)
  if o:
   X,Y=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if T in c[1:3]:yield(1,T)
    elif T in c[-2:]:q+=[([*{*c[-2:]}-{T}][0],m,o,P+[T])]
    else:yield(0,T);q+=[(T,m,o,P+[T])]
  else:
   [(X,Y),C],*I=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if C-1==0 and[]==I:yield(T in c[1:3],T)
    else:q+=[([T,[*{*c[-2:]}-{T}][0]][T in c[-2:]],[[[(X,Y),C-1]]+I,I][C-1==0],0,P+[T])]
def f(d):
 S,*c=[(8-int(b),ord(a)-97)for a,b in d]
 q,s=[S],[S]
 while q:
  S=q.pop(0)
  for x,y in A([S]+c):
   q+=[y]
   if x==0:
    k=[[],[]]
    for X,Y in A([y]+c):k[X]+=[Y]
    if{*k[1]}=={*([1]+c)[1:3]}:return chr(97+y[1])+str(8-y[0])

Try it online!

Python3, 970 bytes:

M=[((1,0),1,3),((0,1),0,2),((-1,0),1,3),((0,-1),0,2)]
def A(c):
 q=[(c[0],i,1,[c[0]])for i,*_ in M]+[(c[0],[(i,2),(M[j][0],1)],0,[c[0]])for i,*J in M for j in J]+[(c[0],[(i,1),(M[j][0],2)],0,[c[0]])for i,*J in M for j in J]
 while q:
  (x,y),m,o,P=q.pop(0)
  if o:
   X,Y=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if T in c[1:3]:yield(1,T)
    elif T in c[-2:]:q+=[([*{*c[-2:]}-{T}][0],m,o,P+[T])]
    else:yield(0,T);q+=[(T,m,o,P+[T])]
  else:
   [(X,Y),C],*I=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if C-1==0 and[]==I:yield(T in c[1:3],T)
    else:
     if T in c[-2:]and C-1:continue
     q+=[([T,[*{*c[-2:]}-{T}][0]][T in c[-2:]],[[[(X,Y),C-1]]+I,I][C-1==0],0,P+[T])]
def f(d):
 S,*c=[(8-int(b),ord(a)-97)for a,b in d]
 q,s=[S],[S]
 while q:
  S=q.pop(0)
  for x,y in A([S]+c):
   q+=[y]
   if x==0:
    k=[[],[]]
    for X,Y in A([y]+c):k[X]+=[Y]
    if{*k[1]}=={*([1]+c)[1:3]}:return chr(97+y[1])+str(8-y[0])

Try it online!

Source Link
Ajax1234
  • 7.7k
  • 1
  • 15
  • 28

Python3, 928 bytes:

M=[((1,0),1,3),((0,1),0,2),((-1,0),1,3),((0,-1),0,2)]
def A(c):
 q=[(c[0],i,1,[c[0]])for i,*_ in M]+[(c[0],[(i,2),(M[j][0],1)],0,[c[0]])for i,*J in M for j in J]+[(c[0],[(i,1),(M[j][0],2)],0,[c[0]])for i,*J in M for j in J]
 while q:
  (x,y),m,o,P=q.pop(0)
  if o:
   X,Y=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if T in c[1:3]:yield(1,T)
    elif T in c[-2:]:q+=[([*{*c[-2:]}-{T}][0],m,o,P+[T])]
    else:yield(0,T);q+=[(T,m,o,P+[T])]
  else:
   [(X,Y),C],*I=m
   if 0<=x+X<8 and 0<=y+Y<8:
    if(T:=(x+X,y+Y))in P:continue
    if C-1==0 and[]==I:yield(T in c[1:3],T)
    else:q+=[([T,[*{*c[-2:]}-{T}][0]][T in c[-2:]],[[[(X,Y),C-1]]+I,I][C-1==0],0,P+[T])]
def f(d):
 S,*c=[(8-int(b),ord(a)-97)for a,b in d]
 q,s=[S],[S]
 while q:
  S=q.pop(0)
  for x,y in A([S]+c):
   q+=[y]
   if x==0:
    k=[[],[]]
    for X,Y in A([y]+c):k[X]+=[Y]
    if{*k[1]}=={*([1]+c)[1:3]}:return chr(97+y[1])+str(8-y[0])

Try it online!