broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False)],
 [('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); nb[to]=nb.pop(fr) if not occ else k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False)],
 [('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A king on e4 checked by a rook on e8 may step back to e3.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if abs(df)+abs(dr)!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if abs(df)+abs(dr) not in (1,2): return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A king cannot step from e4 to f5.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()!=white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.lower()=='k': return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The king may move onto its own pawn but not capture an undefended enemy pawn.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if df and dr and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and abs(df)+abs(dr)==1 and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A white king may step to e5 directly below the black king on e6.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()!=white: return True
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.lower()!='p' and occ.isupper()!=white: return True
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The king takes a pawn on e5 that is protected by another pawn.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False

    b=x['board']; fr,to=x['from'],x['to']; k=b[fr]; white=k=='K'
    df=ord(to[0])-ord(fr[0]); dr=int(to[1])-int(fr[1])
    if max(abs(df),abs(dr))!=1: return False
    occ=b.get(to)
    if occ and occ.isupper()==white: return False
    nb=dict(b); del nb[fr]; nb[to]=k
    return not attacked(nb, to, not white)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('capture own', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'P'}, 'from': 'e4', 'to': 'e5'}, False),
  ('capture undefended', {'board': {'a8': 'k', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'},
   True),
  ('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('capture defended',
   {'board': {'a8': 'k', 'd6': 'p', 'e4': 'K', 'e5': 'p'}, 'from': 'e4', 'to': 'e5'}, False),
  ('next to enemy king orthogonal', {'board': {'e4': 'K', 'e6': 'k'}, 'from': 'e4', 'to': 'e5'},
   False),
  ('next to enemy king diagonal', {'board': {'e4': 'K', 'g6': 'k'}, 'from': 'e4', 'to': 'f5'},
   False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('black king bishop diag retreat',
   {'board': {'b3': 'B', 'd5': 'k', 'h1': 'K'}, 'from': 'd5', 'to': 'e6'}, False),
  ('capture along check line',
   {'board': {'a1': 'k', 'e3': 'p', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('capture defended knight',
   {'board': {'a8': 'k', 'e4': 'K', 'e5': 'n', 'e7': 'r'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)],
 [('retreat along rook file',
   {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'e3'}, False),
  ('sidestep rook file', {'board': {'a1': 'k', 'e4': 'K', 'e8': 'r'}, 'from': 'e4', 'to': 'd3'},
   True),
  ('diagonal step', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'f5'}, True),
  ('stand still', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e4'}, False),
  ('knight below', {'board': {'a8': 'k', 'e4': 'K', 'f1': 'n'}, 'from': 'e4', 'to': 'e3'}, False),
  ('knight above', {'board': {'a8': 'k', 'd7': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'e5'}, False),
  ('two squares', {'board': {'a8': 'k', 'e4': 'K'}, 'from': 'e4', 'to': 'e6'}, False),
  ('knight far below', {'board': {'a8': 'k', 'c4': 'n', 'e4': 'K'}, 'from': 'e4', 'to': 'd3'},
   True)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The king may step next to a knight that attacks the square from below.

Input: {"board", "from": king square, "to": square}. Return true when the king move is legal: exactly one square in any direction, not onto a friendly piece, and the destination is not attacked by the opponent (including the enemy king) once the king has left its origin square. Captures of undefended enemy pieces are allowed.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    b=x['board']; fr,to=x['from'],x['to']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def c(s): return ord(s[0])-97,int(s[1])-1
    kf,kr=c(ks); pf,pr=c(fr); tf,tr=c(to)
    df,dr=pf-kf,pr-kr
    if not (df==0 or dr==0): return True
    sf=(df>0)-(df<0); sr=(dr>0)-(dr<0)
    cf,cr=kf+sf,kr+sr
    while (cf,cr)!=(pf,pr):
        if chr(97+cf)+str(cr+1) in b: return True
        cf+=sf; cr+=sr
    cf,cr=pf+sf,pr+sr
    while 0<=cf<8 and 0<=cr<8:
        v=b.get(chr(97+cf)+str(cr+1))
        if v:
            kinds=('r','q') if sf==0 or sr==0 else ('b','q')
            if v.isupper()!=white and v.lower() in kinds:
                tdf,tdr=tf-kf,tr-kr
                return tdf*sr==tdr*sf and tdf*sf+tdr*sr>0
            return True
        cf+=sf; cr+=sr
    return True
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('shield next to king diagonal',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'P', 'e3': 'N', 'h6': 'b'}, 'from': 'e3', 'to': 'g4'},
   True),
  ('bishop on file is not a pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'b'}, 'from': 'e4', 'to': 'c5'}, True),
  ('rook on diagonal is not a pinner',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'r'}, 'from': 'd2', 'to': 'f3'}, True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('rook on diagonal is not a pinner',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'r'}, 'from': 'd2', 'to': 'f3'}, True),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False),
  ('not on a line',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'N'}, 'from': 'f3', 'to': 'g5'}, True)],
 [('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    b=x['board']; fr,to=x['from'],x['to']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def c(s): return ord(s[0])-97,int(s[1])-1
    kf,kr=c(ks); pf,pr=c(fr); tf,tr=c(to)
    df,dr=pf-kf,pr-kr
    if not abs(df)==abs(dr): return True
    sf=(df>0)-(df<0); sr=(dr>0)-(dr<0)
    cf,cr=kf+sf,kr+sr
    while (cf,cr)!=(pf,pr):
        if chr(97+cf)+str(cr+1) in b: return True
        cf+=sf; cr+=sr
    cf,cr=pf+sf,pr+sr
    while 0<=cf<8 and 0<=cr<8:
        v=b.get(chr(97+cf)+str(cr+1))
        if v:
            kinds=('r','q') if sf==0 or sr==0 else ('b','q')
            if v.isupper()!=white and v.lower() in kinds:
                tdf,tdr=tf-kf,tr-kr
                return tdf*sr==tdr*sf and tdf*sf+tdr*sr>0
            return True
        cf+=sf; cr+=sr
    return True
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('shield next to king diagonal',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'P', 'e3': 'N', 'h6': 'b'}, 'from': 'e3', 'to': 'g4'},
   True),
  ('bishop on file is not a pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'b'}, 'from': 'e4', 'to': 'c5'}, True),
  ('rook on diagonal is not a pinner',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'r'}, 'from': 'd2', 'to': 'f3'}, True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('rook on diagonal is not a pinner',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'r'}, 'from': 'd2', 'to': 'f3'}, True),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False),
  ('not on a line',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'N'}, 'from': 'f3', 'to': 'g5'}, True)],
 [('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, False),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)],
 [('file-pinned rook slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('file-pinned rook leaves',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'}, False),
  ('capture the pinner',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e8'}, True),
  ('diagonal pinned bishop off line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'c3'}, False),
  ('diagonal pinned bishop on line',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'q'}, 'from': 'd2', 'to': 'e3'}, True),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   True),
  ('black rank pin',
   {'board': {'a1': 'K', 'a8': 'R', 'e8': 'n', 'h8': 'k'}, 'from': 'e8', 'to': 'd6'}, False)]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A knight pinned by a bishop against its king is allowed to jump away.

Input: {"board", "from": square of a non-king piece, "to": its pseudo-legal destination}. Return false only when the piece is absolutely pinned (it is the first piece on a line from its own king and the next piece beyond it on that line is an enemy rook/queen on a rank or file, or bishop/queen on a diagonal) and the destination leaves that line; moves along the pin line, including capturing the pinner, return true.

split: open-access