FAILURE MAP
← Case archive

FA-82696 / Chess move legality / Open access

Rook destination occupancy ignored · case 01

King g1, rook h1 castles kingside with a bishop on f1.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Only the king's path is required to be empty.

VERIFIED REPAIR

The emptiness span covers king and rook starts and destinations.

Unsuccessful approach: Including the rook start but not its destination still misses f1.

Case contract

Input: {"board", "side", "wing", "king_from", "rook_from"}; rights are assumed held. Chess960 castling: the king ends on g (kingside) or c (queenside) and the rook on f or d; the kingside rook must be on the king's h-side and the queenside rook on its a-side. Every square from the leftmost to the rightmost of king start, king end, rook start and rook end must be empty apart from the castling king and rook, and no square the king stands on or passes through (start to end inclusive) may be attacked.

Why this case matters

Chess960 castling generalizes standard rules; standard-chess shortcuts break it.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False
    
    b=x['board']; white=x['side']=='w'; rank='1' if white else '8'
    kf=ord(x['king_from'][0])-97; rf=ord(x['rook_from'][0])-97
    if b.get(x['king_from'])!=('K' if white else 'k') or b.get(x['rook_from'])!=('R' if white else 'r'): return False
    if x['wing']=='K':
        if rf<kf: return False
        kd,rd=6,5
    else:
        if rf>kf: return False
        kd,rd=2,3
    lo=min(kf,kd); hi=max(kf,kd)
    for f in range(lo,hi+1):
        q=chr(97+f)+rank
        if q in b and f not in (kf,rf): return False
    step=1 if kd>=kf else -1
    for f in range(kf,kd+step,step):
        if attacked(b, chr(97+f)+rank, not white): return False
    return True
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook f1 king e1 kingside',
   {'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
    'king_from': 'e1',
    'rook_from': 'f1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king b1 rook a1 c1 attacked',
   {'board': {'a1': 'R', 'b1': 'K', 'c8': 'r', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   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)
Boundary fixtureActualExpectedOutcome
king b1 rook a1 queensideTrueTruePassed
king b1 rook c1 kingsideTrueTruePassed
king f1 rook h1TrueTruePassed
king g1 rook h1 staysTrueTruePassed
rook destination occupiedTrueFalseFailed
queenside d1 occupiedTrueFalseFailed
rook on wrong sideFalseFalsePassed
king destination attackedFalseFalsePassed

SHA-256 / 47abbd274c45caf04830447c99773b791de89289bb2953191d1dd357bb085ae8

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False
    
    b=x['board']; white=x['side']=='w'; rank='1' if white else '8'
    kf=ord(x['king_from'][0])-97; rf=ord(x['rook_from'][0])-97
    if b.get(x['king_from'])!=('K' if white else 'k') or b.get(x['rook_from'])!=('R' if white else 'r'): return False
    if x['wing']=='K':
        if rf<kf: return False
        kd,rd=6,5
    else:
        if rf>kf: return False
        kd,rd=2,3
    lo=min(kf,kd,rf); hi=max(kf,kd,rf)
    for f in range(lo,hi+1):
        q=chr(97+f)+rank
        if q in b and f not in (kf,rf): return False
    step=1 if kd>=kf else -1
    for f in range(kf,kd+step,step):
        if attacked(b, chr(97+f)+rank, not white): return False
    return True
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook f1 king e1 kingside',
   {'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
    'king_from': 'e1',
    'rook_from': 'f1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king b1 rook a1 c1 attacked',
   {'board': {'a1': 'R', 'b1': 'K', 'c8': 'r', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   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)
Boundary fixtureActualExpectedOutcome
king b1 rook a1 queensideTrueTruePassed
king b1 rook c1 kingsideTrueTruePassed
king f1 rook h1TrueTruePassed
king g1 rook h1 staysTrueTruePassed
rook destination occupiedTrueFalseFailed
queenside d1 occupiedTrueFalseFailed
rook on wrong sideFalseFalsePassed
king destination attackedFalseFalsePassed

SHA-256 / 752746d18bff930baee99ae4bad7fe434c9e1ff802c724712e34de4152f1d4ea

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    def attacked(bd, sq, by_white):
        f,r=ord(sq[0])-97,int(sq[1])-1
        def at(ff,rr):
            return bd.get(chr(97+ff)+str(rr+1)) if 0<=ff<8 and 0<=rr<8 else None
        P,N,B,R,Q,K=('PNBRQK' if by_white else 'pnbrqk')
        pr=r-1 if by_white else r+1
        if at(f-1,pr)==P or at(f+1,pr)==P: return True
        for df,dr in ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)):
            if at(f+df,r+dr)==N: return True
        for df in (-1,0,1):
            for dr in (-1,0,1):
                if (df or dr) and at(f+df,r+dr)==K: return True
        for df,dr,kinds in ((1,0,(R,Q)),(-1,0,(R,Q)),(0,1,(R,Q)),(0,-1,(R,Q)),(1,1,(B,Q)),(1,-1,(B,Q)),(-1,1,(B,Q)),(-1,-1,(B,Q))):
            ff,rr=f+df,r+dr
            while 0<=ff<8 and 0<=rr<8:
                v=at(ff,rr)
                if v:
                    if v in kinds: return True
                    break
                ff+=df; rr+=dr
        return False
    
    b=x['board']; white=x['side']=='w'; rank='1' if white else '8'
    kf=ord(x['king_from'][0])-97; rf=ord(x['rook_from'][0])-97
    if b.get(x['king_from'])!=('K' if white else 'k') or b.get(x['rook_from'])!=('R' if white else 'r'): return False
    if x['wing']=='K':
        if rf<kf: return False
        kd,rd=6,5
    else:
        if rf>kf: return False
        kd,rd=2,3
    lo=min(kf,kd,rf,rd); hi=max(kf,kd,rf,rd)
    for f in range(lo,hi+1):
        q=chr(97+f)+rank
        if q in b and f not in (kf,rf): return False
    step=1 if kd>=kf else -1
    for f in range(kf,kd+step,step):
        if attacked(b, chr(97+f)+rank, not white): return False
    return True
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king destination attacked',
   {'board': {'a8': 'k', 'e1': 'K', 'g8': 'r', 'h1': 'R'},
    'king_from': 'e1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king in check',
   {'board': {'a8': 'k', 'f1': 'K', 'f8': 'r', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('black queenside c8 d8',
   {'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
    'king_from': 'd8',
    'rook_from': 'a8',
    'side': 'b',
    'wing': 'Q'},
   True),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook f1 king e1 kingside',
   {'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
    'king_from': 'e1',
    'rook_from': 'f1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('king b1 rook c1 f1 attacked',
   {'board': {'a8': 'k', 'b1': 'K', 'c1': 'R', 'f8': 'r'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('rook adjacent on a-side kingside',
   {'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king b1 rook a1 c1 attacked',
   {'board': {'a1': 'R', 'b1': 'K', 'c8': 'r', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False)],
 [('king b1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'K', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   True),
  ('king b1 rook c1 kingside',
   {'board': {'b1': 'K', 'c1': 'R', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'c1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king f1 rook h1',
   {'board': {'e8': 'k', 'f1': 'K', 'h1': 'R'},
    'king_from': 'f1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('king g1 rook h1 stays',
   {'board': {'e8': 'k', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   True),
  ('rook destination occupied',
   {'board': {'e8': 'k', 'f1': 'B', 'g1': 'K', 'h1': 'R'},
    'king_from': 'g1',
    'rook_from': 'h1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('queenside d1 occupied',
   {'board': {'a1': 'R', 'b1': 'K', 'd1': 'N', 'e8': 'k'},
    'king_from': 'b1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   False),
  ('rook on wrong side',
   {'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
    'king_from': 'd1',
    'rook_from': 'b1',
    'side': 'w',
    'wing': 'K'},
   False),
  ('king c1 rook a1 queenside',
   {'board': {'a1': 'R', 'b1': 'N', 'c1': 'K', 'e8': 'k'},
    'king_from': 'c1',
    'rook_from': 'a1',
    'side': 'w',
    'wing': 'Q'},
   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)
Boundary fixtureActualExpectedOutcome
king b1 rook a1 queensideTrueTruePassed
king b1 rook c1 kingsideTrueTruePassed
king f1 rook h1TrueTruePassed
king g1 rook h1 staysTrueTruePassed
rook destination occupiedFalseFalsePassed
queenside d1 occupiedFalseFalsePassed
rook on wrong sideFalseFalsePassed
king destination attackedFalseFalsePassed

SHA-256 / 7e9811f6fdbd41de2a99ece465fa9f474641585225bf73711c1519de82985055

Verification & scope

A deterministic toy model with an explicitly stated contract; boards are {square: piece} with white upper-case and black lower-case pieces; no claim of full FIDE Laws conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:50:14.625888+00:00.

Case digest / 031427e118dfe1da6241135f689c089cca983483fd01a38b9697df7b2307d2e3