This challenge requires a small amount of knowledge about chess. A description of the details required can be found at the bottom if you are not familiar with chess or want a refresher.
For a certain board configuration consisting only of queens we can say that each queens threat number is the number of other queens it threatens.
Here is an example board with each queen labeled by their threat number:
. . . . . . . .
. . . . . . . .
. . . 2 . . . .
. . . . . . . .
. . . . . . . .
. 2 . 3 . . 2 .
. 1 . . . . . .
. . . . . . . 0
A board is at a peaceful standoff if every queen can only attack other queens with the same threat number as themselves.
For example:
. . . . . . . .
. . . . . . . .
. 2 . 2 . . . .
. . . . . . . .
. . . . . . . .
. 2 . 2 . . . .
. . . . . . . .
. . . . . . . .
Each queen can attack 2 others so it's a peaceful standoff.
As another example:
3 . . . . . . 3
. . . . . . . .
. 1 . . . . 1 .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
3 . . . . . . 3
Here not all queens have the same threat number. Some threaten 3 others and some only threaten 1 other. However none of the 3
s threaten a 1
(or vice versa) so it's peaceful.
Task
You will take as input a chessboard and output whether it is a peaceful standoff. You may assume the input board is always the standard chess size of 8 units by 8 units and you may take it as a list of list of booleans, a list of piece locations or any other reasonable format.
You may not require the threat numbers to be pre-calculated in the input. They are shown in the above examples but they are not a part of the input.
You should output one of two consistent distinct values. One when the input is a peaceful standoff and the other when it is not.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
Test cases
False
. . . . . . . .
. . . . . . . .
. . . Q . . . .
. . . . . . . .
. . . . . . . .
. Q . Q . . Q .
. Q . . . . . .
. . . . . . . Q
. . . . . . . .
. Q . Q . Q . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
True
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . Q . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . Q . . . .
. . . . . . . .
. . . . . . . .
. Q . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . Q Q . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. Q . Q . . . .
. . . . . . . .
. . . . . . . .
. Q . Q . . . .
. . . . . . . .
. . . . . . . .
Q . . . . . . Q
. . . . . . . .
. Q . . . . Q .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
Q . . . . . . Q
Q . . . . . . Q
. . Q . . Q . .
. Q . . Q . Q .
. . Q . . . . .
. . . . . Q . .
. Q . Q . . Q .
. . Q . . Q . .
Q . . . . . . Q
Chess
Chess is a game played on an 8 by 8 square grid. Each location on the grid can have up to 1 piece. One such piece is the "queen". Queens can attack any piece that's located in the same row, column, or diagonal as they are, so long as there's not another piece between them an their target. If a piece can attack a piece it is considered to "threaten" that piece.