RegexWars
Tier 2 · Archmagematch

Rook Check

Does a white rook attack the black king along a rank or a file? Any piece standing between them blocks it.

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. This is the first one where the squares in between matter. Along a rank the rook and king sit in the same row, so every character between them has to be an empty square — and the # padding conveniently makes it impossible to run off the end of a rank by accident. Down a file they are some multiple of 15 apart, and only every fifteenth character has to be empty. The rook may be on either side of the king.

Your pattern0 chars · par 51
//
Flags
Start typing — tests run as you go.0 of 6 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..R..#######
    ........#######
    ........#######
    ........#######
    ........
    must match

    along the rank, clear

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

    along the rank from the left

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

    down the file, clear

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

    a bishop is in the way

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

    a pawn blocks the file

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

    a diagonal is not a rook line

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