face status is same within chunks of 5 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 5 == 0:
    return card.is_face != mainline[-1].is_face
return card.is_face == mainline[-1].is_face


rank parity is different within chunks of 2 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 2 == 0:
    return card.rank % 2 == mainline[-1].rank % 2
return card.rank % 2 != mainline[-1].rank % 2


face status is different within chunks of 3 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 3 == 0:
    return card.is_face == mainline[-1].is_face
return card.is_face != mainline[-1].is_face


color is same within chunks of 4 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 4 == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color


suit is same within chunks of 3 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 3 == 0:
    return card.suit != mainline[-1].suit
return card.suit == mainline[-1].suit


rank is different within chunks of 3 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 3 == 0:
    return card.rank == mainline[-1].rank
return card.rank != mainline[-1].rank


face status is same within chunks of 2 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 2 == 0:
    return card.is_face != mainline[-1].is_face
return card.is_face == mainline[-1].is_face


suit is same within chunks of 4 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 4 == 0:
    return card.suit != mainline[-1].suit
return card.suit == mainline[-1].suit


color is different within chunks of 3 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 3 == 0:
    return card.color == mainline[-1].color
return card.color != mainline[-1].color


suit is different within chunks of 4 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 4 == 0:
    return card.suit == mainline[-1].suit
return card.suit != mainline[-1].suit


color is different within chunks of 5 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 5 == 0:
    return card.color == mainline[-1].color
return card.color != mainline[-1].color


rank is same within chunks of 5 and changes at boundaries

if not mainline:
    return True
if len(mainline) % 5 == 0:
    return card.rank != mainline[-1].rank
return card.rank == mainline[-1].rank


suits repeat in chunks of 4 and rank moves down at boundaries

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.suit != prev.suit and card.rank < prev.rank
return card.suit == prev.suit


suits repeat in chunks of 3 and rank moves down at boundaries

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return card.suit != prev.suit and card.rank < prev.rank
return card.suit == prev.suit


suits repeat in chunks of 2 and rank moves down at boundaries

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 2 == 0:
    return card.suit != prev.suit and card.rank < prev.rank
return card.suit == prev.suit


every 3th position requires higher rank; others require different parity

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return card.rank > prev.rank
return card.rank % 2 != prev.rank % 2


every 4th position requires higher rank; others require different suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.rank > prev.rank
return card.suit != prev.suit


every 3th position requires different suit; others require higher rank

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return card.suit != prev.suit
return card.rank > prev.rank


every 4th position requires lower rank; others require same suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.rank < prev.rank
return card.suit == prev.suit


every 2th position requires different parity; others require different suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 2 == 0:
    return card.rank % 2 != prev.rank % 2
return card.suit != prev.suit


every 2th position requires different suit; others require higher rank

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 2 == 0:
    return card.suit != prev.suit
return card.rank > prev.rank


every 4th position requires different parity; others require same suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.rank % 2 != prev.rank % 2
return card.suit == prev.suit


every 2th position requires lower rank; others require different suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 2 == 0:
    return card.rank < prev.rank
return card.suit != prev.suit


every 2th position requires lower rank; others require same suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 2 == 0:
    return card.rank < prev.rank
return card.suit == prev.suit


every 4th position requires different suit; others require different parity

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.suit != prev.suit
return card.rank % 2 != prev.rank % 2


every 4th position requires different suit; others require higher rank

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return card.suit != prev.suit
return card.rank > prev.rank


every 3th position requires lower rank; others require different suit

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return card.rank < prev.rank
return card.suit != prev.suit


red cards that have different suit relative to previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and card.suit != prev.suit


red cards that have lower rank relative to previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and card.rank < prev.rank


red cards that have different parity relative to previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and card.rank % 2 != prev.rank % 2


black cards that have lower rank relative to previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and card.rank < prev.rank


when red is majority in last 2, require different suit; otherwise opposite color

if len(mainline) < 2:
    return True
count = sum(1 for item in mainline[-2:] if item.color == "red")
prev = mainline[-1]
if count > 1:
    return card.suit != prev.suit
return card.color != prev.color


when red is majority in last 4, require same suit; otherwise opposite color

if len(mainline) < 4:
    return True
count = sum(1 for item in mainline[-4:] if item.color == "red")
prev = mainline[-1]
if count > 2:
    return card.suit == prev.suit
return card.color != prev.color


when black is majority in last 2, require higher rank; otherwise opposite color

if len(mainline) < 2:
    return True
count = sum(1 for item in mainline[-2:] if item.color == "black")
prev = mainline[-1]
if count > 1:
    return card.rank > prev.rank
return card.color != prev.color


when black is majority in last 3, require higher rank; otherwise opposite color

if len(mainline) < 3:
    return True
count = sum(1 for item in mainline[-3:] if item.color == "black")
prev = mainline[-1]
if count > 1:
    return card.rank > prev.rank
return card.color != prev.color


when black is majority in last 2, require same suit; otherwise opposite color

if len(mainline) < 2:
    return True
count = sum(1 for item in mainline[-2:] if item.color == "black")
prev = mainline[-1]
if count > 1:
    return card.suit == prev.suit
return card.color != prev.color


after rank 5 or above require same suit; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 5:
    return card.suit == prev.suit
return card.suit != prev.suit


after rank 8 or above require same color; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 8:
    return card.color == prev.color
return card.suit != prev.suit


after rank 5 or above require lower rank; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 5:
    return card.rank < prev.rank
return card.rank % 2 == prev.rank % 2


after rank 5 or above require different parity; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 5:
    return card.rank % 2 != prev.rank % 2
return card.suit != prev.suit


after rank 10 or above require lower rank; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 10:
    return card.rank < prev.rank
return card.rank % 2 == prev.rank % 2


after rank 8 or above require different parity; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 8:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


after rank 10 or above require different parity; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 10:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


after rank 8 or above require different color; otherwise lower rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 8:
    return card.color != prev.color
return card.rank < prev.rank


after rank 10 or above require same color; otherwise different parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 10:
    return card.color == prev.color
return card.rank % 2 != prev.rank % 2


after rank 8 or above require different parity; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 8:
    return card.rank % 2 != prev.rank % 2
return card.suit != prev.suit


after rank 5 or above require same parity; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 5:
    return card.rank % 2 == prev.rank % 2
return card.color != prev.color


after rank 10 or above require same parity; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 10:
    return card.rank % 2 == prev.rank % 2
return card.color != prev.color


after rank 5 or above require higher rank; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 5:
    return card.rank > prev.rank
return card.color == prev.color


if not mainline:
    return True
return abs(card.rank - mainline[-1].rank) <= 3


if not mainline:
    return True
return abs(card.rank - mainline[-1].rank) <= 6


if not mainline:
    return True
return abs(card.rank - mainline[-1].rank) == 4


same side of rank threshold 3 as previous

if not mainline:
    return True
return (card.rank >= 3) == (mainline[-1].rank >= 3)


different side of rank threshold 9 as previous

if not mainline:
    return True
return (card.rank >= 9) != (mainline[-1].rank >= 9)


same side of rank threshold 6 as previous

if not mainline:
    return True
return (card.rank >= 6) == (mainline[-1].rank >= 6)


same side of rank threshold 4 as previous

if not mainline:
    return True
return (card.rank >= 4) == (mainline[-1].rank >= 4)


suits cycle hearts, diamonds, spades, clubs

if not mainline:
    return True
order = ['hearts', 'diamonds', 'spades', 'clubs']
idx = order.index(mainline[-1].suit)
return card.suit == order[(idx + 1) % 4]


suits cycle hearts, clubs, spades, diamonds

if not mainline:
    return True
order = ['hearts', 'clubs', 'spades', 'diamonds']
idx = order.index(mainline[-1].suit)
return card.suit == order[(idx + 1) % 4]


candidate suit has appeared on the mainline

if not mainline:
    return True
return any(card.suit == item.suit for item in mainline)


