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

N = 1
observations = []
def solve(x):
    level, strain, dbl, vul, tricks = x
    need = 6 + level
    if tricks < need:
        down = need - tricks
        if dbl == 0:
            return -(100 if vul else 50) - 50 * (down - 1)
        pen = 0
        for k in range(1, down + 1):
            if vul:
                pen += 200 if k == 1 else 300
            else:
                pen += 100 if k == 1 else 200 if k <= 3 else 300
        return -pen * dbl
    per = 20 if strain in 'CD' else 30
    base = per * level + (10 if strain == 'N' else 0)
    mult = [1, 2, 4][dbl]
    trick_score = base * mult
    score = trick_score
    score += (500 if vul else 300) if trick_score >= 100 else 50
    if level == 6:
        score += 750 if vul else 500
    elif level == 7:
        score += 1500 if vul else 1000
    over = tricks - need
    if dbl == 0:
        score += over * per
    else:
        score += over * (200 if vul else 100) * dbl
    score += 50 * dbl
    return score
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[7, 'D', 0, True, 11], -200], [[7, 'S', 0, True, 12], -100], [[6, 'N', 0, True, 12], 1440], [[2, 'H', 1, True, 9], 870], [[3, 'H', 2, False, 11], 1160], [[5, 'N', 0, False, 11], 460], [[2, 'D', 0, True, 8], 90], [[6, 'H', 0, True, 10], -200]], [[[7, 'S', 0, True, 12], -100], [[7, 'D', 0, True, 8], -500], [[6, 'H', 0, False, 12], 980], [[6, 'H', 0, False, 11], -50], [[6, 'N', 0, False, 12], 990], [[6, 'D', 2, True, 13], 2230], [[5, 'N', 0, True, 6], -500], [[5, 'S', 0, True, 8], -300]], [[[6, 'H', 0, True, 13], 1460], [[2, 'C', 0, True, 9], 110], [[4, 'N', 0, False, 12], 490], [[7, 'C', 0, True, 13], 2140], [[3, 'S', 1, False, 5], -800], [[5, 'C', 2, False, 13], 1200], [[4, 'D', 0, True, 7], -300], [[2, 'D', 0, True, 3], -500]], [[[4, 'N', 2, True, 11], 1520], [[2, 'C', 2, False, 7], -200], [[2, 'H', 2, False, 5], -1000], [[7, 'H', 2, False, 11], -600], [[3, 'N', 1, True, 7], -500], [[6, 'S', 0, True, 12], 1430], [[7, 'C', 0, True, 12], -100], [[5, 'N', 0, True, 6], -500]], [[[1, 'D', 2, True, 6], -400], [[5, 'H', 0, True, 11], 650], [[4, 'D', 0, True, 7], -300], [[7, 'D', 1, True, 10], -800], [[4, 'C', 1, True, 9], -200], [[3, 'S', 2, True, 9], 960], [[2, 'D', 0, True, 5], -300], [[5, 'H', 0, True, 8], -300]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("duplicate score case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Vulnerable declarers lose half the penalty.

Input [level, strain, doubled(0/1/2), vulnerable, tricks]. Trick score C/D 20, H/S 30, NT 40+30; x2/x4 doubled/redoubled. Game bonus 300/500 when trick score >= 100 else 50 partscore; slam 500/750 (6) or 1000/1500 (7); overtricks trick value undoubled, 100/200 per double level; insult 50 per double level. Undertricks: 50/100 undoubled; doubled NV 100, 200, 200, then 300; doubled V 200 then 300; redoubled x2.

split: open-access


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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',):
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1D', 'P', 'X', 'P', '2C', 'P', 'P', 'XX'], ['illegal', 2, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1S', 'P', 'X', 'XX'], ['illegal', 2, None]], [['P', '1C', '1D', '1N', 'P', 'X', 'P'], ['illegal', 5, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1D', 'P', 'X', 'P', '2C', 'P', 'P', 'XX'], ['illegal', 2, None]], [['P', 'P', '1S', 'P', '2D', '2H', 'P', 'X'], ['illegal', 7, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1S', 'P', 'X', 'XX'], ['illegal', 2, None]], [['1C', '1H', '1S', 'P', 'X', 'P', 'XX'], ['illegal', 4, None]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1D', 'X', '2C', '2S', 'P', 'X', '3C', '3N', 'P', '4S', 'XX', '5C', 'P'], ['illegal', 5, None]], [['1C', 'P', 'P', '1H', 'P', 'X', '1N', 'P', 'X', 'P'], ['illegal', 5, None]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or last_caller == seat:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1D', 'P', 'X', 'P', '2C', 'P', 'P', 'XX'], ['illegal', 2, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1S', 'P', 'X', 'XX'], ['illegal', 2, None]], [['P', '1C', '1D', '1N', 'P', 'X', 'P'], ['illegal', 5, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1D', 'P', 'X', 'P', '2C', 'P', 'P', 'XX'], ['illegal', 2, None]], [['P', 'P', '1S', 'P', '2D', '2H', 'P', 'X'], ['illegal', 7, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1S', 'P', 'X', 'XX'], ['illegal', 2, None]], [['1C', '1H', '1S', 'P', 'X', 'P', 'XX'], ['illegal', 4, None]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1D', 'X', '2C', '2S', 'P', 'X', '3C', '3N', 'P', '4S', 'XX', '5C', 'P'], ['illegal', 5, None]], [['1C', 'P', 'P', '1H', 'P', 'X', '1N', 'P', 'X', 'P'], ['illegal', 5, None]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Doubling your own side contract is accepted.

Input list of calls (bids like "2H"/"3N", "P", "X", "XX") starting with dealer seat 0. Each bid must outrank the previous bid (level, then C<D<H<S<N). X requires the last non-pass call to be an opponent bid; XX an opponent X. Four initial passes -> ["passed out", None, None]; three passes after a bid -> ["contract", bid+X/XX, declarer] where declarer is the first player of the declaring side to name the strain. Illegal call -> ["illegal", index, None]; unfinished -> ["open", None, None].

split: open-access


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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'XX', 'X', 'P', 'P'], ['illegal', 1, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['P', '1D', 'P', 'P', 'XX', 'P', 'X', 'P', 'X'], ['illegal', 4, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]], [['P', 'P', 'P', '1S', 'X', 'P', 'P', 'P'], ['contract', '1SX', 3]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
            passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'XX', 'X', 'P', 'P'], ['illegal', 1, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['P', '1D', 'P', 'P', 'XX', 'P', 'X', 'P', 'X'], ['illegal', 4, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['P', '1S', 'P', 'P', 'X', 'P', 'P', 'X', '2H', 'P', 'XX', 'P', '2S'], ['illegal', 7, None]], [['P', 'P', 'P', '1S', 'X', 'P', 'P', 'P'], ['contract', '1SX', 3]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An auction ends one pass after a balancing double.

Input list of calls (bids like "2H"/"3N", "P", "X", "XX") starting with dealer seat 0. Each bid must outrank the previous bid (level, then C<D<H<S<N). X requires the last non-pass call to be an opponent bid; XX an opponent X. Four initial passes -> ["passed out", None, None]; three passes after a bid -> ["contract", bid+X/XX, declarer] where declarer is the first player of the declaring side to name the strain. Illegal call -> ["illegal", index, None]; unfinished -> ["open", None, None].

split: open-access


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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1H', 'X', 'XX', '2C', 'P', 'P', 'P'], ['contract', '2C', 3]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1H', 'X', '2C', 'P', 'P', 'P'], ['contract', '2C', 2]], [['1C', 'P', 'P', 'X', 'XX', '1N', 'P', 'P', 'P'], ['contract', '1N', 1]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1S', 'X', 'XX', 'P', '2D', 'P', 'P', 'P'], ['contract', '2D', 0]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1H', 'X', 'XX', '2C', 'P', 'P', 'P'], ['contract', '2C', 3]], [['1H', 'X', '2C', 'P', 'P', 'P'], ['contract', '2C', 2]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['XX', 'P', 'X', 'XX', '1C', 'P', 'XX', 'P', 'P', 'XX', 'X', '1H'], ['illegal', 0, None]], [['1C', 'P', 'P', 'X', 'XX', '1N', 'P', 'P', 'P'], ['contract', '1N', 1]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = max(state - 1, 0)
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1H', 'X', 'XX', '2C', 'P', 'P', 'P'], ['contract', '2C', 3]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1H', 'X', '2C', 'P', 'P', 'P'], ['contract', '2C', 2]], [['1C', 'P', 'P', 'X', 'XX', '1N', 'P', 'P', 'P'], ['contract', '1N', 1]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1S', 'X', 'XX', 'P', '2D', 'P', 'P', 'P'], ['contract', '2D', 0]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1H', 'X', 'XX', '2C', 'P', 'P', 'P'], ['contract', '2C', 3]], [['1H', 'X', '2C', 'P', 'P', 'P'], ['contract', '2C', 2]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['XX', 'P', 'X', 'XX', '1C', 'P', 'XX', 'P', 'P', 'XX', 'X', '1H'], ['illegal', 0, None]], [['1C', 'P', 'P', 'X', 'XX', '1N', 'P', 'P', 'P'], ['contract', '1N', 1]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The final contract reports X although a later bid overcalled the doubled contract.

Input list of calls (bids like "2H"/"3N", "P", "X", "XX") starting with dealer seat 0. Each bid must outrank the previous bid (level, then C<D<H<S<N). X requires the last non-pass call to be an opponent bid; XX an opponent X. Four initial passes -> ["passed out", None, None]; three passes after a bid -> ["contract", bid+X/XX, declarer] where declarer is the first player of the declaring side to name the strain. Illegal call -> ["illegal", index, None]; unfinished -> ["open", None, None].

split: open-access


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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], last_bidder]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['P', '1D', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 3]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1H', 'P', '1S', 'P', '2S', 'P', 'P', 'P'], ['contract', '2S', 2]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['P', '1D', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 3]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank <= (int(last_bid[0]), strains.index(last_bid[1])):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first[(seat % 2, call[1])] = seat
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['P', '1D', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 3]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1H', 'P', '1S', 'P', '2S', 'P', 'P', 'P'], ['contract', '2S', 2]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]]], [[['1D', 'XX', 'P', 'P', 'XX', 'P'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['1C', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 2]], [['P', '1D', 'P', '1H', 'P', '2H', 'P', 'P', 'P'], ['contract', '2H', 3]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
When partner first named the strain, the raiser is reported as declarer.

