FAILURE MAP
← Case archive

FA-82791 / Chess move legality / Open access

Standing still counted as a king move · case 01

Stalemated kings are reported as "ongoing".

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

ROOT CAUSE

The (0,0) offset is not skipped, so the king's own unattacked square counts as a legal move.

VERIFIED REPAIR

Skip the zero offset; a move must change squares.

Unsuccessful approach: Skipping every offset with a zero component also discards the four orthogonal king moves.

Case contract

Input: {"wk", "wq", "bk"} squares, black to move. Return "checkmate" if black has no legal king move and is attacked by the queen, "stalemate" if it has none and is not attacked, else "ongoing". The queen attacks along ranks, files and diagonals and is blocked only by the white king; the black king may capture the queen when it is not adjacent to the white king.

Why this case matters

Game-end detection must distinguish mate from stalemate exactly.

1 / The failure

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

N = 1
observations = []
def solve(x):
    def c(q): return ord(q[0])-97,int(q[1])-1
    wk,wq,bk=c(x['wk']),c(x['wq']),c(x['bk'])
    def queen_hits(t, occupied):
        if t==wq: return False
        df,dr=t[0]-wq[0],t[1]-wq[1]
        if not (df==0 or dr==0 or abs(df)==abs(dr)): return False
        sf=(df>0)-(df<0); sr=(dr>0)-(dr<0)
        f,r=wq[0]+sf,wq[1]+sr
        while (f,r)!=t:
            if (f,r) in occupied: return False
            f+=sf; r+=sr
        return True
    def near(a,b2): return max(abs(a[0]-b2[0]),abs(a[1]-b2[1]))<=1
    in_check=queen_hits(bk,{wk})
    moves=0
    for df in (-1,0,1):
        for dr in (-1,0,1):
            t=(bk[0]+df,bk[1]+dr)
            if not (0<=t[0]<8 and 0<=t[1]<8): continue
            if near(t,wk): continue
            if queen_hits(t,{wk}): continue
            moves+=1
    if moves: return 'ongoing'
    return 'checkmate' if in_check else 'stalemate'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('shielded by king', {'bk': 'e5', 'wk': 'e3', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('mate with rank retreat', {'bk': 'b1', 'wk': 'a3', 'wq': 'd1'}, 'checkmate'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('edge mate', {'bk': 'e8', 'wk': 'e6', 'wq': 'e7'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('far queen ongoing', {'bk': 'd5', 'wk': 'a1', 'wq': 'h2'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')]]
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
corner stalemateongoingstalemateFailed
queen kiss matecheckmatecheckmatePassed
back rank long matecheckmatecheckmatePassed
capture free queenongoingongoingPassed
queen check escapeongoingongoingPassed
stalemate h-fileongoingstalemateFailed
queen behind white kingongoingongoingPassed
orthogonal free captureongoingongoingPassed

SHA-256 / 5b736b8d6659dc789470d0dbee8539719629c14ebe4e4b4a6e3e47cb336b1de1

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    def c(q): return ord(q[0])-97,int(q[1])-1
    wk,wq,bk=c(x['wk']),c(x['wq']),c(x['bk'])
    def queen_hits(t, occupied):
        if t==wq: return False
        df,dr=t[0]-wq[0],t[1]-wq[1]
        if not (df==0 or dr==0 or abs(df)==abs(dr)): return False
        sf=(df>0)-(df<0); sr=(dr>0)-(dr<0)
        f,r=wq[0]+sf,wq[1]+sr
        while (f,r)!=t:
            if (f,r) in occupied: return False
            f+=sf; r+=sr
        return True
    def near(a,b2): return max(abs(a[0]-b2[0]),abs(a[1]-b2[1]))<=1
    in_check=queen_hits(bk,{wk})
    moves=0
    for df in (-1,0,1):
        for dr in (-1,0,1):
            if not (df and dr): continue
            t=(bk[0]+df,bk[1]+dr)
            if not (0<=t[0]<8 and 0<=t[1]<8): continue
            if near(t,wk): continue
            if queen_hits(t,{wk}): continue
            moves+=1
    if moves: return 'ongoing'
    return 'checkmate' if in_check else 'stalemate'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('shielded by king', {'bk': 'e5', 'wk': 'e3', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('mate with rank retreat', {'bk': 'b1', 'wk': 'a3', 'wq': 'd1'}, 'checkmate'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('edge mate', {'bk': 'e8', 'wk': 'e6', 'wq': 'e7'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('far queen ongoing', {'bk': 'd5', 'wk': 'a1', 'wq': 'h2'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')]]
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
corner stalematestalematestalematePassed
queen kiss matecheckmatecheckmatePassed
back rank long matecheckmatecheckmatePassed
capture free queenongoingongoingPassed
queen check escapeongoingongoingPassed
stalemate h-filestalematestalematePassed
queen behind white kingstalemateongoingFailed
orthogonal free capturecheckmateongoingFailed

SHA-256 / 10ff7389e1fcaadbfaba972566600975f57d7de5aa734973d86475a9b825314c

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    def c(q): return ord(q[0])-97,int(q[1])-1
    wk,wq,bk=c(x['wk']),c(x['wq']),c(x['bk'])
    def queen_hits(t, occupied):
        if t==wq: return False
        df,dr=t[0]-wq[0],t[1]-wq[1]
        if not (df==0 or dr==0 or abs(df)==abs(dr)): return False
        sf=(df>0)-(df<0); sr=(dr>0)-(dr<0)
        f,r=wq[0]+sf,wq[1]+sr
        while (f,r)!=t:
            if (f,r) in occupied: return False
            f+=sf; r+=sr
        return True
    def near(a,b2): return max(abs(a[0]-b2[0]),abs(a[1]-b2[1]))<=1
    in_check=queen_hits(bk,{wk})
    moves=0
    for df in (-1,0,1):
        for dr in (-1,0,1):
            if not (df or dr): continue
            t=(bk[0]+df,bk[1]+dr)
            if not (0<=t[0]<8 and 0<=t[1]<8): continue
            if near(t,wk): continue
            if queen_hits(t,{wk}): continue
            moves+=1
    if moves: return 'ongoing'
    return 'checkmate' if in_check else 'stalemate'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('shielded by king', {'bk': 'e5', 'wk': 'e3', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('mate with rank retreat', {'bk': 'b1', 'wk': 'a3', 'wq': 'd1'}, 'checkmate'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('queen kiss far side', {'bk': 'b8', 'wk': 'a6', 'wq': 'd8'}, 'checkmate'),
  ('edge mate', {'bk': 'e8', 'wk': 'e6', 'wq': 'e7'}, 'checkmate'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('far queen ongoing', {'bk': 'd5', 'wk': 'a1', 'wq': 'h2'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing'),
  ('king retreat along queen file', {'bk': 'd7', 'wk': 'a1', 'wq': 'd1'}, 'ongoing')],
 [('corner stalemate', {'bk': 'a8', 'wk': 'c6', 'wq': 'b6'}, 'stalemate'),
  ('queen kiss mate', {'bk': 'a8', 'wk': 'b6', 'wq': 'b7'}, 'checkmate'),
  ('back rank long mate', {'bk': 'h8', 'wk': 'g6', 'wq': 'a8'}, 'checkmate'),
  ('capture free queen', {'bk': 'a8', 'wk': 'h1', 'wq': 'b7'}, 'ongoing'),
  ('queen check escape', {'bk': 'e5', 'wk': 'a1', 'wq': 'e1'}, 'ongoing'),
  ('stalemate h-file', {'bk': 'h8', 'wk': 'f7', 'wq': 'g6'}, 'stalemate'),
  ('queen behind white king', {'bk': 'a1', 'wk': 'b3', 'wq': 'b5'}, 'ongoing'),
  ('orthogonal free capture', {'bk': 'a8', 'wk': 'h1', 'wq': 'a7'}, 'ongoing')]]
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
corner stalematestalematestalematePassed
queen kiss matecheckmatecheckmatePassed
back rank long matecheckmatecheckmatePassed
capture free queenongoingongoingPassed
queen check escapeongoingongoingPassed
stalemate h-filestalematestalematePassed
queen behind white kingongoingongoingPassed
orthogonal free captureongoingongoingPassed

SHA-256 / df5ee5466a3198834e0cd497cf32abe8307a86f3be0bb857357c561c450f17d5

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:15.347083+00:00.

Case digest / 60237c68fbbf4b4c8b1bd5b8437789e21ee2dbeeeea014c5fcd3763621e29121