candidate rank parity has not appeared on the mainline

if not mainline:
    return True
return all(card.rank % 2 != item.rank % 2 for item in mainline)


candidate follows the majority color in the last 2 accepted cards

if len(mainline) < 2:
    return True
reds = sum(1 for item in mainline[-2:] if item.color == "red")
return (card.color == "red") == (reds >= 1)


candidate follows the minority color in the last 4 accepted cards

if len(mainline) < 4:
    return True
reds = sum(1 for item in mainline[-4:] if item.color == "red")
return (card.color == "red") == (reds < 2)


candidate follows the majority color in the last 3 accepted cards

if len(mainline) < 3:
    return True
reds = sum(1 for item in mainline[-3:] if item.color == "red")
return (card.color == "red") == (reds >= 2)


rank is at most the minimum of the last 4

if len(mainline) < 4:
    return True
recent = [item.rank for item in mainline[-4:]]
return card.rank <= min(recent)


rank is at most the minimum of the last 2

if len(mainline) < 2:
    return True
recent = [item.rank for item in mainline[-2:]]
return card.rank <= min(recent)


if len(mainline) < 4:
    return True
recent = [item.rank for item in mainline[-4:]]
return card.rank < min(recent)


if len(mainline) < 5:
    return True
recent = [item.rank for item in mainline[-5:]]
return card.rank > max(recent)


if len(mainline) < 3:
    return True
recent = [item.rank for item in mainline[-3:]]
return card.rank < min(recent)


if len(mainline) < 2:
    return True
recent = [item.rank for item in mainline[-2:]]
return card.rank > max(recent)


candidate avoids a rank parity from the last 3

if len(mainline) < 3:
    return True
return all(card.rank % 2 != item.rank % 2 for item in mainline[-3:])


candidate avoids a color from the last 4

if len(mainline) < 4:
    return True
return all(card.color != item.color for item in mainline[-4:])


candidate avoids a rank parity from the last 2

if len(mainline) < 2:
    return True
return all(card.rank % 2 != item.rank % 2 for item in mainline[-2:])


candidate repeats a rank parity from the last 4

if len(mainline) < 4:
    return True
return any(card.rank % 2 == item.rank % 2 for item in mainline[-4:])


candidate repeats a rank parity from the last 2

if len(mainline) < 2:
    return True
return any(card.rank % 2 == item.rank % 2 for item in mainline[-2:])


if len(mainline) < 4:
    return True
return all(card.suit != item.suit for item in mainline[-4:])


candidate repeats a face status from the last 3

if len(mainline) < 3:
    return True
return any(card.is_face == item.is_face for item in mainline[-3:])


candidate avoids a color from the last 3

if len(mainline) < 3:
    return True
return all(card.color != item.color for item in mainline[-3:])


candidate avoids a rank parity from the last 4

if len(mainline) < 4:
    return True
return all(card.rank % 2 != item.rank % 2 for item in mainline[-4:])


if not mainline:
    return True
pattern = [1, 0, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 4])


if not mainline:
    return True
pattern = [0, 1, 0, 1, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 6])


if not mainline:
    return True
pattern = [1, 0, 0, 1, 0, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 6])


if not mainline:
    return True
pattern = [1, 0, 0, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 5])


if not mainline:
    return True
pattern = [0, 0, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 4])


if not mainline:
    return True
pattern = [1, 0, 0, 1, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 6])


if not mainline:
    return True
pattern = [1, 0, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 3])


if not mainline:
    return True
pattern = [0, 1, 1, 1, 1]
return (card.color == "red") == bool(pattern[len(mainline) % 5])


if not mainline:
    return True
pattern = [1, 0, 0, 1, 0]
return (card.color == "red") == bool(pattern[len(mainline) % 5])


position cycle over diamonds, clubs, spades, hearts

if not mainline:
    return True
pattern = ['diamonds', 'clubs', 'spades', 'hearts']
return card.suit == pattern[len(mainline) % 4]


position cycle over clubs, spades, hearts

if not mainline:
    return True
pattern = ['clubs', 'spades', 'hearts']
return card.suit == pattern[len(mainline) % 3]


position cycle over hearts, diamonds, clubs

if not mainline:
    return True
pattern = ['hearts', 'diamonds', 'clubs']
return card.suit == pattern[len(mainline) % 3]


position cycle over diamonds, spades, clubs

if not mainline:
    return True
pattern = ['diamonds', 'spades', 'clubs']
return card.suit == pattern[len(mainline) % 3]


position cycle over hearts, clubs, spades

if not mainline:
    return True
pattern = ['hearts', 'clubs', 'spades']
return card.suit == pattern[len(mainline) % 3]


position cycle over spades, hearts, clubs, diamonds

if not mainline:
    return True
pattern = ['spades', 'hearts', 'clubs', 'diamonds']
return card.suit == pattern[len(mainline) % 4]


position cycle over diamonds, spades, hearts, clubs

if not mainline:
    return True
pattern = ['diamonds', 'spades', 'hearts', 'clubs']
return card.suit == pattern[len(mainline) % 4]


position cycle over clubs, spades, hearts, diamonds

if not mainline:
    return True
pattern = ['clubs', 'spades', 'hearts', 'diamonds']
return card.suit == pattern[len(mainline) % 4]


position cycle over diamonds, clubs, spades

if not mainline:
    return True
pattern = ['diamonds', 'clubs', 'spades']
return card.suit == pattern[len(mainline) % 3]


position cycle over spades, hearts, diamonds

if not mainline:
    return True
pattern = ['spades', 'hearts', 'diamonds']
return card.suit == pattern[len(mainline) % 3]


position cycle over clubs, spades, diamonds, hearts

if not mainline:
    return True
pattern = ['clubs', 'spades', 'diamonds', 'hearts']
return card.suit == pattern[len(mainline) % 4]


position cycle over hearts, diamonds, clubs, spades

if not mainline:
    return True
pattern = ['hearts', 'diamonds', 'clubs', 'spades']
return card.suit == pattern[len(mainline) % 4]


position cycle over spades, diamonds, hearts

if not mainline:
    return True
pattern = ['spades', 'diamonds', 'hearts']
return card.suit == pattern[len(mainline) % 3]


position cycle over spades, diamonds, hearts, clubs

if not mainline:
    return True
pattern = ['spades', 'diamonds', 'hearts', 'clubs']
return card.suit == pattern[len(mainline) % 4]


position cycle over clubs, spades, diamonds

if not mainline:
    return True
pattern = ['clubs', 'spades', 'diamonds']
return card.suit == pattern[len(mainline) % 3]


position cycle over clubs, hearts, spades, diamonds

if not mainline:
    return True
pattern = ['clubs', 'hearts', 'spades', 'diamonds']
return card.suit == pattern[len(mainline) % 4]


if not mainline:
    return True
pattern = ['hearts', 'diamonds']
return card.suit == pattern[len(mainline) % 2]


if not mainline:
    return True
pattern = ['clubs', 'diamonds']
return card.suit == pattern[len(mainline) % 2]


position cycle over spades, hearts, diamonds, clubs

if not mainline:
    return True
pattern = ['spades', 'hearts', 'diamonds', 'clubs']
return card.suit == pattern[len(mainline) % 4]


if not mainline:
    return True
pattern = ['hearts', 'spades']
return card.suit == pattern[len(mainline) % 2]


return card.color == "black" and card.rank <= 4


return card.color == "red" and card.rank <= 11


return card.color == "black" and card.rank >= 6


return card.color == "red" and card.rank >= 6


return card.color == "black" and card.rank >= 8


return card.color == "red" and card.rank <= 10


return card.suit == "hearts" and card.rank % 2 == 1


return card.suit == "spades" and card.rank % 2 == 1


return card.suit == "clubs" and card.rank % 2 == 1


color matches within chunks of 5; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 5 == 0:
    return True
return card.color == mainline[-1].color


color matches within chunks of 3 with rank distance at most 5; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 3
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 5