Input list of calls (bids like "2H"/"3N", "P", "X", "XX") starting with dealer seat 0. Each bid must outrank the previous bid (level, then C<D<H<S<N). X requires the last non-pass call to be an opponent bid; XX an opponent X. Four initial passes -> ["passed out", None, None]; three passes after a bid -> ["contract", bid+X/XX, declarer] where declarer is the first player of the declaring side to name the strain. Illegal call -> ["illegal", index, None]; unfinished -> ["open", None, None].

split: open-access


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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and int(call[0]) < int(last_bid[0]):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'XX', 'X', 'P', 'P'], ['illegal', 1, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1S', '1H', '2D', 'P', 'P', '3C'], ['illegal', 1, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1S', '2D', '2H', '3D', '3C', 'P', '3C'], ['illegal', 4, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['XX', 'P', 'X', 'XX', '1C', 'P', 'XX', 'P', 'P', 'XX', 'X', '1H'], ['illegal', 0, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    calls = x
    strains = 'CDHSN'
    last_bid = None
    last_bidder = None
    state = 0
    last_call = None
    last_caller = None
    passes = 0
    first = {}
    for i, call in enumerate(calls):
        seat = i % 4
        if call == 'P':
            passes += 1
            if last_bid is None and passes == 4:
                return ['passed out', None, None]
            if last_bid is not None and passes == 3:
                side = last_bidder % 2
                return ['contract', last_bid + ['', 'X', 'XX'][state], first[(side, last_bid[1])]]
            continue
        if call == 'X':
            if last_call is None or last_call not in ('bid',) or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 1
        elif call == 'XX':
            if last_call != 'X' or (last_caller - seat) % 2 == 0:
                return ['illegal', i, None]
            state = 2
        else:
            rank = (int(call[0]), strains.index(call[1]))
            if last_bid is not None and rank[0] <= int(last_bid[0]) and rank[1] <= strains.index(last_bid[1]):
                return ['illegal', i, None]
            last_bid = call
            last_bidder = seat
            state = 0
            first.setdefault((seat % 2, call[1]), seat)
        passes = 0
        last_call = 'bid' if call not in ('X', 'XX') else call
        last_caller = seat
    return ['open', None, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[['X', '1D', 'P'], ['illegal', 0, None]], [['P', 'X', '1C', 'P', 'P', 'P', 'P', '1N', '2S', '3H'], ['illegal', 1, None]], [['1S', 'P', 'P', '2C', '2N', 'P', '2S'], ['illegal', 6, None]], [['P', '1S', 'P', 'P', 'P', '2D', 'P'], ['contract', '1S', 1]], [['P', 'P'], ['open', None, None]], [['1H'], ['open', None, None]], [['P', 'XX', 'X', 'P', 'P'], ['illegal', 1, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['P', 'P', '1C', 'P', 'X', 'P', '1H', '2C', '2N'], ['illegal', 4, None]], [['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['P', 'P', '1C', 'P'], ['open', None, None]], [['1S', 'P', 'P', '2C', 'XX', 'X'], ['illegal', 4, None]], [['XX', '1C', '1N', 'P', 'P', 'P'], ['illegal', 0, None]], [['1C', 'XX', 'P', 'X', 'P', 'P', '1D', 'X', 'P', 'P', 'P'], ['illegal', 1, None]], [['1C', 'X', 'P', '1D', '1H', 'P', 'P', 'X', 'P', '2D', '2C', 'X'], ['illegal', 10, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['P', 'P'], ['open', None, None]], [['1H', 'P', 'XX', 'X', '1D', '2D'], ['illegal', 2, None]], [['XX'], ['illegal', 0, None]], [['XX', 'P'], ['illegal', 0, None]], [['X', 'P', '1C', 'P', 'P', 'P', 'X'], ['illegal', 0, None]], [['P', 'X', 'XX', 'X', 'X', 'P', 'X', 'P'], ['illegal', 1, None]], [['1S', '1H', '2D', 'P', 'P', '3C'], ['illegal', 1, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['1H', '1S', 'P', '2H', 'P', 'P', '2N', 'X', 'P', '3D'], ['open', None, None]], [['P', 'X', 'X', '1H', 'P', 'P', 'X', '2D', 'P', 'P'], ['illegal', 1, None]], [['P', 'P', 'X', 'P', 'X'], ['illegal', 2, None]], [['XX', 'P', 'P', 'P'], ['illegal', 0, None]], [['P', 'X'], ['illegal', 1, None]], [['X', '1D', 'P', '2C', 'P', 'P', 'P', 'XX', '2D', 'X', '2H', 'P', '2S'], ['illegal', 0, None]], [['1S', '2D', '2H', '3D', '3C', 'P', '3C'], ['illegal', 4, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]], [[['1C', '1C', 'P', '1S', 'P', 'X', 'P', 'P', 'XX'], ['illegal', 1, None]], [['1S', 'P', 'XX', '2D', '2S', 'P'], ['illegal', 2, None]], [['P', 'P', '1D', 'P', 'P', 'P', 'P', '1H', 'X', '1N', 'P'], ['contract', '1D', 2]], [['P', 'P', '1H', 'XX', '1S', '2C', '2H', '2D', 'P', 'P', '3C', 'XX', 'P'], ['illegal', 3, None]], [['P', '1C', 'XX', 'P', 'P', 'P', 'P', '1N', 'P'], ['illegal', 2, None]], [['P', '1D', 'X', '2C', '2S', 'P', '3D', 'P', 'P', 'P'], ['contract', '3D', 2]], [['XX', 'P', 'X', 'XX', '1C', 'P', 'XX', 'P', 'P', 'XX', 'X', '1H'], ['illegal', 0, None]], [['2C', 'P', '1N'], ['illegal', 2, None]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("auction case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
1H over 1S is accepted as sufficient.

Input list of calls (bids like "2H"/"3N", "P", "X", "XX") starting with dealer seat 0. Each bid must outrank the previous bid (level, then C<D<H<S<N). X requires the last non-pass call to be an opponent bid; XX an opponent X. Four initial passes -> ["passed out", None, None]; three passes after a bid -> ["contract", bid+X/XX, declarer] where declarer is the first player of the declaring side to name the strain. Illegal call -> ["illegal", index, None]; unfinished -> ["open", None, None].

split: open-access


prompt:
The jack of the same colour loses to small trumps and follows its printed suit.

Input [four_cards, leader, trump]. The jack of trump (right bower) is highest, the jack of the same-colour suit (left bower) is second and belongs to the trump suit; then A K Q T 9 of trump. Otherwise the highest card of the effective led suit (A K Q J T 9) wins. Return the winning seat.

split: open-access


prompt:
The same-colour jack beats the jack of trump.

Input [four_cards, leader, trump]. The jack of trump (right bower) is highest, the jack of the same-colour suit (left bower) is second and belongs to the trump suit; then A K Q T 9 of trump. Otherwise the highest card of the effective led suit (A K Q J T 9) wins. Return the winning seat.

split: open-access


prompt:
Playing the left bower on a led plain suit loses the trick.

Input [four_cards, leader, trump]. The jack of trump (right bower) is highest, the jack of the same-colour suit (left bower) is second and belongs to the trump suit; then A K Q T 9 of trump. Otherwise the highest card of the effective led suit (A K Q J T 9) wins. Return the winning seat.

split: open-access


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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks >= 4:
            return ['makers', 4 if alone else 2]
        return ['makers', 1]
    return ['defenders', 4 if def_alone else 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[4, False, False], ['makers', 1]], [[5, True, False], ['makers', 4]]], [[[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]], [[5, True, True], ['makers', 4]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[4, True, False], ['makers', 1]], [[5, True, False], ['makers', 4]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[4, False, True], ['makers', 1]], [[5, True, True], ['makers', 4]]], [[[3, False, True], ['makers', 1]], [[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, True, False], ['makers', 4]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks == 5 and not alone:
            return ['makers', 4 if alone else 2]
        return ['makers', 1]
    return ['defenders', 4 if def_alone else 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[4, False, False], ['makers', 1]], [[5, True, False], ['makers', 4]]], [[[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]], [[5, True, True], ['makers', 4]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[4, True, False], ['makers', 1]], [[5, True, False], ['makers', 4]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[4, False, True], ['makers', 1]], [[5, True, True], ['makers', 4]]], [[[3, False, True], ['makers', 1]], [[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, True, False], ['makers', 4]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Makers with four tricks get 2 points.

Input [makers_tricks, maker_alone, defender_alone]. Makers with 3-4 tricks score 1; all 5 score 2, or 4 when alone. Makers with fewer than 3 are euchred: defenders score 2, or 4 when a defender played alone. Return [team, points].

split: open-access


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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks == 5:
            return ['makers', 4 if alone else 2]
        return ['makers', 2 if alone else 1]
    return ['defenders', 4 if def_alone else 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, True, False], ['makers', 1]], [[4, True, False], ['makers', 1]]], [[[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[4, False, False], ['makers', 1]], [[4, True, False], ['makers', 1]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, True, True], ['makers', 1]], [[4, False, True], ['makers', 1]]], [[[3, False, True], ['makers', 1]], [[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks == 5:
            return ['makers', 4 if alone else 2]
        return ['makers', 1 if tricks == 3 else 2]
    return ['defenders', 4 if def_alone else 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, True, False], ['makers', 1]], [[4, True, False], ['makers', 1]]], [[[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[4, False, False], ['makers', 1]], [[4, True, False], ['makers', 1]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, True, True], ['makers', 1]], [[4, False, True], ['makers', 1]]], [[[3, False, True], ['makers', 1]], [[3, True, False], ['makers', 1]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Partial lone hands are over-rewarded.

Input [makers_tricks, maker_alone, defender_alone]. Makers with 3-4 tricks score 1; all 5 score 2, or 4 when alone. Makers with fewer than 3 are euchred: defenders score 2, or 4 when a defender played alone. Return [team, points].

split: open-access


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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks == 5:
            return ['makers', 4 if alone else 2]
        return ['makers', 1]
    return ['defenders', 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[0, False, True], ['defenders', 4]], [[0, False, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, False, True], ['makers', 1]]], [[[1, True, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]], [[5, False, True], ['makers', 2]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[1, False, True], ['defenders', 4]], [[2, False, True], ['defenders', 4]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, False, True], ['makers', 1]]], [[[0, False, True], ['defenders', 4]], [[1, False, True], ['defenders', 4]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    tricks, alone, def_alone = x
    if tricks >= 3:
        if tricks == 5:
            return ['makers', 4 if alone else 2]
        return ['makers', 1]
    return ['defenders', 4 if alone else 2]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[0, False, True], ['defenders', 4]], [[0, False, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, False, True], ['makers', 1]]], [[[1, True, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]], [[5, False, True], ['makers', 2]]], [[[0, False, False], ['defenders', 2]], [[0, False, True], ['defenders', 4]], [[0, True, False], ['defenders', 2]], [[0, True, True], ['defenders', 4]], [[1, False, False], ['defenders', 2]], [[1, False, True], ['defenders', 4]], [[2, False, True], ['defenders', 4]], [[5, True, True], ['makers', 4]]], [[[1, True, False], ['defenders', 2]], [[1, True, True], ['defenders', 4]], [[2, False, False], ['defenders', 2]], [[2, False, True], ['defenders', 4]], [[2, True, False], ['defenders', 2]], [[2, True, True], ['defenders', 4]], [[3, False, False], ['makers', 1]], [[3, False, True], ['makers', 1]]], [[[0, False, True], ['defenders', 4]], [[1, False, True], ['defenders', 4]], [[3, True, True], ['makers', 1]], [[4, False, False], ['makers', 1]], [[4, False, True], ['makers', 1]], [[4, True, False], ['makers', 1]], [[4, True, True], ['makers', 1]], [[5, False, False], ['makers', 2]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("hand points case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Defending alone earns no bonus.

Input [makers_tricks, maker_alone, defender_alone]. Makers with 3-4 tricks score 1; all 5 score 2, or 4 when alone. Makers with fewer than 3 are euchred: defenders score 2, or 4 when a defender played alone. Return [team, points].

split: open-access


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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = bt <= 5
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = third != 8
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['KC', 'JD'], ['TC', 'TD'], ['AH', '4S']], [1, 4, 'banker', 2]], [[['JD', 'QD'], ['7S', 'AC'], ['5C', '6H']], [0, 8, 'banker', 0]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['4S', '8H'], ['9C', 'KD'], ['JH', 'AD']], [2, 9, 'banker', 0]], [[['KS', 'QH'], ['4C', '4D'], ['4C', '5S']], [0, 8, 'banker', 0]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['5H', '5S'], ['AC', '7C'], ['KC', 'KH']], [0, 8, 'banker', 0]], [[['3H', '2D'], ['KH', '8H'], ['3C', 'QC']], [5, 8, 'banker', 0]]], [[[['8D', 'TH'], ['QS', '9S'], ['3S', '9H']], [8, 9, 'banker', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['6S', '9D'], ['4S', '5S'], ['4D', 'AC']], [5, 9, 'banker', 0]], [[['JH', 'AD'], ['7D', 'AC'], ['TS', '5D']], [1, 8, 'banker', 0]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['JC', '5H'], ['AH', '3D'], ['2H', '9H']], [7, 3, 'player', 2]], [[['QS', 'TD'], ['AS', '7S'], ['KS', 'JH']], [0, 8, 'banker', 0]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8 and bt < 9:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = bt <= 5
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = third != 8
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['KC', 'JD'], ['TC', 'TD'], ['AH', '4S']], [1, 4, 'banker', 2]], [[['JD', 'QD'], ['7S', 'AC'], ['5C', '6H']], [0, 8, 'banker', 0]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['4S', '8H'], ['9C', 'KD'], ['JH', 'AD']], [2, 9, 'banker', 0]], [[['KS', 'QH'], ['4C', '4D'], ['4C', '5S']], [0, 8, 'banker', 0]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['5H', '5S'], ['AC', '7C'], ['KC', 'KH']], [0, 8, 'banker', 0]], [[['3H', '2D'], ['KH', '8H'], ['3C', 'QC']], [5, 8, 'banker', 0]]], [[[['8D', 'TH'], ['QS', '9S'], ['3S', '9H']], [8, 9, 'banker', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['6S', '9D'], ['4S', '5S'], ['4D', 'AC']], [5, 9, 'banker', 0]], [[['JH', 'AD'], ['7D', 'AC'], ['TS', '5D']], [1, 8, 'banker', 0]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['JC', '5H'], ['AH', '3D'], ['2H', '9H']], [7, 3, 'player', 2]], [[['QS', 'TD'], ['AS', '7S'], ['KS', 'JH']], [0, 8, 'banker', 0]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Player draws against a banker 8 or 9.

Input [player_cards, banker_cards, next_shoe_cards]. Values A=1, 2-9 pip, T/J/Q/K 0; totals mod 10. A natural 8/9 on either side stops the coup. Player draws on 0-5. If player stood, banker draws on 0-5; otherwise banker draws on 0-2, on 3 unless the player third card is 8, on 4 vs 2-7, on 5 vs 4-7, on 6 vs 6-7. Return [player_total, banker_total, winner, cards_drawn].

split: open-access


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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8 and bt < 8:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = bt <= 5
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = True
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['8D', 'TH'], ['QS', '9S'], ['3S', '9H']], [8, 9, 'banker', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8 and bt < 8:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = bt <= 5
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = third != 9
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['8D', 'TH'], ['QS', '9S'], ['3S', '9H']], [8, 9, 'banker', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]], [[['3S', '8C'], ['3H', 'TS'], ['8S', '5C']], [9, 3, 'player', 1]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Banker takes a card it must refuse.

Input [player_cards, banker_cards, next_shoe_cards]. Values A=1, 2-9 pip, T/J/Q/K 0; totals mod 10. A natural 8/9 on either side stops the coup. Player draws on 0-5. If player stood, banker draws on 0-5; otherwise banker draws on 0-2, on 3 unless the player third card is 8, on 4 vs 2-7, on 5 vs 4-7, on 6 vs 6-7. Return [player_total, banker_total, winner, cards_drawn].

split: open-access


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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8 and bt < 8:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = bt <= 6
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = third != 8
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['QC', '7S'], ['AC', '2D'], ['4H', 'JS']], [7, 7, 'tie', 1]], [[['AC', '6C'], ['8C', '8S'], ['JC', 'AD']], [7, 6, 'player', 0]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['JH', '6D'], ['TD', '4C'], ['7H', '9S']], [6, 1, 'player', 1]], [[['2S', '4H'], ['KC', '6D'], ['9C', '5S']], [6, 6, 'tie', 0]]], [[[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['JH', '3H'], ['TH', '3D'], ['AH', '2S']], [4, 5, 'banker', 2]], [[['TS', '6C'], ['3H', 'AH'], ['QS', '9D']], [6, 4, 'player', 1]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['7D', '9C'], ['QH', 'TD'], ['KS', '2S']], [6, 0, 'player', 1]], [[['AC', '6C'], ['8C', '8S'], ['JC', 'AD']], [7, 6, 'player', 0]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p, b, shoe = x
    def val(c):
        r = c[0]
        if r == 'A':
            return 1
        if r in 'TJQK':
            return 0
        return int(r)
    def tot(h):
        return sum(val(c) for c in h) % 10
    p = list(p)
    b = list(b)
    k = 0
    pt, bt = tot(p), tot(b)
    if pt < 8 and bt < 8:
        third = None
        if pt <= 5:
            p.append(shoe[k])
            k += 1
            third = val(p[-1])
        if third is None:
            draw = False
        elif bt <= 2:
            draw = True
        elif bt == 3:
            draw = third != 8
        elif bt == 4:
            draw = 2 <= third <= 7
        elif bt == 5:
            draw = 4 <= third <= 7
        elif bt == 6:
            draw = 6 <= third <= 7
        else:
            draw = False
        if draw:
            b.append(shoe[k])
            k += 1
    pt, bt = tot(p), tot(b)
    winner = 'player' if pt > bt else 'banker' if bt > pt else 'tie'
    return [pt, bt, winner, k]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[[['6C', '8D'], ['3H', 'TS'], ['9D', 'QS']], [3, 3, 'tie', 2]], [[['JD', '4H'], ['QC', '8D'], ['TS', '7H']], [4, 8, 'banker', 0]], [[['2H', '8C'], ['7C', 'JS'], ['2C', '7D']], [2, 7, 'banker', 1]], [[['2C', '9D'], ['7C', 'JH'], ['2S', '8H']], [3, 7, 'banker', 1]], [[['5C', '3C'], ['TC', '5H'], ['AC', 'TH']], [8, 5, 'player', 0]], [[['7C', '2C'], ['6H', '3S'], ['AH', '5S']], [9, 9, 'tie', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]]], [[[['6S', 'QD'], ['6C', '7D'], ['7S', '4D']], [6, 0, 'player', 1]], [[['7H', '3D'], ['JS', 'JH'], ['6H', 'AC']], [6, 1, 'player', 2]], [[['2S', '2C'], ['AS', '7D'], ['2H', '9H']], [4, 8, 'banker', 0]], [[['KC', '6H'], ['9D', 'QS'], ['2C', 'KD']], [6, 9, 'banker', 0]], [[['5S', '6C'], ['6S', '3S'], ['KC', 'KH']], [1, 9, 'banker', 0]], [[['9C', '2H'], ['JC', 'JS'], ['TH', 'QC']], [1, 0, 'player', 2]], [[['QC', '7S'], ['AC', '2D'], ['4H', 'JS']], [7, 7, 'tie', 1]], [[['AC', '6C'], ['8C', '8S'], ['JC', 'AD']], [7, 6, 'player', 0]]], [[[['4C', '5S'], ['6S', '4H'], ['QC', '3C']], [9, 0, 'player', 0]], [[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['2C', '4D'], ['8D', '3H'], ['KS', '6C']], [6, 1, 'player', 1]], [[['6S', 'QD'], ['8H', '9D'], ['3S', 'TD']], [6, 7, 'banker', 0]], [[['3H', 'TD'], ['QS', '5C'], ['5D', 'AD']], [8, 6, 'player', 2]], [[['6S', 'JS'], ['4D', '6D'], ['2C', 'KD']], [6, 2, 'player', 1]], [[['JH', '6D'], ['TD', '4C'], ['7H', '9S']], [6, 1, 'player', 1]], [[['2S', '4H'], ['KC', '6D'], ['9C', '5S']], [6, 6, 'tie', 0]]], [[[['5H', '2C'], ['TD', '6C'], ['7S', 'KC']], [7, 6, 'player', 0]], [[['AS', '5H'], ['5D', '9D'], ['7S', '5S']], [6, 1, 'player', 1]], [[['7C', 'JD'], ['2H', 'KC'], ['JS', 'AS']], [7, 2, 'player', 1]], [[['TH', '8C'], ['2C', '7H'], ['JH', '4D']], [8, 9, 'banker', 0]], [[['TC', '5D'], ['JC', '7S'], ['7C', '4C']], [2, 7, 'banker', 1]], [[['AS', '5H'], ['6C', '8C'], ['7D', '9S']], [6, 1, 'player', 1]], [[['JH', '3H'], ['TH', '3D'], ['AH', '2S']], [4, 5, 'banker', 2]], [[['TS', '6C'], ['3H', 'AH'], ['QS', '9D']], [6, 4, 'player', 1]]], [[[['5S', 'JS'], ['KH', 'TC'], ['4C', '9S']], [9, 9, 'tie', 2]], [[['9H', '9S'], ['TS', '4S'], ['TD', 'TC']], [8, 4, 'player', 0]], [[['9D', '9S'], ['2S', '6D'], ['6S', '4C']], [8, 8, 'tie', 0]], [[['2S', '9H'], ['7H', 'AS'], ['AH', '5H']], [1, 8, 'banker', 0]], [[['2C', '6H'], ['3D', 'TH'], ['QD', 'KS']], [8, 3, 'player', 0]], [[['2S', '2H'], ['3C', '9D'], ['KH', '6C']], [4, 8, 'banker', 2]], [[['7D', '9C'], ['QH', 'TD'], ['KS', '2S']], [6, 0, 'player', 1]], [[['AC', '6C'], ['8C', '8S'], ['JC', 'AD']], [7, 6, 'player', 0]]]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("coup case %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Banker 6 takes a card after player stands on 6-7.

Input [player_cards, banker_cards, next_shoe_cards]. Values A=1, 2-9 pip, T/J/Q/K 0; totals mod 10. A natural 8/9 on either side stops the coup. Player draws on 0-5. If player stood, banker draws on 0-5; otherwise banker draws on 0-2, on 3 unless the player third card is 8, on 4 vs 2-7, on 5 vs 4-7, on 6 vs 6-7. Return [player_total, banker_total, winner, cards_drawn].

split: open-access