RegexWars
Tier 1 · Sorcerermatch

Is The King In Check?

The boss. Is the black king attacked by anything at all — pawn, knight, bishop, rook, queen or the white king?

The whole board is one line. Squares run row-major from the top-left, an empty one is a dot, and between rows sit seven # — one fewer than the board is wide — so a diagonal or a knight jump that runs off the side lands on padding instead of wrapping onto the next rank. The black king is k; white pieces are uppercase P N B R Q K. The first row is rank 8, so white advances towards the start of the string. One square right is +1 and one square down is +15; every other offset you need is built from those two. Every piece at once. The pawn is the asymmetric one: white advances towards the start of the string, so a white pawn checks only from below the king — one above it is attacking the other way. Knights ignore blockers entirely. Bishops, rooks and queens are stopped by the first piece on the ray, whichever colour. The white king attacks all eight of its neighbours. And any of them may sit before or after the k in the string, so every case needs both directions.

Your pattern0 chars · par 265
//
Flags
Start typing — tests run as you go.0 of 9 visible tests passing
Test cases

Wrapped into rows of 8 so you can see the board. The string itself is one line with no line breaks in it — the 7 # between rows are ordinary characters, and a dot will happily match straight past them.

  • ........#######
    ........#######
    ....k...#######
    ...P....#######
    ........#######
    ........#######
    ........#######
    ........
    must match

    pawn

  • ........#######
    ........#######
    ........#######
    ..N.....#######
    ....k...#######
    ........#######
    ........#######
    ........
    must match

    knight

  • ........#######
    ....k...#######
    ........#######
    ........#######
    ........#######
    ....R...#######
    ........#######
    ........
    must match

    rook down the file

  • ........#######
    ........#######
    ..k.....#######
    ........#######
    ....B...#######
    ........#######
    ........#######
    ........
    must match

    bishop

  • ........#######
    .Q......#######
    ........#######
    ...k....#######
    ........#######
    ........#######
    ........#######
    ........
    must match

    queen on the diagonal

  • ........#######
    ........#######
    ........#######
    ........#######
    ....kK..#######
    ........#######
    ........#######
    ........
    must match

    the white king itself

  • ........#######
    ........#######
    ..P.P...#######
    ...k....#######
    ........#######
    ........#######
    ........#######
    ........
    must not match

    pawns above the king attack away from it

  • ........#######
    ....k...#######
    ........#######
    ....P...#######
    ........#######
    ....R...#######
    ........#######
    ........
    must not match

    the rook is blocked

  • k.......#######
    ........#######
    ........#######
    ........#######
    ........#######
    ........#######
    ........#######
    ..N..B.R
    must not match

    nothing in range

+ 26 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.