Revision 78c3d3a4-a45e-4ef3-92c3-f1b1f7be2bf8 - Code Golf Stack Exchange

# [JavaScript (Node.js)], 84 bytes

<!-- language: lang-javascript -->

 s=>[a=~"0628"[[C,P,F,R]=Buffer(s),i=P%11%7],b=-"63682"[i]||4][C&1]+(F+R&1?45-a-b:19)

[Try it online!][TIO-kfghbduf]

[JavaScript (Node.js)]: https://nodejs.org
[TIO-kfghbduf]: https://tio.run/##ZcvNCoIwAADge08hA2XDLdv8yYIVJHjpIl7HDtNUDNFwlRfp1delCOz88V3VU@lybG930g@XytTcaH4Qir/AJmIxECLBGU5xLvnpUdfVCDXCLc9sSu2txAUnIPKjmAHRynkOpEgcKl2YurlDj0FIFCn2dIdMOfR66Kp1NzSwhmDKFQUIWZ5nMX@1wOKHNF7ilJXsg2HwN89N/EVq3g "JavaScript (Node.js) – Try It Online"

### How?

The color, the piece, the file and the rank characters are turned into ASCII codes which are saved into \$C\,ドル \$P\,ドル \$F\$ and \$R\$ respectively.

We compute the piece index \$i=(P \bmod 11)\bmod 7\$:

 char. | code | mod 11 | mod 7
 -------+------+--------+-------
 'B' | 66 | 0 | 0 Reordered by index:
 'K' | 75 | 9 | 2 
 'N' | 78 | 1 | 1 0 | 1 | 2 | 3 | 4 | 5
 'P' | 80 | 3 | 3 ---+---+---+---+---+---
 'Q' | 81 | 4 | 4 B | N | K | P | Q | R
 'R' | 82 | 5 | 5

We compute \$a\,ドル which is the number of outline squares for the piece, minus \19ドル\$:

<!-- language: lang-javascript -->

 a = ~"0628"[i]

We compute \$b\,ドル which is the number of filled squares for the piece, minus \19ドル\$:

<!-- language: lang-javascript -->

 b = -"63682"[i] || 4

We use `C & 1` to figure out the color of the piece and `F + R & 1` to figure out the color of the square.

The final result is:

<!-- language: lang-javascript -->

 [a, b][C & 1] // use outline squares if the piece is black
 + // or filled squares if the piece is white
 ( //
 F + R & 1 ? // if the square is white:
 45 - a - b // add 19 + (64 - ((a + 19) + (b + 19)))
 // = 45 - a - b
 : // else:
 19 // just add 19
 ) //

AltStyle によって変換されたページ (->オリジナル) /