RegexWars
Tier 3 · Warlockmatch

Knight Check

Does a white knight attack the black king? Eight fixed jumps, and nothing can block a knight.

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. A knight moves two squares one way and one the other, which in this encoding is four distances — each of them usable in either direction, because the knight may sit before or after the king in the string. Work the numbers out from +1 and +15 rather than guessing.

Your pattern0 chars · par 57
//
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...#######
    ..N.....#######
    ........#######
    ........#######
    ........#######
    ........
    must match

    one row down, two files left

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

    one row up, two files left

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

    two rows down, one file right

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

    diagonally adjacent is not a knight move

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

    two rows straight down is not either

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

    nowhere near

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