color matches within chunks of 3; last card of each chunk unrestricted [2->1]

if not mainline:
    return True
if (len(mainline)-1) % 3 == 1:
    return True
return card.color == mainline[-1].color


within chunks of 2: same color and rank within 5; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 2 == 0:
    return True
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 5


color matches within chunks of 5; last card of each chunk unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 5 == 2:
    return True
return card.color == mainline[-1].color


rank parity is different within chunks of 5 and matches at boundaries [2->4]

if not mainline:
    return True
if len(mainline) % 5 == 0:
    return card.rank % 4 == mainline[-1].rank % 4
return card.rank % 4 != mainline[-1].rank % 4


color matches within chunks of 4 with rank distance at most 3; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 3


color matches within chunks of 4; last card of each chunk unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 4 == 2:
    return True
return card.color == mainline[-1].color


rank parity is different within chunks of 7 and matches at boundaries

if not mainline:
    return True
if len(mainline) % 7 == 0:
    return card.rank % 2 == mainline[-1].rank % 2
return card.rank % 2 != mainline[-1].rank % 2


color matches within chunks of 2 with rank distance at most 5; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 2
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 5


within chunks of 2: same color and rank within 8; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 2 == 0:
    return True
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 8


within chunks of 3: same color and rank within 6; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 3 == 0:
    return True
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 6


rank parity is different within chunks of 5 and matches at boundaries [2->3]

if not mainline:
    return True
if len(mainline) % 5 == 0:
    return card.rank % 3 == mainline[-1].rank % 3
return card.rank % 3 != mainline[-1].rank % 3


color matches within chunks of 4 with rank distance at most 6; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 6


within chunks of 4: same color and rank within 6; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 4 == 0:
    return True
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 6


within chunks of 2: same color and rank within 7; boundaries unrestricted

if not mainline:
    return True
if (len(mainline)-1) % 2 == 0:
    return True
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 7


color is different within chunks of 7 and matches at their boundaries

if not mainline:
    return True
if len(mainline) % 7 == 0:
    return card.color == mainline[-1].color
return card.color != mainline[-1].color


color matches within chunks of 4 with rank distance at most 7; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 7


color matches within chunks of 6 with rank distance at most 5; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
if phase == 0:
    return card.color != mainline[-1].color
return card.color == mainline[-1].color and abs(card.rank - mainline[-1].rank) <= 5


red rank at least one below previous; black different parity [1->2]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank - 2
return card.rank % 2 != prev.rank % 2


candidate has different rank parity or nondecreasing rank relative to previous [2->3]

if not mainline:
    return True
prev = mainline[-1]
return (card.rank % 3 != prev.rank % 3) or (card.rank >= prev.rank)


