# Print the Najdorf Sicilian

The Najdorf Variation of the Sicilian Defence is an opening often played at the highest level of chess. It is named after GM Miguel Najdorf and is known for being extremely sharp and theory heavy.

Your task is to write a program that, given a Boolean-like input, prints a chessboard representation of the opening from either White or Black perspective.

## I/O format

Your program can take any input that has two possible values. Boolean, Integer, etc.

Your program must output a square chessboard using your language's standard output (usually the console). Each piece must have a corresponding character (your choice). Black and white pieces must be different. Black and white squares are allowed to be the same, but you are allowed to have different characters for them if you wish.

Using standard notation and uppercase for white and lowercase for black, here are the two chessboards, though you are free to represent the pieces differently:

True               False

R   B K Q B   R    r n b q k b   r
P P P     P P P      p     p p p p
N        p     p   n
P N
N P
n   p     p        N
p p p p     p      P P P     P P P
r   b k q b n r    R   B Q K B   R


This is , so shortest program in bytes wins!

• Challenges should be as self-contained as possible. I've included the chessboard configurations themselves into the challenge so that the challenge contains the details, but also keeps the link to the Wikipedia page for further details. Apr 30, 2021 at 4:47
• Is the example correct? Shouldn't the opposite side see the board 180 degrees rotated instead of rows reversed? Apr 30, 2021 at 4:55
• Also, it seems like the Black King's Knight is not at the right position in the True version. Apr 30, 2021 at 5:21
• @Bubbler Fixed. Apr 30, 2021 at 10:49
• @Bubbler You're right; that's my bad. Sorry. May 1, 2021 at 21:43

# Jelly, 45 bytes

“¤d2ʂẠ⁽ÞWƓż:§ßẸ:ȯlEØƘƑṀ°@œḥƥßıẠ’ṃ“Œ⁼L»s8UṚ$¡G  0 outputs from White's perspective, 1 from Black's. As allowed in the question this uses other characters, the mapping is:  Black White R u t N y i B n a Q p b K r l P d c empty e e  Try it online! Or see this version which uses the letters from the question's example output and . for empty. ### How? “...’ṃ“Œ⁼L»s8UṚ$¡G - Main Link: integer (from [0,1]), is_Black
“...’              - a large integer (stored in base 250)
“Œ⁼L»        - dictionary word = "unpredictably"
ṃ             - base-decompress (i.e. use "unpredictably" as the base-13 digits)
s8      - split into slices eight long
¡  - repeat (is_Black) times:
$- last two links as a monad: U - reverse each Ṛ - reverse (equivalent to rotating a 1/2 turn) G - format as a grid  • Oh, using another character set like that is very clever :) May 1, 2021 at 21:42 # JavaScript (Node.js), 11489 124 bytes x=>RNBQKB R P PPPP P P N np n ppp ppp r bqkb r.split .sort(_=>x-1).map(n=>[...n].sort(_=>x-1).join).join   Try it online! Take the grid and flip if needed. • You can save a byte by using f.sort(_=>x||-1) instead of (x?f:f.reverse()). But the 2nd row is only 7 characters long. I guess they should all be padded to 8 characters or not padded at all. Apr 30, 2021 at 5:32 • (Since the sort is stable, f.sort(_=>x-1) should be fine as well.) Apr 30, 2021 at 6:05 • @Arnauld Thanks! Apr 30, 2021 at 7:15 # Jelly, 64 bytes “¢ƙ]Ŀ°Mė8Ḃ“¢Ɠt:bẎ€^E“¡ṣḂƘ3^Q““¡⁽Ñ<Ṅ“Ṛ"ß“¡żN5Aʠṭm“¡ƬọG¢2|ie»UṚ$¡G


Try it online!

-6 bytes thanks to Lyxal by compressing the string using Jelly's built-in dictionary compressed string type.

## Explanation

“...»       The grid itself
UṚ$Reverse the order of rows and rows themselves (180 degree rotation) ¡ N times G Formatted as a grid  • You mean string compression is useless here? Apr 30, 2021 at 10:36 • Your program must output a square chessboard using your language's standard output - I think the footer, which formats it into a grid, has to count towards the size of the program Apr 30, 2021 at 10:49 • @EnderShadow8 Fair enough. Outputting 2D text in native data types is usually accepted but since this is very similar to a kolmogorov challenge it's fair enough that I need to output the actual text and not just an internal representation. Apr 30, 2021 at 17:09 • @Lyxal I'm surprised, but despite there being next to no pattern to this, dictionary compression does actually shorten it. It might be due to all the spaces. Apr 30, 2021 at 17:13 # Vyxalj, 4945 42 bytes »¬℅→⁺w½] oꜝ}l÷₄ǒẇ‡⋎ḋ∩P,*ø:⁺Ȯ∞J₀»k63ȯτ?ßṘ8/  Try it Online! »...» # Push compressed integer k6 # Push constant 0123456789abcdef 3ȯ # Slice from 3rd character (3456789abcdef) τ # Custom base conversion (to base13 with above) ?ßṘ # If input is truthy, reverse 8/ # Divide into 8 pieces # Implicit join by newline  • The shorter one is allowed by the rules stated. May 21, 2021 at 12:09 • @EnderShadow8 Ok. May 21, 2021 at 12:10 # Charcoal, 46 bytes ”⟲.>Ｘc'eΣＺ\KＯＸW⟲w‴PVＣτΣ\⁻μ⊖[⊖Ｕ×Ｋ↙mψQ{π!J”ＵＥ¹⟲Ｎ  Try it online! Link is to verbose version of code. Uses 0 for White's view and 4 for Black's view. Assumes that Black wants to see the board rotated rather than flipped. Explanation: ”⟲.>Ｘc'eΣＺ\KＯＸW⟲w‴PVＣτΣ\⁻μ⊖[⊖Ｕ×Ｋ↙mψQ{π!J”  Print the compressed board. ＵＥ¹  Space the characters out horizontally. ⟲Ｎ  Rotate the board as necessary. 42 bytes without the horizontal spacing: ✳Ｎ”⟲.>Ｘc'eΣＺ\KＯＸW⟲w‴PVＣτΣ\⁻μ⊖[⊖Ｕ×Ｋ↙mψQ{π!J  Try it online! Link is to verbose version of code. Explanation: Prints the same compressed string, but in the input direction, which means that the string terminator is no longer required. 30 bytes by using a custom output format: ✳Ｎ“↶⊟∨dO9Ｒξ1d"⁼¦Q≕τm×↖ＷSLＱg℅R₂  Try it online! Link is to verbose version of code. Uses the following key: . Black pawn ! White pawn " Black rook # Black knight$   Black bishop
%   White rook
&   White knight
'   White bishop
(   Black king
)   Black queen
*   White king
+   White queen
`
• I think spacing out the characters isn't needed, althought the examples show it that way. Apr 30, 2021 at 7:53