Inspired by a discussion from the Esolangs.org unofficial Discord Server.
Instructions
A chess cycle is an arrangement of a chess board where each piece must attack one other piece, and only one other piece, and each piece is attacked exactly once.
The effective idea to to "connect" pieces with each other, forming a single cyclic chain. Here is a board example:
You will only be given boards with Knights, Rooks and Bishops.
Your submission must take a chess board in any valid format(string, list of strings, 2D array, list of piece positions, FEN, ...) and output a truthy or falsy value for whether the board represents a valid cycle or not.
Testcases
To create your own testcases, create your board here, copy the FEN box contents, and use as input here.
FEN: 8/2B5/8/1N6/5N2/3B4/8/8
, lichess
Board:
........
..B.....
........
.N......
.....N..
...B....
........
........
Output: True
(In the illustration)
FEN: 8/8/8/3R4/8/8/8/8
, lichess
Board:
........
........
........
...R....
........
........
........
........
Output: False
(Rook cannot attack self)
FEN: 1R4B1/3N4/3N4/3N1B2/8/2B2N2/4R1BB/R1N5
, lichess
Board:
.R....B.
...N....
...N....
...N.B..
........
..B..N..
....R.BB
R.N.....
Output: True
FEN: 6B1/4N2N/5B2/8/8/6B1/4N2N/5B2
, lichess
Board:
......B.
....N..N
.....B..
........
........
......B.
....N..N
.....B..
Output: False
(Multiple Cycles)
FEN: 8/6R1/8/5R1N/3N4/8/5BB1/7N
, lichess
Board:
........
......R.
........
.....R.N
...N....
........
.....BB.
.......N
Output: False
(Rook on f5 attacks two pieces)
FEN: 8/8/8/8/8/8/8/8
, lichess(tsh)
Board:
........
........
........
........
........
........
........
........
Output: False
(No pieces for a cycle)
FEN: 8/8/8/2R2R2/8/8/8/8
, lichess(tsh)
Board:
........
........
........
..R..R..
........
........
........
........
Output: True
(Two connected rooks, single cycle)
FEN: 8/8/8/1R3B2/8/3R2N1/8/8
, lichess(Robin Ryder)
Board:
........
........
........
.R...B..
........
...R..N.
........
........
Output: False
Other Info
- You may represent the pieces and empty squares as any number or character, as long as it is consistent.
- Given boards will always be 8x8 and valid i.e. not containing any invalid characters.
8/8/8/8/8/8/8/8
;8/8/8/2R2R2/8/8/8/8
. \$\endgroup\$(piece type, a value representing the position)
? \$\endgroup\$