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 or 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: break
        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),
  ('shield next to king diagonal',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'P', 'e3': 'N', 'h6': 'b'}, 'from': 'e3', 'to': 'g4'},
   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),
  ('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)],
 [('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),
  ('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),
  ('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),
  ('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),
  ('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)]]
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 (df==0 or dr==0 or 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 and (cf,cr)!=(kf+sf,kr+sr): 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),
  ('shield next to king diagonal',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'P', 'e3': 'N', 'h6': 'b'}, 'from': 'e3', 'to': 'g4'},
   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),
  ('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)],
 [('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),
  ('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),
  ('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),
  ('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),
  ('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)]]
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 rook with a pawn between it and the king cannot leave the file.

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


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 or 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','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),
  ('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)],
 [('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, 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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True)],
 [('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 to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('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),
  ('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),
  ('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 to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('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 slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('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),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   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)]]
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):
    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 or 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=('b','q') if sf==0 or sr==0 else ('r','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),
  ('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)],
 [('diagonal pin knight',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'N', 'g5': 'b'}, 'from': 'd2', 'to': 'f3'}, 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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True)],
 [('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 to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('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),
  ('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),
  ('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 to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('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 slides',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'e6'}, True),
  ('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),
  ('shield between king and piece',
   {'board': {'a8': 'k', 'e1': 'K', 'e2': 'P', 'e4': 'R', 'e8': 'r'}, 'from': 'e4', 'to': 'a4'},
   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)]]
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 between its king and an enemy bishop on the same file may not move.

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


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 or 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==0 or tdr==0 or abs(tdf)==abs(tdr)
            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),
  ('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)],
 [('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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True)],
 [('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 (df==0 or dr==0 or 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*sf>=0 and 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),
  ('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)],
 [('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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True)],
 [('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 bishop pinned on the c1-g5 diagonal may move to c3 or e1.

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


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 or 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.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),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, 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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, 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),
  ('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),
  ('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),
  ('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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True),
  ('not on a line',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'N'}, 'from': 'f3', 'to': 'g5'}, 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):
    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 or 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 or v.lower()=='q') 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),
  ('diagonal pinned bishop to e1',
   {'board': {'a8': 'k', 'c1': 'K', 'd2': 'B', 'g5': 'b'}, 'from': 'd2', 'to': 'e1'}, False),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, 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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, 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),
  ('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),
  ('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),
  ('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),
  ('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),
  ('own queen behind',
   {'board': {'a8': 'k', 'e1': 'K', 'e4': 'N', 'e8': 'Q'}, 'from': 'e4', 'to': 'c5'}, True),
  ('not on a line',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'N'}, 'from': 'f3', 'to': 'g5'}, 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 knight between its king and its own queen may not move.

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


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

N = 1
observations = []
def solve(x):
    b=x['board']; fr,to=x['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>2: return False
    if not checkers: return True
    c=checkers[0]
    if to==c: return True
    if b[c].lower() in ('n','p'): return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True)],
 [('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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):
    b=x['board']; fr,to=x['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>=2 and to not in checkers: return False
    if not checkers: return True
    c=checkers[0]
    if to==c: return True
    if b[c].lower() in ('n','p'): return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True)],
 [('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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:
With rook and knight both giving check, a queen interposition is accepted.

Input: {"board", "move": [from, to]} for a non-king piece whose king may be in check (pins are ignored). Return true if the move is allowed by the check rules: no check means true; double check means false; a single check is answered by capturing the checker or, for a rook, bishop or queen checker, by moving onto a square strictly between it and the king.

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['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>=2: return False
    if not checkers: return True
    c=checkers[0]
    pass
    if b[c].lower() in ('n','p'): return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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):
    b=x['board']; fr,to=x['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>=2: return False
    if not checkers: return True
    c=checkers[0]
    if to==c and b[c].lower() in ('n','p'): return True
    if b[c].lower() in ('n','p'): return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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 rook capturing the checking rook is rejected.

Input: {"board", "move": [from, to]} for a non-king piece whose king may be in check (pins are ignored). Return true if the move is allowed by the check rules: no check means true; double check means false; a single check is answered by capturing the checker or, for a rook, bishop or queen checker, by moving onto a square strictly between it and the king.

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['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>=2: return False
    if not checkers: return True
    c=checkers[0]
    if to==c: return True
    if b[c].lower()=='p': return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False)],
 [('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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):
    b=x['board']; fr,to=x['move']; p=b[fr]; white=p.isupper()
    ks=[s for s,v in b.items() if v==('K' if white else 'k')][0]
    def at(f,r): return b.get(chr(97+f)+str(r+1)) if 0<=f<8 and 0<=r<8 else None
    def sq(f,r): return chr(97+f)+str(r+1)
    def attackers(s, by_white):
        f,r=ord(s[0])-97,int(s[1])-1
        P,N,B,R,Q=('PNBRQ' if by_white else 'pnbrq')
        out=[]
        pr=r-1 if by_white else r+1
        for df in (-1,1):
            if at(f+df,pr)==P: out.append(sq(f+df,pr))
        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: out.append(sq(f+df,r+dr))
        for df,dr in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)):
            kinds=(R,Q) if df==0 or dr==0 else (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: out.append(sq(ff,rr))
                    break
                ff+=df; rr+=dr
        return out
    checkers=attackers(ks, not white)
    if len(checkers)>=2: return False
    if not checkers: return True
    c=checkers[0]
    if to==c: return True
    if b[c] in ('n','p'): return False
    cf,cr=ord(c[0])-97,int(c[1])-1
    kf,kr=ord(ks[0])-97,int(ks[1])-1
    sf=(cf>kf)-(cf<kf); sr=(cr>kr)-(cr<kr)
    f,r=kf+sf,kr+sr
    between=[]
    while (f,r)!=(cf,cr) and 0<=f<8 and 0<=r<8:
        between.append(sq(f,r)); f+=sf; r+=sr
    return to in between
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False)],
 [('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('cannot block knight',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'f3': 'n'}, 'move': ['d1', 'e2']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False)],
 [('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('double check block',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r', 'f3': 'n'}, 'move': ['d1', 'e2']},
   False),
  ('double check capture one',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']},
   False),
  ('diagonal interpose',
   {'board': {'a5': 'b', 'c1': 'N', 'e1': 'K', 'h8': 'k'}, 'move': ['c1', 'b3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('diagonal interpose d2',
   {'board': {'a5': 'b', 'e1': 'K', 'f3': 'N', 'h8': 'k'}, 'move': ['f3', 'd2']}, True),
  ('black blocks white queen',
   {'board': {'a1': 'K', 'c6': 'n', 'e1': 'Q', 'e8': 'k'}, 'move': ['c6', 'e7']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('irrelevant move in check',
   {'board': {'a2': 'P', 'a8': 'k', 'e1': 'K', 'e8': 'r'}, 'move': ['a2', 'a3']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, True)],
 [('no check', {'board': {'b1': 'N', 'e1': 'K', 'e8': 'k'}, 'move': ['b1', 'c3']}, True),
  ('block rook check',
   {'board': {'a8': 'k', 'b1': 'N', 'e1': 'K', 'e8': 'r'}, 'move': ['b1', 'c3']}, False),
  ('interpose on file',
   {'board': {'a8': 'k', 'd1': 'Q', 'e1': 'K', 'e8': 'r'}, 'move': ['d1', 'e2']}, True),
  ('capture rook checker',
   {'board': {'a8': 'k', 'e1': 'K', 'e8': 'r', 'h8': 'R'}, 'move': ['h8', 'e8']}, True),
  ('knight check sidestep piece',
   {'board': {'a8': 'k', 'b2': 'B', 'd3': 'n', 'e1': 'K'}, 'move': ['b2', 'c3']}, False),
  ('bishop takes knight checker',
   {'board': {'a8': 'k', 'e1': 'K', 'f3': 'n', 'g2': 'B'}, 'move': ['g2', 'f3']}, True),
  ('black cannot block white knight',
   {'board': {'a1': 'K', 'c8': 'b', 'd6': 'N', 'e8': 'k'}, 'move': ['c8', 'd7']}, False),
  ('rank check interpose',
   {'board': {'a1': 'K', 'a8': 'k', 'b3': 'N', 'h1': 'q'}, 'move': ['b3', 'c1']}, 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 queen move to a square between king and a checking knight is accepted.

Input: {"board", "move": [from, to]} for a non-king piece whose king may be in check (pins are ignored). Return true if the move is allowed by the check rules: no check means true; double check means false; a single check is answered by capturing the checker or, for a rook, bishop or queen checker, by moving onto a square strictly between it and the king.

split: open-access