| Bytes | Lang | Time | Link |
|---|---|---|---|
| 051 | Ruby | 240903T171825Z | Jordan |
| 050 | Pari/GP | 220105T035059Z | alephalp |
| 032 | Charcoal | 220105T215950Z | Neil |
| 040 | R | 220104T234323Z | Dominic |
| 048 | Perl 5 | 220105T100916Z | Kjetil S |
| 032 | Retina 0.8.2 | 220105T105613Z | Neil |
| nan | J | 220104T203508Z | Jonah |
| 066 | JavaScript Node.js | 220105T020503Z | tsh |
| 043 | Factor | 220104T233939Z | chunes |
| 009 | Jelly | 220104T194818Z | caird co |
| 034 | Python | 220104T193143Z | loopy wa |
| 245 | Python3 | 220104T200856Z | Ajax1234 |
Pari/GP, 50 bytes
a->sum(n=0,1,!matrix(8,,i,j,(i+j+n+t=a[i,j])%2*t))
Takes input as an 8x8 matrix of 0s (empty), 1s (black), 2s (white).
Charcoal, 32 bytes
F²⊞υ⟦⟧F⁸UMS⊞O§υ⁺ιλ⁻№ακ№βκ⊙υ×⌈ι⌊ι
Try it online! Takes input as a board and outputs nothing for a reverse draughts position and - if not. Explanation:
F²⊞υ⟦⟧
Start collecting the colour of pieces on squares of each colour.
F⁸
Loop over the rows.
UMS⊞O§υ⁺ιλ⁻№ακ№βκ
Push 1, 0, or -1 to the appropriate square colour list depending on the colour of the piece or 0 if there is no piece.
⊙υ×⌈ι⌊ι
See whether any square colours contain pieces of both colours. Since there can only be 15 pieces of the same colour on squares of one colour, there will be at least one zero in the array, but this will not be the minimum or the maximum if this is not a reverse draughts position.
R, 68 50 40 bytes
function(x)sd((z=rbind(x,0)*.5:-1)[!!z])
Input is 8x8 matrix with 1s and -1s representing black and white pieces (or the other way around), and 0s representing empty positions. Outputs zero (falsy) for not-reverse-checkers positions, non-zero (truthy) for reverse-checkers positions (or +2 bytes for single-character input 0, 2 & 1 as black, white & empty).
Multiplies black squares by -0.5 and white squares by 0.5, and then uses the standard deviation (sd) to check if all the resulting nonzero [!!z] values are the same (in which case the standard deviation is zero). In many challenges, the sd approach could fail for inputs with zero or one items (which would yield a standard deviation of NA), but luckily this can't happen here for a valid chess position.
Perl 5, 48 bytes
y,/2468,1,d;$_=/^(([w\d][b\d])+|([b\d][w\d])+)$/
Takes preprosessed FEN-input: blacks becomes b and whites w. Deletes 2, 4, 6 and 8 empty squares since they don't change the result, odd empties 1, 3, 5 and 7 are treated as 1 (no difference in result). Flattens the board so the newlines / become one invisible empty square. The regex tests if all 36 pairs (9x8/2) of the flattened board consist of either white|empty then black|empty or the opposite. Returns 1 for truthy and "" (empty string) for falsey.
Retina 0.8.2, 35 32 bytes
T`L`0
T`l`1
s`(\d).(..)*(?!\1)\d
Try it online! Takes input as a board but link is to test suite which converts from FEN to a compatible board, so if you want to test board input then delete the contents of the header first. Outputs 0 for a reverse draughts position and non-zero if not (+1 byte to always output 1). Explanation: Maps pieces to 0 or 1 depending on their colour (-12 bytes for a custom input format) and then checks whether opposite colour pieces are on two squares of the same colour.
J, 23 22 21 16 15 bytes
6 e.]*.//.~2|#\
Test cases taken from caird's Jelly answer
Input: Single list with space & newline = 1, black = 2, white = 3.
Output: 0 for valid, 1 for invalid.
how
2|#\Creates list1 0 1 0 1 0 ...to length of input.]*.//.~Partitions input according to that, taking LCM of each partition. Only an invalid board will have a partition containing both2and3, and hence an LCM of42.6 e.Is6an element of that? Only possible on invalid boards.
JavaScript (Node.js), 66 bytes
a=>a.map(t=r=>r.map(c=>t|=5+(g=-g)*(c>{}?-1:c>'@'),g=-g),g=3)^15^t
Input 2d array of characters in rnbqpRNBQP.. Output truthy vs falsy. 52 bytes if input as 2d array of +1, 0, -1.
Factor, 43 bytes
[ 2 group unzip [ cardinality 3 = ] both? ]
Takes input as a string with any three distinct values representing black pieces, white pieces, and empty spaces and relies on the trick from @loopy walt's Python answer: namely, that because of newlines, even and odd indices of the string correspond to black and white squares. However, all we need to do is check if the cardinality of both groups is three.
Jelly, 9 bytes
ŒJ§ḂṬƙFṀḊ
Takes input as an \$8 \times 8\$ matrix, with 0 being empty space, 1 being white and 2 being black. Outputs an empty list [] for truthy, and a non-empty list [1] for falsey.
Additionally, if we really want to stretch the output format, we can have this 8 byter
ŒJ§ḂṬƙFṀ
which outputs [1] for truthy, and [1, 1] for falsey.
How it works
ŒJ§ḂṬƙFṀḊ - Main link. Takes a matrix M on the left
ŒJ - 8x8 grid of coordinates [x, y] between 1 and 8
§ - Sum of each coordinate
Ḃ - Bit
F - Flatten M
ƙ - Over the lists formed by grouping the flattened M by the bit of the coordinate:
Ṭ - Yield a boolean list, with 1s at the indices in the list
Ṁ - Maximum
Ḋ - Dequeue, remove the first element
Python, 34 bytes
lambda p:{*p[::2]}<{*p}>{*p[1::2]}
Accepts a single string. Works for any distinct 4 characters for empty,black,white,newline.
How?
Uses the fact that including the linebreak lines have odd length, hence going over the entire string skipping every other character separates black and white squares. Both subsets must contain newlines and empty squares (we can't legally put all 32 initial pieces on the same colour squares because of the bishops). Iff there are pieces of both players on the same kind of square that subset will be the full set and the corresponding inequality fail.
Old Python, 40 bytes
lambda p:{*p[::2]}<{*"bw.\n"}>{*p[1::2]}
Accepts a single string. ".bw\n" for empty,black,white,newline.
Wrong Python, 36 bytes
lambda p:len({*p[::2]}&{*p[1::2]})<3
Accepts a single string.
Works for any distinct 4 characters for empty,black,white,newline.
Python3, 245 bytes:
lambda b:g({(x,y):b[x][y]for x in r(8)for y in r(8)})
r=range
g=lambda p:len(set(w:=[(x%2==0 and y%2==0)or(x%2 and y%2)for x,y in p if p[(x,y)]==1]))==1 and len(set(b:=[(x%2==0 and y%2==0)or(x%2 and y%2)for x,y in p if p[(x,y)]==0]))==1 and w!=b