different parity or (same color and rank at least previous) [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 3 != prev.rank % 3 or (card.color == prev.color and card.rank >= prev.rank)


different parity or (same color and rank within 1 of previous)

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 1 != prev.rank % 1 or (card.color == prev.color and abs(card.rank - prev.rank) <= 1)


same color or (different parity and rank distance at most 3) [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or (card.rank % 3 != prev.rank % 3 and abs(card.rank - prev.rank) <= 3)


different parity or (same color and rank at least previous) [2->1]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 1 != prev.rank % 1 or (card.color == prev.color and card.rank >= prev.rank)


different parity or (same color and rank at least previous) [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 4 != prev.rank % 4 or (card.color == prev.color and card.rank >= prev.rank)


red rank at least one below previous; black different parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank - 1
return card.rank % 3 != prev.rank % 3


red rank at least one below previous; black different parity [2->1]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank - 1
return card.rank % 1 != prev.rank % 1


different parity or same color or rank distance at most 1

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 1 != prev.rank % 1 or card.color == prev.color or abs(card.rank - prev.rank) <= 1


same color or (different parity and rank distance at most 3) [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or (card.rank % 4 != prev.rank % 4 and abs(card.rank - prev.rank) <= 3)


red nondecreasing; black different parity or rank distance at most 4  [ea@18]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 4 != prev.rank % 4 or abs(card.rank - prev.rank) <= 4


different parity and rank distance at most 3 [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 4 != prev.rank % 4 and abs(card.rank - prev.rank) <= 3


red nondecreasing; black different parity or rank distance at most 3  [ea@18]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 3 != prev.rank % 3 or abs(card.rank - prev.rank) <= 3


different parity or same color or rank distance at most 3

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 3 != prev.rank % 3 or card.color == prev.color or abs(card.rank - prev.rank) <= 3


different parity or same color from previous [2->3]

if not mainline:
    return True
prev=mainline[-1]
return card.rank % 3 != prev.rank % 3 or card.color == prev.color


candidate has different rank parity or nondecreasing rank relative to previous [2->4]

if not mainline:
    return True
prev = mainline[-1]
return (card.rank % 4 != prev.rank % 4) or (card.rank >= prev.rank)


different parity and rank distance at most 5

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 2 != prev.rank % 2 and abs(card.rank - prev.rank) <= 5


different parity and rank distance at most 3 [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 3 != prev.rank % 3 and abs(card.rank - prev.rank) <= 3


different parity or (same color and rank distance at most 1)

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 2 != prev.rank % 2 or (card.color == prev.color and abs(card.rank - prev.rank) <= 1)


red nondecreasing; black different parity or rank distance at most 1  [ea@18]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 1 != prev.rank % 1 or abs(card.rank - prev.rank) <= 1


same color or (different parity and rank distance at most 5)

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or (card.rank % 2 != prev.rank % 2 and abs(card.rank - prev.rank) <= 5)


different parity or (same color and rank within 4 of previous)

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 4 != prev.rank % 4 or (card.color == prev.color and abs(card.rank - prev.rank) <= 4)


different parity or (same color and rank distance at most 3) [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 4 != prev.rank % 4 or (card.color == prev.color and abs(card.rank - prev.rank) <= 3)


red rank at least one below previous; black different parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank - 1
return card.rank % 4 != prev.rank % 4


red rank at least one below previous; black different parity [1->3]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank - 3
return card.rank % 2 != prev.rank % 2


different parity or same color from previous [2->4]

if not mainline:
    return True
prev=mainline[-1]
return card.rank % 4 != prev.rank % 4 or card.color == prev.color


red nondecreasing; black different parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 3 != prev.rank % 3


different parity or (same color and rank distance at most 3) [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.rank % 3 != prev.rank % 3 or (card.color == prev.color and abs(card.rank - prev.rank) <= 3)


red nondecreasing; black different parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 4 != prev.rank % 4


red nondecreasing; black different parity [2->1]

if not mainline:
    return True
prev = mainline[-1]
if card.color == "red":
    return card.rank >= prev.rank
return card.rank % 1 != prev.rank % 1


red -> nondecreasing rank and rank distance at most 4; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank and abs(card.rank - prev.rank) <= 4
return card.color == prev.color


after rank 4 or above require different color; otherwise lower rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 4:
    return card.color != prev.color
return card.rank < prev.rank


even -> same parity; otherwise rank within 4 [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 3 == 0:
    return card.rank % 3 == prev.rank % 3
return abs(card.rank - prev.rank) <= 4


if previous red, different parity; otherwise any [2->1]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 1 != prev.rank % 1
return True


after rank 6 or above require different color; otherwise lower rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 6:
    return card.color != prev.color
return card.rank < prev.rank


red -> same color; else same parity [2->3]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank % 3 == prev.rank % 3


red -> same color; else same parity [2->4]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank % 4 == prev.rank % 4


if previous red, accept red; otherwise same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return True
return card.rank % 3 == prev.rank % 3


red -> nondecreasing rank; otherwise same parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank
return card.rank % 4 == prev.rank % 4


red -> nondecreasing rank; otherwise same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank
return card.rank % 3 == prev.rank % 3


if previous red, different parity; otherwise any [2->4]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 4 != prev.rank % 4
return True


red -> nondecreasing rank and rank distance at most 8; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank and abs(card.rank - prev.rank) <= 8
return card.color == prev.color


red -> same color; otherwise at most one rank below previous [1->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank >= prev.rank - 3


if previous is red, require different parity; otherwise different suit [2->1]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank % 1 != prev.rank % 1
return card.suit != prev.suit


red -> nondecreasing rank and rank distance at most 7; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank and abs(card.rank - prev.rank) <= 7
return card.color == prev.color


if previous red, accept red; otherwise rank within 3 of previous

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return True
return abs(card.rank - prev.rank) <= 3


if previous red, accept red; otherwise rank within 1 of previous

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return True
return abs(card.rank - prev.rank) <= 1


if previous even, require same parity; otherwise any [2->3]

if not mainline:
    return True
if mainline[-1].rank % 3 == 0:
    return card.rank % 3 == mainline[-1].rank % 3
return True


red -> same color; otherwise same color or rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.color == prev.color or abs(card.rank - prev.rank) <= 3


if previous face, require different parity; otherwise any [2->1]

if not mainline:
    return True
if mainline[-1].is_face:
    return card.rank % 1 != mainline[-1].rank % 1
return True


if previous face, require different parity; otherwise any [2->3]

if not mainline:
    return True
if mainline[-1].is_face:
    return card.rank % 3 != mainline[-1].rank % 3
return True


even -> same parity; otherwise different parity [2->3]

if not mainline:
    return True
prev=mainline[-1]
if prev.rank % 3 == 0:
    return card.rank % 3 == prev.rank % 3
return card.rank % 3 != prev.rank % 3


red -> different parity; else lower rank [2->3]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 3 != prev.rank % 3
return card.rank < prev.rank


if previous red, different parity; otherwise any [2->3]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 3 != prev.rank % 3
return True


even -> same parity; otherwise different parity [2->4]

if not mainline:
    return True
prev=mainline[-1]
if prev.rank % 4 == 0:
    return card.rank % 4 == prev.rank % 4
return card.rank % 4 != prev.rank % 4


red -> different parity; else lower rank [2->4]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 4 != prev.rank % 4
return card.rank < prev.rank


even -> same parity; otherwise rank within 3  [floor@100] [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 3 == 0:
    return card.rank % 3 == prev.rank % 3
return abs(card.rank - prev.rank) <= 3


previous red -> same color; otherwise different parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank % 3 != prev.rank % 3


red -> same color; otherwise at most one rank below previous [1->2]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank >= prev.rank - 2


if previous red, accept red; otherwise same parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return True
return card.rank % 4 == prev.rank % 4


previous red -> same color; otherwise different parity [2->1]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank % 1 != prev.rank % 1


red -> different parity; else lower rank [2->1]

if not mainline:
    return True
prev=mainline[-1]
if prev.color == "red":
    return card.rank % 1 != prev.rank % 1
return card.rank < prev.rank


red -> same color; otherwise same color or rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.color == prev.color or abs(card.rank - prev.rank) <= 4


red -> same color; otherwise same color or rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.color == prev.color or abs(card.rank - prev.rank) <= 1


if previous is even, require same parity; otherwise different color [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 4 == 0:
    return card.rank % 4 == prev.rank % 4
return card.color != prev.color


red -> nondecreasing rank and rank distance at most 5; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank and abs(card.rank - prev.rank) <= 5
return card.color == prev.color


red -> nondecreasing rank; otherwise same parity [2->1]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank
return card.rank % 1 == prev.rank % 1


after rank 7 or above require different color; otherwise lower rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 7:
    return card.color != prev.color
return card.rank < prev.rank


if previous is even, require same parity; otherwise different color [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 3 == 0:
    return card.rank % 3 == prev.rank % 3
return card.color != prev.color


even -> same parity; otherwise rank within 4 [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 4 == 0:
    return card.rank % 4 == prev.rank % 4
return abs(card.rank - prev.rank) <= 4


face -> same color; red -> same parity; otherwise any [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color == prev.color
if prev.color == "red":
    return card.rank % 4 == prev.rank % 4
return True


if previous even, require same parity; otherwise any [2->4]

if not mainline:
    return True
if mainline[-1].rank % 4 == 0:
    return card.rank % 4 == mainline[-1].rank % 4
return True


even -> same parity; otherwise rank within 3  [floor@100] [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 4 == 0:
    return card.rank % 4 == prev.rank % 4
return abs(card.rank - prev.rank) <= 3


after rank 3 or above require different color; otherwise lower rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 3:
    return card.color != prev.color
return card.rank < prev.rank


if previous red, accept red; otherwise rank within 4 of previous

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return True
return abs(card.rank - prev.rank) <= 4


if previous is red, require different parity; otherwise different suit [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank % 4 != prev.rank % 4
return card.suit != prev.suit


if previous is red, require different parity; otherwise different suit [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank % 3 != prev.rank % 3
return card.suit != prev.suit


previous red -> same color; otherwise different parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.rank % 4 != prev.rank % 4


face -> same color; red -> same parity; otherwise any [2->3]

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color == prev.color
if prev.color == "red":
    return card.rank % 3 == prev.rank % 3
return True


rank distance at most 6 or same parity or same color [2->4]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 6 or card.rank % 4 == prev.rank % 4 or card.color == prev.color


distance <=3, same color, different parity [2->3]

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 3 and card.color == prev.color and card.rank % 3 != prev.rank % 3


distance <=5, same color, different parity

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 5 and card.color == prev.color and card.rank % 2 != prev.rank % 2


rank differs by exactly 3 or exactly 9 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 3 or d == 9


rank differs by exactly 3 or exactly 6 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 3 or d == 6


rank differs by exactly 4 or exactly 7 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 4 or d == 7


rank distance at most 6 or same parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 6 or card.rank % 4 == prev.rank % 4


rank differs by exactly 4 or exactly 11 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 4 or d == 11


same color or rank distance at most 3 or same parity

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or abs(card.rank - prev.rank) <= 3 or card.rank % 2 == prev.rank % 2


if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color and card.rank % 3 != prev.rank % 3


if not mainline:
    return True
return (card.color == mainline[-1].color) and (card.rank % 4 == mainline[-1].rank % 4)


distance <=3, same color, different parity [2->4]

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 3 and card.color == prev.color and card.rank % 4 != prev.rank % 4


rank differs by exactly 4 or exactly 8 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 4 or d == 8


rank differs by exactly 2 or exactly 8 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 2 or d == 8


rank differs by exactly 5 or exactly 9 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 5 or d == 9


same color or rank distance at most 5 or same parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or abs(card.rank - prev.rank) <= 5 or card.rank % 4 == prev.rank % 4


rank differs by exactly 4 or exactly 10 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 4 or d == 10


if not mainline:
    return True
return abs(card.rank - mainline[-1].rank) == 7


rank differs by exactly 6 or exactly 9 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 6 or d == 9


rank distance <= 3 or same parity [2->4]

if not mainline:
    return True
return abs(card.rank-mainline[-1].rank) <= 3 or card.rank % 4 == mainline[-1].rank % 4


rank distance at most 8 or same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 8 or card.rank % 3 == prev.rank % 3


rank differs by exactly 1 or exactly 8 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 1 or d == 8


distance <= 4 or same parity or same color

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 4 or card.rank % 4 == prev.rank % 4 or card.color == prev.color


if not mainline:
    return True
prev=mainline[-1]
return (abs(card.rank-prev.rank) <= 4 or card.rank % 4 == prev.rank % 4) and card.color == prev.color


if not mainline:
    return True
return (card.color == mainline[-1].color) and (card.rank % 3 == mainline[-1].rank % 3)


if not mainline:
    return True
return abs(card.rank-mainline[-1].rank) <= 5 and card.color == mainline[-1].color


rank distance at most 7 or same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 7 or card.rank % 3 == prev.rank % 3


rank differs by exactly 3 or exactly 10 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 3 or d == 10


rank differs by exactly 2 or exactly 9 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 2 or d == 9


if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color and card.rank % 4 != prev.rank % 4


distance <=1, same color, different parity

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 1 and card.color == prev.color and card.rank % 2 != prev.rank % 2


rank differs by exactly 5 or exactly 8 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 5 or d == 8


rank distance at most 1 or same parity [2->3]

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 1 or card.rank % 3 == prev.rank % 3


rank distance at most 1 or same parity [2->4]

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 1 or card.rank % 4 == prev.rank % 4


same color or rank distance at most 5 or same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or abs(card.rank - prev.rank) <= 5 or card.rank % 3 == prev.rank % 3


if not mainline:
    return True
prev=mainline[-1]
return (abs(card.rank-prev.rank) <= 3 or card.rank % 3 == prev.rank % 3) and card.color == prev.color


rank differs by exactly 3 or exactly 7 from previous

if not mainline:
    return True
prev = mainline[-1]
d = abs(card.rank - prev.rank)
return d == 3 or d == 7


rank distance at most 5 or same parity [2->4]

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 5 or card.rank % 4 == prev.rank % 4


distance <= 3 or same parity or same color

if not mainline:
    return True
prev=mainline[-1]
return abs(card.rank-prev.rank) <= 3 or card.rank % 3 == prev.rank % 3 or card.color == prev.color


rank distance at most 7 or same parity [2->4]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 7 or card.rank % 4 == prev.rank % 4


rank distance at most 6 or same parity [2->3]

if not mainline:
    return True
prev = mainline[-1]
return abs(card.rank - prev.rank) <= 6 or card.rank % 3 == prev.rank % 3


rank distance <= 3 or same parity [2->3]

if not mainline:
    return True
return abs(card.rank-mainline[-1].rank) <= 3 or card.rank % 3 == mainline[-1].rank % 3


candidate parity follows accepted-history majority [2->4]

if not mainline:
    return True
odd = sum(1 for item in mainline if item.rank % 4)
even = len(mainline) - odd
return (card.rank % 4 == 1) == (odd >= even)


candidate parity follows accepted-history majority [1->2]

if not mainline:
    return True
odd = sum(2 for item in mainline if item.rank % 2)
even = len(mainline) - odd
return (card.rank % 2 == 2) == (odd >= even)


when the cumulative accepted-rank sum is 2 modulo 4, require nondecreasing rank; otherwise require nonincreasing rank

if not mainline:
    return True
prev = mainline[-1]
total = sum(item.rank for item in mainline)
if total % 4 == 2:
    return card.rank >= prev.rank
return card.rank <= prev.rank


when the cumulative accepted-rank sum is 1 modulo 3, require nondecreasing rank; otherwise require nonincreasing rank

if not mainline:
    return True
prev = mainline[-1]
total = sum(item.rank for item in mainline)
if total % 3 == 1:
    return card.rank >= prev.rank
return card.rank <= prev.rank


when the cumulative accepted-rank sum is 2 modulo 5, require nondecreasing rank; otherwise require nonincreasing rank

if not mainline:
    return True
prev = mainline[-1]
total = sum(item.rank for item in mainline)
if total % 5 == 2:
    return card.rank >= prev.rank
return card.rank <= prev.rank


candidate parity follows accepted-history majority [2->3]

if not mainline:
    return True
odd = sum(1 for item in mainline if item.rank % 3)
even = len(mainline) - odd
return (card.rank % 3 == 1) == (odd >= even)


rank within 3 of the card two positions back

if not mainline:
    return True
if len(mainline) < 2:
    return True
return abs(card.rank - mainline[-2].rank) <= 3


parity matches either of the last two accepted cards [2->3]

if not mainline:
    return True
recent = mainline[-2:]
return any(card.rank % 3 == item.rank % 3 for item in recent)


candidate parity follows the majority parity of the last three accepted cards [3->1]

if not mainline:
    return True
if len(mainline) < 1:
    return True
recent = mainline[-3:]
odd = sum(1 for item in recent if item.rank % 2)
even = len(recent) - odd
return (card.rank % 2 == 1) == (odd >= even)


rank within 6 of the card two positions back

if not mainline:
    return True
if len(mainline) < 2:
    return True
return abs(card.rank - mainline[-2].rank) <= 6


follow the majority color in the last three accepted cards [1->2]

if not mainline:
    return True
recent=mainline[-3:]
red=sum(2 for item in recent if item.color == "red")
black=len(recent)-red
return card.color == ("red" if red >= black else "black")


parity matches either of the last two accepted cards [2->4]

if not mainline:
    return True
recent = mainline[-2:]
return any(card.rank % 4 == item.rank % 4 for item in recent)


candidate parity follows the majority parity of the last three accepted cards [3->2]

if not mainline:
    return True
if len(mainline) < 2:
    return True
recent = mainline[-3:]
odd = sum(1 for item in recent if item.rank % 2)
even = len(recent) - odd
return (card.rank % 2 == 1) == (odd >= even)


rank within 5 of the card two positions back

if not mainline:
    return True
if len(mainline) < 2:
    return True
return abs(card.rank - mainline[-2].rank) <= 5


face cards impose same suit, number cards require different suit [12->10]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank in (11, 10, 13):
    return card.suit == prev.suit
return card.suit != prev.suit


face cards impose same suit, number cards require different suit [11->9]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank in (9, 12, 13):
    return card.suit == prev.suit
return card.suit != prev.suit


if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 9
if prev_is_face:
    return card.rank <= 10
return card.rank >= 9


alternate face and number cards [11->10]

if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 10
if prev_is_face:
    return card.rank <= 10
return card.rank >= 10


alternate face and number cards [10->12]

if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 11
if prev_is_face:
    return card.rank <= 12
return card.rank >= 11


same color or same rank parity as previous card [2->4]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or (card.rank % 4) == (prev.rank % 4)


same color or same rank parity as previous card [2->3]

if not mainline:
    return True
prev = mainline[-1]
return card.color == prev.color or (card.rank % 3) == (prev.rank % 3)


suits cycle hearts, spades, clubs, diamonds [4->3]

if not mainline:
    return True
order = ["hearts", "spades", "clubs", "diamonds"]
prev_idx = order.index(mainline[-1].suit)
return card.suit == order[(prev_idx + 1) % 3]


if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 11
if prev_is_face:
    return card.rank <= 9
return card.rank >= 11


alternate face and number cards [11->12]

if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 12
if prev_is_face:
    return card.rank <= 10
return card.rank >= 12


alternate face and number cards [11->13]

if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 13
if prev_is_face:
    return card.rank <= 10
return card.rank >= 13


if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 11
if prev_is_face:
    return card.rank <= 8
return card.rank >= 11


face cards impose same suit, number cards require different suit [11->10]

if not mainline:
    return True
prev = mainline[-1]
if prev.rank in (10, 12, 13):
    return card.suit == prev.suit
return card.suit != prev.suit


alternate face and number cards [10->11]

if not mainline:
    return True
prev_is_face = mainline[-1].rank >= 11
if prev_is_face:
    return card.rank <= 11
return card.rank >= 11


suits cycle hearts, spades, clubs, diamonds [1->2]

if not mainline:
    return True
order = ["hearts", "spades", "clubs", "diamonds"]
prev_idx = order.index(mainline[-1].suit)
return card.suit == order[(prev_idx + 2) % 4]


suits cycle hearts, spades, clubs, diamonds [4->2]

if not mainline:
    return True
order = ["hearts", "spades", "clubs", "diamonds"]
prev_idx = order.index(mainline[-1].suit)
return card.suit == order[(prev_idx + 1) % 2]


return card.color == "red" and card.rank <= 5


return card.color == "red" and card.rank <= 9


face cards red, number cards black [11->13]

if card.rank >= 13:
    return card.color == "red"
return card.color == "black"


face cards red, number cards black [11->9]

if card.rank >= 9:
    return card.color == "red"
return card.color == "black"


face cards red, number cards black [11->10]

if card.rank >= 10:
    return card.color == "red"
return card.color == "black"


face cards red, number cards black [11->12]

if card.rank >= 12:
    return card.color == "red"
return card.color == "black"


if card.color == "red":
    return card.rank <= 12
return card.rank >= 7


return (card.color == "red" and 2 <= card.rank <= 6) or (card.color == "black" and 9 <= card.rank <= 13)


even ranks 2-8 or odd ranks 7-12 [8->10]

return (card.rank % 2 == 0 and 2 <= card.rank <= 10) or (card.rank % 2 == 1 and 7 <= card.rank <= 12)


even ranks 2-8 or odd ranks 7-12 [12->10]

return (card.rank % 2 == 0 and 2 <= card.rank <= 8) or (card.rank % 2 == 1 and 7 <= card.rank <= 10)


return (card.color == "red" and 4 <= card.rank <= 6) or (card.color == "black" and 8 <= card.rank <= 13)


even ranks 2,4,4,8 or odd ranks 7,9,11,13

return (card.rank % 2 == 0 and card.rank in {2, 4, 4, 8}) or (card.rank % 2 == 1 and card.rank in {7, 9, 11, 13})


return (card.rank % 2 == 0 and 2 <= card.rank <= 8) or (card.rank % 2 == 1 and 5 <= card.rank <= 12)


red ranks 3-7 or black ranks 9-13 [7->8]

return (card.color == "red" and 3 <= card.rank <= 8) or (card.color == "black" and 9 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 11
return card.rank >= 7


return (card.rank % 2 == 0 and 5 <= card.rank <= 8) or (card.rank % 2 == 1 and 7 <= card.rank <= 13)


red ranks 3-7 or black ranks 9-13 [7->6]

return (card.color == "red" and 3 <= card.rank <= 6) or (card.color == "black" and 9 <= card.rank <= 13)


return (card.rank % 4 == 0 and 4 <= card.rank <= 8) or (card.rank % 4 == 1 and 7 <= card.rank <= 12)


red ranks 3-7 or black ranks 9-13 [13->11]

return (card.color == "red" and 3 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 11)


return card.color == "black" and card.rank >= 7


return (card.color == "red" and 5 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 10
return card.rank >= 8


if card.color == "red":
    return card.rank <= 8
return card.rank >= 3


even ranks 2,4,6,10 or odd ranks 7,9,11,13

return (card.rank % 2 == 0 and card.rank in {2, 4, 6, 10}) or (card.rank % 2 == 1 and card.rank in {7, 9, 11, 13})


red ranks 2-6 or black ranks 8-13 [13->11]

return (card.color == "red" and 2 <= card.rank <= 6) or (card.color == "black" and 8 <= card.rank <= 11)


return card.color == "black" and card.rank >= 3


return (card.rank % 2 == 0 and 2 <= card.rank <= 6) or (card.rank % 2 == 1 and 7 <= card.rank <= 12)


if card.color == "red":
    return card.rank <= 10
return card.rank >= 6


return (card.rank % 2 == 0 and 3 <= card.rank <= 8) or (card.rank % 2 == 1 and 5 <= card.rank <= 13)


return (card.rank % 2 == 0 and 2 <= card.rank <= 6) or (card.rank % 2 == 1 and 7 <= card.rank <= 13)


return (card.color == "red" and 3 <= card.rank <= 6) or (card.color == "black" and 8 <= card.rank <= 13)


return (card.color == "red" and 2 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 13)


return card.rank in [2, 1, 4, 5, 6, 8, 9]


if card.color == "red":
    return card.rank <= 7
return card.rank >= 5


if card.color == "red":
    return card.rank <= 6
return card.rank >= 5


even ranks 2,4,6,8 or odd ranks 5,9,11,13

return (card.rank % 2 == 0 and card.rank in {2, 4, 6, 8}) or (card.rank % 2 == 1 and card.rank in {5, 9, 11, 13})


return (card.rank % 4 == 0 and 3 <= card.rank <= 8) or (card.rank % 4 == 1 and 7 <= card.rank <= 13)


red ranks 2-6 or black ranks 8-13 [6->5]

return (card.color == "red" and 2 <= card.rank <= 5) or (card.color == "black" and 8 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 9
return card.rank >= 7


return (card.rank % 3 == 0 and 3 <= card.rank <= 8) or (card.rank % 3 == 1 and 7 <= card.rank <= 13)


return (card.color == "red" and 3 <= card.rank <= 7) or (card.color == "black" and 11 <= card.rank <= 13)


red ranks 2-6 or black ranks 8-13 [13->12]

return (card.color == "red" and 2 <= card.rank <= 6) or (card.color == "black" and 8 <= card.rank <= 12)


return (card.rank % 3 == 0 and 3 <= card.rank <= 8) or (card.rank % 3 == 1 and 7 <= card.rank <= 12)


red ranks 2-6 or black ranks 8-13 [6->7]

return (card.color == "red" and 2 <= card.rank <= 7) or (card.color == "black" and 8 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 8
return card.rank >= 7


return (card.rank % 2 == 0 and 2 <= card.rank <= 8) or (card.rank % 2 == 1 and 8 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 10
return card.rank >= 9


red ranks 2-6 or black ranks 8-13 [6->4]

return (card.color == "red" and 2 <= card.rank <= 4) or (card.color == "black" and 8 <= card.rank <= 13)


return (card.rank % 2 == 0 and 2 <= card.rank <= 8) or (card.rank % 2 == 1 and 8 <= card.rank <= 12)


even ranks 3-8 or odd ranks 7-13 [13->11]

return (card.rank % 2 == 0 and 3 <= card.rank <= 8) or (card.rank % 2 == 1 and 7 <= card.rank <= 11)


return (card.rank % 2 == 0 and 3 <= card.rank <= 8) or (card.rank % 2 == 1 and 8 <= card.rank <= 13)


even ranks 2,4,6,8 or odd ranks 7,9,9,13

return (card.rank % 2 == 0 and card.rank in {2, 4, 6, 8}) or (card.rank % 2 == 1 and card.rank in {7, 9, 9, 13})


return (card.color == "red" and 1 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 13)


even ranks 2-8 or odd ranks 7-13 [8->10]

return (card.rank % 2 == 0 and 2 <= card.rank <= 10) or (card.rank % 2 == 1 and 7 <= card.rank <= 13)


return (card.rank % 2 == 0 and 3 <= card.rank <= 6) or (card.rank % 2 == 1 and 7 <= card.rank <= 13)


return card.rank in [2, 2, 4, 5, 6, 8, 9]


even ranks 1,4,6,8 or odd ranks 7,9,11,13

return (card.rank % 1 == 0 and card.rank in {1, 4, 6, 8}) or (card.rank % 1 == 1 and card.rank in {7, 9, 11, 13})


even ranks 3-8 or odd ranks 7-13 [8->10]

return (card.rank % 2 == 0 and 3 <= card.rank <= 10) or (card.rank % 2 == 1 and 7 <= card.rank <= 13)


return (card.rank % 2 == 0 and 2 <= card.rank <= 8) or (card.rank % 2 == 1 and 5 <= card.rank <= 13)


even ranks 3,4,6,8 or odd ranks 7,9,11,13

return (card.rank % 3 == 0 and card.rank in {3, 4, 6, 8}) or (card.rank % 3 == 1 and card.rank in {7, 9, 11, 13})


red ranks 3-7 or black ranks 9-13 [13->12]

return (card.color == "red" and 3 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 12)


if card.color == "red":
    return card.rank <= 9
return card.rank >= 5


even ranks 2,4,6,8 or odd ranks 7,7,11,13

return (card.rank % 2 == 0 and card.rank in {2, 4, 6, 8}) or (card.rank % 2 == 1 and card.rank in {7, 7, 11, 13})


return (card.color == "red" and 3 <= card.rank <= 7) or (card.color == "black" and 8 <= card.rank <= 13)


return (card.color == "red" and 4 <= card.rank <= 7) or (card.color == "black" and 9 <= card.rank <= 13)


rank modulo 7 requires red on residues [0] and black otherwise

red_residues = [0]
return (card.color == "red") == (card.rank % 7 in red_residues)


even ranks 2,2,6,8 or odd ranks 7,9,11,13

return (card.rank % 2 == 0 and card.rank in {2, 2, 6, 8}) or (card.rank % 2 == 1 and card.rank in {7, 9, 11, 13})


rank modulo 8 requires red on residues [0] and black otherwise

red_residues = [0]
return (card.color == "red") == (card.rank % 8 in red_residues)


return (card.color == "red" and 2 <= card.rank <= 6) or (card.color == "black" and 10 <= card.rank <= 13)


return (card.color == "red" and 2 <= card.rank <= 6) or (card.color == "black" and 7 <= card.rank <= 13)


return (card.color == "red" and 3 <= card.rank <= 7) or (card.color == "black" and 10 <= card.rank <= 13)


if card.color == "red":
    return card.rank <= 10
return card.rank >= 5


red ranks 3-7 or black ranks 9-13 [7->5]

return (card.color == "red" and 3 <= card.rank <= 5) or (card.color == "black" and 9 <= card.rank <= 13)


rank modulo 5 requires red on residues [0] and black otherwise

red_residues = [0]
return (card.color == "red") == (card.rank % 5 in red_residues)


suit matches within chunks of 7; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit
return card.suit == prev.suit


parity matches within chunks of 5; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


suit matches within chunks of 8; rank within 6 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


suit matches within chunks of 8; rank within 3 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


suit matches within chunks of 6; rank within 5 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


suit matches within chunks of 5; rank within 6 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


suit matches within chunks of 7; rank within 4 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 4
return card.suit == prev.suit


suit matches within chunks of 5; rank within 4 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 4
return card.suit == prev.suit


suit matches within chunks of 7; rank within 7 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 7
return card.suit == prev.suit


suit matches within chunks of 8; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit
return card.suit == prev.suit


suit matches within chunks of 6; rank within 3 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


suit matches within chunks of 4; rank within 4 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 4
return card.suit == prev.suit


parity matches within chunks of 4; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


suit matches within chunks of 7; rank within 5 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


suit matches within chunks of 4; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit
return card.suit == prev.suit


parity matches within chunks of 8; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


suit matches within chunks of 6; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit
return card.suit == prev.suit


suit matches within chunks of 6; rank within 7 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 7
return card.suit == prev.suit


suit matches within chunks of 8; rank within 4 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 4
return card.suit == prev.suit


color matches within chunks of 8; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.color != prev.color
return card.color == prev.color


suit matches within chunks of 6; rank within 6 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


parity matches within chunks of 7; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


suit matches within chunks of 5; rank within 5 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


suit matches within chunks of 5; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit
return card.suit == prev.suit


suit matches within chunks of 5; rank within 7 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 7
return card.suit == prev.suit


parity matches within chunks of 6; alternates at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.rank % 2 != prev.rank % 2
return card.rank % 2 == prev.rank % 2


suit matches within chunks of 4; rank within 7 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 7
return card.suit == prev.suit


suit matches within chunks of 7; rank within 6 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


suit matches within chunks of 4; rank within 3 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


suit matches within chunks of 6; rank within 4 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 6
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 4
return card.suit == prev.suit


suit matches within chunks of 8; rank within 5 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


suit matches within chunks of 4; rank within 6 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


suit matches within chunks of 5; rank within 3 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 5
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


suit matches within chunks of 8; rank within 7 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 8
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 7
return card.suit == prev.suit


suit matches within chunks of 4; rank within 5 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 4
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


suit matches within chunks of 7; rank within 3 at boundaries

if not mainline:
    return True
phase = (len(mainline)-1) % 7
prev = mainline[-1]
if phase == 0:
    return card.suit != prev.suit and abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


black cards with rank distance at most 3 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and abs(card.rank - prev.rank) <= 3


red cards with rank distance at most 4 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and abs(card.rank - prev.rank) <= 4


red cards with rank distance at most 5 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and abs(card.rank - prev.rank) <= 5


every 3-boundary requires rank distance at most 3; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return abs(card.rank - prev.rank) <= 3
return card.color != prev.color


red cards with rank distance at most 3 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and abs(card.rank - prev.rank) <= 3


every 5-boundary requires rank distance at most 3; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 5 == 0:
    return abs(card.rank - prev.rank) <= 3
return card.color != prev.color


every 3-boundary requires rank distance at most 4; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.color != prev.color


red cards with rank distance at most 2 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and abs(card.rank - prev.rank) <= 2


every 4-boundary requires rank distance at most 4; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.color != prev.color


red cards with rank distance at most 6 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "red" and abs(card.rank - prev.rank) <= 6


every 4-boundary requires rank distance at most 2; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return abs(card.rank - prev.rank) <= 2
return card.color != prev.color


every 5-boundary requires rank distance at most 2; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 5 == 0:
    return abs(card.rank - prev.rank) <= 2
return card.color != prev.color


black cards with rank distance at most 5 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and abs(card.rank - prev.rank) <= 5


black cards with rank distance at most 6 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and abs(card.rank - prev.rank) <= 6


black cards with rank distance at most 2 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and abs(card.rank - prev.rank) <= 2


every 5-boundary requires rank distance at most 4; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 5 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.color != prev.color


black cards with rank distance at most 4 of previous

if not mainline:
    return True
prev = mainline[-1]
return card.color == "black" and abs(card.rank - prev.rank) <= 4


every 4-boundary requires rank distance at most 3; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 4 == 0:
    return abs(card.rank - prev.rank) <= 3
return card.color != prev.color


every 3-boundary requires rank distance at most 2; otherwise opposite color

if not mainline:
    return True
prev = mainline[-1]
if len(mainline) % 3 == 0:
    return abs(card.rank - prev.rank) <= 2
return card.color != prev.color


even prev -> rank within 6; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 6
return card.color == prev.color


even prev -> nondecreasing; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank >= prev.rank
return card.suit == prev.suit


red -> rank within 2; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 2
return card.rank > prev.rank


even prev -> rank within 4; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 4
return abs(card.rank - prev.rank) <= 3


high prev -> rank within 3; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 3
return card.rank >= prev.rank


red -> rank within 2; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 1


face prev -> rank within 6; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 6
return abs(card.rank - prev.rank) <= 1


red -> rank within 4; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 4
return card.color == prev.color


even prev -> nondecreasing; otherwise opposite parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank >= prev.rank
return card.rank % 2 != prev.rank % 2


even prev -> same color; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.color == prev.color
return abs(card.rank - prev.rank) <= 4


red -> rank within 6; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


face prev -> different color; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color != prev.color
return card.rank > prev.rank


red -> rank within 4; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 4
return card.rank < prev.rank


even prev -> same parity; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank % 2 == prev.rank % 2
return abs(card.rank - prev.rank) <= 5


high prev -> rank within 4; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 4
return card.suit != prev.suit


high prev -> same parity; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 == prev.rank % 2
return abs(card.rank - prev.rank) <= 4


even prev -> different color; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.color != prev.color
return abs(card.rank - prev.rank) <= 2


red -> rank within 1; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 1
return card.suit != prev.suit


even prev -> rank within 6; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 6
return card.color != prev.color


face prev -> rank within 5; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 5
return card.suit != prev.suit


red -> same parity; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank % 2 == prev.rank % 2
return card.rank >= prev.rank


even prev -> higher rank; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank > prev.rank
return card.rank < prev.rank


face prev -> decreasing; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank < prev.rank
return abs(card.rank - prev.rank) <= 2


high prev -> rank within 3; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 3
return card.color != prev.color


face prev -> nondecreasing; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 5


even prev -> rank within 3; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 3
return card.suit != prev.suit


high prev -> rank within 6; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 6
return card.color != prev.color


red -> rank within 5; otherwise opposite parity

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 5
return card.rank % 2 != prev.rank % 2


even prev -> rank within 4; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.rank < prev.rank


even prev -> rank within 3; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 3
return abs(card.rank - prev.rank) <= 2


face prev -> rank within 5; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 5
return abs(card.rank - prev.rank) <= 4


face prev -> rank within 3; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 3
return card.suit == prev.suit


face prev -> rank within 6; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 6
return card.color == prev.color


red -> decreasing; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank < prev.rank
return abs(card.rank - prev.rank) <= 1


even prev -> different suit; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.suit != prev.suit
return card.rank > prev.rank


even prev -> rank within 6; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 6
return card.suit == prev.suit


high prev -> rank within 5; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 5
return card.suit == prev.suit


even prev -> rank within 1; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 1
return card.rank > prev.rank


even prev -> rank within 4; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.color == prev.color


high prev -> rank within 2; otherwise rank within 6

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 6


face prev -> higher rank; otherwise rank within 6

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank > prev.rank
return abs(card.rank - prev.rank) <= 6


face prev -> rank within 6; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 6
return abs(card.rank - prev.rank) <= 4


even prev -> rank within 4; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 4
return card.rank > prev.rank


face prev -> rank within 1; otherwise opposite parity

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 1
return card.rank % 2 != prev.rank % 2


high prev -> rank within 4; otherwise rank within 6

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 4
return abs(card.rank - prev.rank) <= 6


red -> rank within 3; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 3
return card.color == prev.color


even prev -> rank within 3; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 3
return card.color == prev.color


face prev -> different color; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color != prev.color
return abs(card.rank - prev.rank) <= 1


face prev -> rank within 3; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 3
return abs(card.rank - prev.rank) <= 1


face prev -> same color; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color == prev.color
return card.rank < prev.rank


high prev -> different color; otherwise opposite parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.color != prev.color
return card.rank % 2 != prev.rank % 2


red -> different color; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color != prev.color
return card.rank < prev.rank


even prev -> nondecreasing; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 3


high prev -> same parity; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 == prev.rank % 2
return card.color != prev.color


face prev -> nondecreasing; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 3


high prev -> same color; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.color == prev.color
return card.suit != prev.suit


even prev -> rank within 2; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 3


high prev -> decreasing; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank < prev.rank
return card.rank >= prev.rank


high prev -> rank within 3; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 3
return card.color == prev.color


red -> decreasing; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank < prev.rank
return abs(card.rank - prev.rank) <= 4


high prev -> opposite parity; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 != prev.rank % 2
return card.rank >= prev.rank


face prev -> rank within 6; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 6
return abs(card.rank - prev.rank) <= 5


even prev -> different color; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.color != prev.color
return card.rank >= prev.rank


high prev -> opposite parity; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 != prev.rank % 2
return card.rank > prev.rank


high prev -> rank within 5; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 5
return abs(card.rank - prev.rank) <= 2


high prev -> different color; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.color != prev.color
return card.rank < prev.rank


face prev -> nondecreasing; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 4


high prev -> rank within 1; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 1
return abs(card.rank - prev.rank) <= 3


high prev -> higher rank; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank > prev.rank
return card.rank >= prev.rank


face prev -> rank within 2; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 2
return card.rank < prev.rank


even prev -> rank within 5; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 5
return card.rank < prev.rank


red -> same color; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.color == prev.color
return card.color != prev.color


red -> rank within 5; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 5
return card.rank < prev.rank


high prev -> rank within 1; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 1
return card.rank % 2 == prev.rank % 2


even prev -> higher rank; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank > prev.rank
return abs(card.rank - prev.rank) <= 1


high prev -> rank within 4; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 4
return card.rank >= prev.rank


face prev -> rank within 3; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 3
return card.suit != prev.suit


red -> rank within 1; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 1
return card.suit == prev.suit


red -> nondecreasing; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank
return card.suit != prev.suit


face prev -> rank within 3; otherwise opposite parity

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 3
return card.rank % 2 != prev.rank % 2


high prev -> nondecreasing; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 5


face prev -> rank within 1; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 1
return card.color == prev.color


face prev -> same suit; otherwise rank within 6

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.suit == prev.suit
return abs(card.rank - prev.rank) <= 6


face prev -> rank within 1; otherwise same suit

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 1
return card.suit == prev.suit


even prev -> different suit; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.suit != prev.suit
return card.color == prev.color


face prev -> different color; otherwise same color

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.color != prev.color
return card.color == prev.color


even prev -> rank within 2; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 1


even prev -> rank within 6; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 6
return abs(card.rank - prev.rank) <= 1


red -> rank within 1; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 1
return abs(card.rank - prev.rank) <= 4


face prev -> rank within 1; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 1
return card.color != prev.color


red -> rank within 5; otherwise higher rank

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 5
return card.rank > prev.rank


even prev -> same color; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.color == prev.color
return card.rank % 2 == prev.rank % 2


face prev -> higher rank; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank > prev.rank
return abs(card.rank - prev.rank) <= 2


red -> rank within 2; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 4


red -> nondecreasing; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank >= prev.rank
return card.color != prev.color


face prev -> rank within 6; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 6
return card.rank < prev.rank


high prev -> decreasing; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank < prev.rank
return card.suit != prev.suit


high prev -> same color; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.color == prev.color
return abs(card.rank - prev.rank) <= 5


even prev -> nondecreasing; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank >= prev.rank
return abs(card.rank - prev.rank) <= 5


red -> same parity; otherwise rank within 1

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.rank % 2 == prev.rank % 2
return abs(card.rank - prev.rank) <= 1


face prev -> nondecreasing; otherwise same parity

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank >= prev.rank
return card.rank % 2 == prev.rank % 2


even prev -> decreasing; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.rank < prev.rank
return abs(card.rank - prev.rank) <= 4


high prev -> nondecreasing; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank >= prev.rank
return card.color != prev.color


face prev -> rank within 1; otherwise rank within 4

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 1
return abs(card.rank - prev.rank) <= 4


face prev -> opposite parity; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.rank % 2 != prev.rank % 2
return abs(card.rank - prev.rank) <= 5


face prev -> rank within 2; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 2
return card.suit != prev.suit


high prev -> same color; otherwise nondecreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.color == prev.color
return card.rank >= prev.rank


face prev -> different suit; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return card.suit != prev.suit
return abs(card.rank - prev.rank) <= 5


even prev -> rank within 5; otherwise different color

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return abs(card.rank - prev.rank) <= 5
return card.color != prev.color


high prev -> rank within 6; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 6
return abs(card.rank - prev.rank) <= 3


even prev -> same color; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank % 2 == 0:
    return card.color == prev.color
return card.suit != prev.suit


high prev -> same parity; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 == prev.rank % 2
return abs(card.rank - prev.rank) <= 3


face prev -> rank within 2; otherwise rank within 3

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 2
return abs(card.rank - prev.rank) <= 3


high prev -> rank within 3; otherwise different suit

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return abs(card.rank - prev.rank) <= 3
return card.suit != prev.suit


red -> different suit; otherwise rank within 5

if not mainline:
    return True
prev = mainline[-1]
if prev.color == "red":
    return card.suit != prev.suit
return abs(card.rank - prev.rank) <= 5


high prev -> opposite parity; otherwise rank within 2

if not mainline:
    return True
prev = mainline[-1]
if prev.rank >= 9:
    return card.rank % 2 != prev.rank % 2
return abs(card.rank - prev.rank) <= 2


face prev -> rank within 3; otherwise decreasing

if not mainline:
    return True
prev = mainline[-1]
if prev.is_face:
    return abs(card.rank - prev.rank) <= 3
return card.rank < prev.rank