FA-82706 / Chess move legality / Open access
Kingside castling with a rook on the a-side · case 01
King d1 castles "kingside" with the rook on b1.
ROOT CAUSE
The rook's side relative to the king is never checked for kingside castling.
VERIFIED REPAIR
The kingside rook must stand on a file greater than the king's.
Unsuccessful approach: Allowing the adjacent a-side file still accepts rooks on the wrong side.
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':
pass
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),
('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 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 adjacent on a-side kingside',
{'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'c1',
'side': 'w',
'wing': 'K'},
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 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 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),
('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 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),
('rook on wrong side',
{'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'b1',
'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)]]
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 |
| king f1 rook h1 | True | True | Passed |
| king g1 rook h1 stays | True | True | Passed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | True | False | Failed |
| rook adjacent on a-side kingside | True | False | Failed |
SHA-256 / 1da8c182fae3e79c88bc0524a6b1b9589bc067f6895e669f69723c58dc6cef00
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-1: 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),
('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 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 adjacent on a-side kingside',
{'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'c1',
'side': 'w',
'wing': 'K'},
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 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 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),
('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 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),
('rook on wrong side',
{'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'b1',
'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)]]
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 |
| king f1 rook h1 | True | True | Passed |
| king g1 rook h1 stays | True | True | Passed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | False | False | Passed |
| rook adjacent on a-side kingside | True | False | Failed |
SHA-256 / ca2e3102de1ace246eec445f22d490cb17558a998ba86a5479ab546a4a1d0ab7
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),
('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 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 adjacent on a-side kingside',
{'board': {'c1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'c1',
'side': 'w',
'wing': 'K'},
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 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 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),
('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 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),
('rook on wrong side',
{'board': {'b1': 'R', 'd1': 'K', 'e8': 'k'},
'king_from': 'd1',
'rook_from': 'b1',
'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)]]
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 |
| king f1 rook h1 | True | True | Passed |
| king g1 rook h1 stays | True | True | Passed |
| rook destination occupied | False | False | Passed |
| queenside d1 occupied | False | False | Passed |
| rook on wrong side | False | False | Passed |
| rook adjacent on a-side kingside | False | False | Passed |
SHA-256 / a779bc4bac230d3cb05a3eed5def8d090a03be0f2ca6d221543b98f20a06bede
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.639614+00:00.
Case digest / 1724333a66517118dca953121ccd63bc0e1fc2f7ebcf6421ca9ec1736911abe5