FA-82691 / Chess move legality / Open access
Castling rook blocks its own king · case 01
King b1 with rook c1 cannot castle kingside because the king must pass the rook's square.
ROOT CAUSE
Only the king is exempted from the emptiness check, so the castling rook counts as an obstacle.
VERIFIED REPAIR
Exempt both the castling king and the castling rook.
Unsuccessful approach: Exempting only the rook makes the king's own start square an obstacle.
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,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!=kf: 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),
('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),
('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 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 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),
('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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
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 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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
True),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'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 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),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'side': 'w',
'wing': 'K'},
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| king b1 rook a1 queenside | False | True | Failed |
| king b1 rook c1 kingside | False | True | Failed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | False | False | Passed |
| king destination attacked | False | False | Passed |
| king in check | False | False | Passed |
| king c1 rook a1 queenside | False | False | Passed |
SHA-256 / 424483862174290e0550315856db9281fa2efbaa98918b834dd54c12a33fa526
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,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!=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),
('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),
('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 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 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),
('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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
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 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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
True),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'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 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),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'side': 'w',
'wing': 'K'},
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| king b1 rook a1 queenside | False | True | Failed |
| king b1 rook c1 kingside | False | True | Failed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | False | False | Passed |
| king destination attacked | False | False | Passed |
| king in check | False | False | Passed |
| king c1 rook a1 queenside | False | False | Passed |
SHA-256 / 4238ab5fd75c44f4c57ef739997930ec4688f3172f793780d4a015b433ddc27d
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),
('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),
('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 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 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),
('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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
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 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),
('black queenside c8 d8',
{'board': {'a8': 'r', 'd8': 'k', 'e1': 'K'},
'king_from': 'd8',
'rook_from': 'a8',
'side': 'b',
'wing': 'Q'},
True),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'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 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),
('rook f1 king e1 kingside',
{'board': {'e1': 'K', 'e8': 'k', 'f1': 'R'},
'king_from': 'e1',
'rook_from': 'f1',
'side': 'w',
'wing': 'K'},
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| king b1 rook a1 queenside | True | True | Passed |
| king b1 rook c1 kingside | True | True | Passed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | False | False | Passed |
| king destination attacked | False | False | Passed |
| king in check | False | False | Passed |
| king c1 rook a1 queenside | False | False | Passed |
SHA-256 / 06821deae7f2165dc3174abdf332d5c6a839e899e15f82ee38338cc960db64bc
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.622431+00:00.
Case digest / 7bfe5544fed094b0e566a335c37d524ac774e9d6c80a2d19cfaa94a3bb21d6e2