[{"data":1,"prerenderedAt":1212},["ShallowReactive",2],{"navigation_docs":3,"-encodings-fen":140,"-encodings-fen-surround":1209},[4,52],{"title":5,"path":6,"stem":7,"children":8,"icon":51},"Guide","\u002Fguide","1.guide\u002F01.index",[9,11,15,19,23,27,31,35,39,43,47],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Encoding and Decoding","\u002Fguide\u002Fencoding","1.guide\u002F02.encoding",{"title":16,"path":17,"stem":18},"Checksums","\u002Fguide\u002Fchecksums","1.guide\u002F03.checksums",{"title":20,"path":21,"stem":22},"Identify","\u002Fguide\u002Fidentify","1.guide\u002F04.identify",{"title":24,"path":25,"stem":26},"CLI","\u002Fguide\u002Fcli","1.guide\u002F05.cli",{"title":28,"path":29,"stem":30},"Agents","\u002Fguide\u002Fagents","1.guide\u002F06.agents",{"title":32,"path":33,"stem":34},"Code pages","\u002Fguide\u002Fcode-pages","1.guide\u002F07.code-pages",{"title":36,"path":37,"stem":38},"RLP","\u002Fguide\u002Frlp","1.guide\u002F08.rlp",{"title":40,"path":41,"stem":42},"OpenPGP armor","\u002Fguide\u002Farmor","1.guide\u002F09.armor",{"title":44,"path":45,"stem":46},"Custom Encodings","\u002Fguide\u002Fcustom","1.guide\u002F10.custom",{"title":48,"path":49,"stem":50},"Playground","\u002Fguide\u002Fplayground","1.guide\u002F11.playground","i-lucide-book-open",{"title":53,"path":54,"stem":55,"children":56,"icon":139},"Encodings","\u002Fencodings","2.encodings\u002F00.index",[57,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,131,135],{"title":58,"path":54,"stem":55},"Every encoding",{"title":60,"path":61,"stem":62},"Binary","\u002Fencodings\u002Fbinary","2.encodings\u002F01.binary",{"title":64,"path":65,"stem":66},"Octal","\u002Fencodings\u002Foctal","2.encodings\u002F02.octal",{"title":68,"path":69,"stem":70},"Decimal","\u002Fencodings\u002Fdecimal","2.encodings\u002F03.decimal",{"title":72,"path":73,"stem":74},"Integer","\u002Fencodings\u002Finteger","2.encodings\u002F03.integer",{"title":76,"path":77,"stem":78},"Hex","\u002Fencodings\u002Fhex","2.encodings\u002F04.hex",{"title":80,"path":81,"stem":82},"Base32","\u002Fencodings\u002Fbase32","2.encodings\u002F05.base32",{"title":84,"path":85,"stem":86},"Base45","\u002Fencodings\u002Fbase45","2.encodings\u002F09.base45",{"title":88,"path":89,"stem":90},"Base58","\u002Fencodings\u002Fbase58","2.encodings\u002F10.base58",{"title":92,"path":93,"stem":94},"Base64","\u002Fencodings\u002Fbase64","2.encodings\u002F14.base64",{"title":96,"path":97,"stem":98},"Base85","\u002Fencodings\u002Fbase85","2.encodings\u002F18.base85",{"title":100,"path":101,"stem":102},"basE91","\u002Fencodings\u002Fbase91","2.encodings\u002F19.base91",{"title":104,"path":105,"stem":106},"Base256","\u002Fencodings\u002Fbase256","2.encodings\u002F20.base256",{"title":108,"path":109,"stem":110},"Bech32","\u002Fencodings\u002Fbech32","2.encodings\u002F21.bech32",{"title":112,"path":113,"stem":114},"uuencode","\u002Fencodings\u002Fuuencode","2.encodings\u002F22.uuencode",{"title":116,"path":117,"stem":118},"Quoted-Printable","\u002Fencodings\u002Fquoted-printable","2.encodings\u002F23.quoted-printable",{"title":120,"path":121,"stem":122},"HTML","\u002Fencodings\u002Fhtml","2.encodings\u002F24.html",{"title":124,"path":125,"stem":126},"ITA2","\u002Fencodings\u002Fita2","2.encodings\u002F25.ita2",{"title":128,"path":129,"stem":130},"Prefix codes","\u002Fencodings\u002Fprefix","2.encodings\u002F26.prefix",{"title":132,"path":133,"stem":134},"Chess squares","\u002Fencodings\u002Fsquare","2.encodings\u002F27.square",{"title":136,"path":137,"stem":138},"FEN","\u002Fencodings\u002Ffen","2.encodings\u002F28.fen","i-lucide-library",{"id":141,"title":136,"body":142,"description":1202,"extension":1203,"links":1204,"meta":1205,"navigation":1206,"path":137,"seo":1207,"stem":138,"__hash__":1208},"docs\u002F2.encodings\u002F28.fen.md",{"type":143,"value":144,"toc":1193},"minimark",[145,149,157,224,231,236,251,315,333,344,369,380,384,387,490,529,532,575,581,585,595,629,632,640,653,676,679,683,690,750,760,781,784,803,806,809,840,845,848,875,882,892,896,903,963,985,998,1003,1026,1029,1033,1036,1056,1062,1066,1091,1111,1120,1123,1158,1189],[146,147],"encoding-facts",{"name":148},"fen",[150,151,152,153,156],"p",{},"FEN strings turn up in chess puzzles, sometimes inside a password. Parse one by hand and a typo puts a bishop on the wrong colour. ",[154,155,148],"code",{}," reads the notation strictly and says where it broke.",[158,159,164],"pre",{"className":160,"code":161,"language":162,"meta":163,"style":163},"language-ts shiki shiki-themes encodings encodings encodings","const start = \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\";\ndecode(\"fen\", start).bytes   \u002F\u002F 64 bytes: \"RNBQKBNRPPPPPPPP................................pppppppprnbqkbnr\"\ndecode(\"fen\", start).details \u002F\u002F { turn: \"w\", castling: \"KQkq\", enPassant: \"-\", halfmove: 0, fullmove: 1 }\n","ts","",[154,165,166,189,209],{"__ignoreMap":163},[167,168,171,175,179,182,186],"span",{"class":169,"line":170},"line",1,[167,172,174],{"class":173},"skH_V","const",[167,176,178],{"class":177},"s38Sx"," start ",[167,180,181],{"class":173},"=",[167,183,185],{"class":184},"shU9J"," \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"",[167,187,188],{"class":177},";\n",[167,190,192,196,199,202,205],{"class":169,"line":191},2,[167,193,195],{"class":194},"sK71F","decode",[167,197,198],{"class":177},"(",[167,200,201],{"class":184},"\"fen\"",[167,203,204],{"class":177},", start).bytes   ",[167,206,208],{"class":207},"scIB-","\u002F\u002F 64 bytes: \"RNBQKBNRPPPPPPPP................................pppppppprnbqkbnr\"\n",[167,210,212,214,216,218,221],{"class":169,"line":211},3,[167,213,195],{"class":194},[167,215,198],{"class":177},[167,217,201],{"class":184},[167,219,220],{"class":177},", start).details ",[167,222,223],{"class":207},"\u002F\u002F { turn: \"w\", castling: \"KQkq\", enPassant: \"-\", halfmove: 0, fullmove: 1 }\n",[150,225,226,227,230],{},"The board becomes 64 bytes. Everything else lands in ",[154,228,229],{},"details",", where it can't get in the way.",[232,233,235],"h2",{"id":234},"where-is-each-piece","Where is each piece?",[150,237,238,239,242,243,246,247,250],{},"Each byte is a piece letter in ASCII, or ",[154,240,241],{},"."," for an empty square. White writes ",[154,244,245],{},"P N B R Q K",", Black ",[154,248,249],{},"p n b r q k",". Print the bytes as text and the position reads itself.",[158,252,254],{"className":160,"code":253,"language":162,"meta":163,"style":163},"const afterE4 = \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F4P3\u002F8\u002FPPPP1PPP\u002FRNBQKBNR b KQkq e3 0 1\";\nconst position = decode(\"fen\", afterE4);\nposition.bytes[28] \u002F\u002F 80, \"P\" on e4\nposition.bytes[12] \u002F\u002F 46, \".\" on e2\nposition.details   \u002F\u002F { turn: \"b\", castling: \"KQkq\", enPassant: \"e3\", halfmove: 0, fullmove: 1 }\n",[154,255,256,270,289,297,306],{"__ignoreMap":163},[167,257,258,260,263,265,268],{"class":169,"line":170},[167,259,174],{"class":173},[167,261,262],{"class":177}," afterE4 ",[167,264,181],{"class":173},[167,266,267],{"class":184}," \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F4P3\u002F8\u002FPPPP1PPP\u002FRNBQKBNR b KQkq e3 0 1\"",[167,269,188],{"class":177},[167,271,272,274,277,279,282,284,286],{"class":169,"line":191},[167,273,174],{"class":173},[167,275,276],{"class":177}," position ",[167,278,181],{"class":173},[167,280,281],{"class":194}," decode",[167,283,198],{"class":177},[167,285,201],{"class":184},[167,287,288],{"class":177},", afterE4);\n",[167,290,291,294],{"class":169,"line":211},[167,292,293],{"class":177},"position.bytes[28] ",[167,295,296],{"class":207},"\u002F\u002F 80, \"P\" on e4\n",[167,298,300,303],{"class":169,"line":299},4,[167,301,302],{"class":177},"position.bytes[12] ",[167,304,305],{"class":207},"\u002F\u002F 46, \".\" on e2\n",[167,307,309,312],{"class":169,"line":308},5,[167,310,311],{"class":177},"position.details   ",[167,313,314],{"class":207},"\u002F\u002F { turn: \"b\", castling: \"KQkq\", enPassant: \"e3\", halfmove: 0, fullmove: 1 }\n",[150,316,317,318,321,322,325,326,329,330,241],{},"The default ",[154,319,320],{},"layout: \"a1\""," starts at a1 and counts along each rank. It goes from a1 to h1, then a2, up to h8. Byte 0 is ",[154,323,324],{},"R",", byte 4 is ",[154,327,328],{},"K",", and byte 60 is ",[154,331,332],{},"k",[150,334,335,336,339,340,343],{},"Want FEN's own reading order instead? Use ",[154,337,338],{},"layout: \"a8\""," to start at a8. Use ",[154,341,342],{},"layout: \"file\""," to count a1 through a8, then b1.",[158,345,347],{"className":160,"code":346,"language":162,"meta":163,"style":163},"decode(\"fen\", start, { layout: \"a8\" }).bytes \u002F\u002F 64 bytes: \"rnbqkbnrpppppppp................................PPPPPPPPRNBQKBNR\"\n",[154,348,349],{"__ignoreMap":163},[167,350,351,353,355,357,360,363,366],{"class":169,"line":170},[167,352,195],{"class":194},[167,354,198],{"class":177},[167,356,201],{"class":184},[167,358,359],{"class":177},", start, { layout: ",[167,361,362],{"class":184},"\"a8\"",[167,364,365],{"class":177}," }).bytes ",[167,367,368],{"class":207},"\u002F\u002F 64 bytes: \"rnbqkbnrpppppppp................................PPPPPPPPRNBQKBNR\"\n",[150,370,371,372,375,376,379],{},"Byte 0 is ",[154,373,374],{},"r"," here. These layouts match the ",[154,377,378],{},"square"," codec, so their indices agree.",[232,381,383],{"id":382},"how-do-you-get-the-fen-back","How do you get the FEN back?",[150,385,386],{},"Pass the decoded fields back as options. The board bytes don't remember whose turn it is or who can castle.",[158,388,390],{"className":160,"code":389,"language":162,"meta":163,"style":163},"const { bytes, details } = decode(\"fen\", start);\nencode(\"fen\", bytes)                       \u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w - - 0 1\"\nencode(\"fen\", bytes, { castling: \"KQkq\" }) \u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"\nencode(\"fen\", bytes, details)              \u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"\nencode(\"fen\", bytes, { turn: \"b\", castling: \"Kq\", enPassant: \"e3\", halfmove: 7, fullmove: 40 }) \u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR b Kq e3 7 40\"\n",[154,391,392,410,425,445,458],{"__ignoreMap":163},[167,393,394,396,399,401,403,405,407],{"class":169,"line":170},[167,395,174],{"class":173},[167,397,398],{"class":177}," { bytes, details } ",[167,400,181],{"class":173},[167,402,281],{"class":194},[167,404,198],{"class":177},[167,406,201],{"class":184},[167,408,409],{"class":177},", start);\n",[167,411,412,415,417,419,422],{"class":169,"line":191},[167,413,414],{"class":194},"encode",[167,416,198],{"class":177},[167,418,201],{"class":184},[167,420,421],{"class":177},", bytes)                       ",[167,423,424],{"class":207},"\u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w - - 0 1\"\n",[167,426,427,429,431,433,436,439,442],{"class":169,"line":211},[167,428,414],{"class":194},[167,430,198],{"class":177},[167,432,201],{"class":184},[167,434,435],{"class":177},", bytes, { castling: ",[167,437,438],{"class":184},"\"KQkq\"",[167,440,441],{"class":177}," }) ",[167,443,444],{"class":207},"\u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"\n",[167,446,447,449,451,453,456],{"class":169,"line":299},[167,448,414],{"class":194},[167,450,198],{"class":177},[167,452,201],{"class":184},[167,454,455],{"class":177},", bytes, details)              ",[167,457,444],{"class":207},[167,459,460,462,464,466,469,472,475,478,481,484,487],{"class":169,"line":308},[167,461,414],{"class":194},[167,463,198],{"class":177},[167,465,201],{"class":184},[167,467,468],{"class":177},", bytes, { turn: ",[167,470,471],{"class":184},"\"b\"",[167,473,474],{"class":177},", castling: ",[167,476,477],{"class":184},"\"Kq\"",[167,479,480],{"class":177},", enPassant: ",[167,482,483],{"class":184},"\"e3\"",[167,485,486],{"class":177},", halfmove: 7, fullmove: 40 }) ",[167,488,489],{"class":207},"\u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR b Kq e3 7 40\"\n",[150,491,492,493,496,497,500,501,504,505,508,509,496,512,514,515,504,518,521,522,504,525,528],{},"Without options, ",[154,494,495],{},"turn"," defaults to ",[154,498,499],{},"w"," and ",[154,502,503],{},"castling"," to ",[154,506,507],{},"-",". ",[154,510,511],{},"enPassant",[154,513,507],{},", ",[154,516,517],{},"halfmove",[154,519,520],{},"0",", and ",[154,523,524],{},"fullmove",[154,526,527],{},"1",". Castling rights don't survive unless you pass them back.",[150,530,531],{},"A short FEN keeps only the fields it contains. Extra spaces and line breaks between fields are fine.",[158,533,535],{"className":160,"code":534,"language":162,"meta":163,"style":163},"decode(\"fen\", \"4k3\u002F8\u002F8\u002F8\u002F8\u002F8\u002F4P3\u002F4K3 b\").details \u002F\u002F { turn: \"b\" }\ndecode(\"fen\", \"8\u002F8\u002F8\u002F8\u002F8\u002F8\u002F8\u002F8\").details         \u002F\u002F {}\n",[154,536,537,556],{"__ignoreMap":163},[167,538,539,541,543,545,547,550,553],{"class":169,"line":170},[167,540,195],{"class":194},[167,542,198],{"class":177},[167,544,201],{"class":184},[167,546,514],{"class":177},[167,548,549],{"class":184},"\"4k3\u002F8\u002F8\u002F8\u002F8\u002F8\u002F4P3\u002F4K3 b\"",[167,551,552],{"class":177},").details ",[167,554,555],{"class":207},"\u002F\u002F { turn: \"b\" }\n",[167,557,558,560,562,564,566,569,572],{"class":169,"line":191},[167,559,195],{"class":194},[167,561,198],{"class":177},[167,563,201],{"class":184},[167,565,514],{"class":177},[167,567,568],{"class":184},"\"8\u002F8\u002F8\u002F8\u002F8\u002F8\u002F8\u002F8\"",[167,570,571],{"class":177},").details         ",[167,573,574],{"class":207},"\u002F\u002F {}\n",[150,576,577,578,580],{},"A missing field stays missing in ",[154,579,229],{},". No guessing that it's White to move.",[232,582,584],{"id":583},"can-it-draw-the-board","Can it draw the board?",[150,586,587,588,591,592,241],{},"Set ",[154,589,590],{},"diagram: true"," to print the board with rank 8 on top. White sits at the bottom, just as with python-chess's ",[154,593,594],{},"print(board)",[158,596,598],{"className":160,"code":597,"language":162,"meta":163,"style":163},"const board = decode(\"fen\", afterE4).bytes;\nencode(\"fen\", board, { diagram: true })\n",[154,599,600,618],{"__ignoreMap":163},[167,601,602,604,607,609,611,613,615],{"class":169,"line":170},[167,603,174],{"class":173},[167,605,606],{"class":177}," board ",[167,608,181],{"class":173},[167,610,281],{"class":194},[167,612,198],{"class":177},[167,614,201],{"class":184},[167,616,617],{"class":177},", afterE4).bytes;\n",[167,619,620,622,624,626],{"class":169,"line":191},[167,621,414],{"class":194},[167,623,198],{"class":177},[167,625,201],{"class":184},[167,627,628],{"class":177},", board, { diagram: true })\n",[150,630,631],{},"The result is:",[158,633,638],{"className":634,"code":636,"language":637,"meta":163},[635],"language-text","r n b q k b n r\np p p p p p p p\n. . . . . . . .\n. . . . . . . .\n. . . . P . . .\n. . . . . . . .\nP P P P . P P P\nR N B Q K B N R\n","text",[154,639,636],{"__ignoreMap":163},[150,641,642,643,645,646,648,649,652],{},"A diagram shows the board alone. Decode it with ",[154,644,590],{},", with or without spaces between squares. Its ",[154,647,229],{}," is ",[154,650,651],{},"{}",". Encode won't accept fields beside the diagram option.",[158,654,656],{"className":160,"code":655,"language":162,"meta":163,"style":163},"encode(\"fen\", board, { diagram: true, castling: \"KQkq\" }) \u002F\u002F throws: Invalid option castling=KQkq: a diagram shows the board alone\n",[154,657,658],{"__ignoreMap":163},[167,659,660,662,664,666,669,671,673],{"class":169,"line":170},[167,661,414],{"class":194},[167,663,198],{"class":177},[167,665,201],{"class":184},[167,667,668],{"class":177},", board, { diagram: true, castling: ",[167,670,438],{"class":184},[167,672,441],{"class":177},[167,674,675],{"class":207},"\u002F\u002F throws: Invalid option castling=KQkq: a diagram shows the board alone\n",[150,677,678],{},"No castling rights fit in that picture.",[232,680,682],{"id":681},"can-the-pieces-hide-bits-of-their-own","Can the pieces hide bits of their own?",[150,684,685,686,689],{},"The board can be the message. Twelve boards for one position sounds like a lot. But a puzzle that hides one bit per piece needs exactly that, and ",[154,687,688],{},"bitboards: true"," hands it over.",[158,691,693],{"className":160,"code":692,"language":162,"meta":163,"style":163},"const bytes = decode(\"fen\", afterE4, { bitboards: true }).bytes \u002F\u002F 96 bytes\nbytes.subarray(0, 8)                                             \u002F\u002F white pawns, in hex 000000001000ef00\nencode(\"square\", bytes.subarray(0, 8), { bitboard: true })       \u002F\u002F \"a2 b2 c2 d2 f2 g2 h2 e4\"\n",[154,694,695,716,730],{"__ignoreMap":163},[167,696,697,699,702,704,706,708,710,713],{"class":169,"line":170},[167,698,174],{"class":173},[167,700,701],{"class":177}," bytes ",[167,703,181],{"class":173},[167,705,281],{"class":194},[167,707,198],{"class":177},[167,709,201],{"class":184},[167,711,712],{"class":177},", afterE4, { bitboards: true }).bytes ",[167,714,715],{"class":207},"\u002F\u002F 96 bytes\n",[167,717,718,721,724,727],{"class":169,"line":191},[167,719,720],{"class":177},"bytes.",[167,722,723],{"class":194},"subarray",[167,725,726],{"class":177},"(0, 8)                                             ",[167,728,729],{"class":207},"\u002F\u002F white pawns, in hex 000000001000ef00\n",[167,731,732,734,736,739,742,744,747],{"class":169,"line":211},[167,733,414],{"class":194},[167,735,198],{"class":177},[167,737,738],{"class":184},"\"square\"",[167,740,741],{"class":177},", bytes.",[167,743,723],{"class":194},[167,745,746],{"class":177},"(0, 8), { bitboard: true })       ",[167,748,749],{"class":207},"\u002F\u002F \"a2 b2 c2 d2 f2 g2 h2 e4\"\n",[150,751,752,753,756,757,759],{},"Each piece type gets its own 8-byte big-endian board. White moves first here too: ",[154,754,755],{},"P N B R Q K p n b r q k",". The FEN fields stay in ",[154,758,229],{}," as usual.",[150,761,762,763,766,767,769,770,773,774,777,778,780],{},"Bit ",[154,764,765],{},"i"," marks square ",[154,768,765],{}," in the chosen ",[154,771,772],{},"layout",". The default is ",[154,775,776],{},"a1",": bit 0 is a1, bit 63 is h8. Same layouts and same bitboards as ",[154,779,378],{},", so any slice plugs straight into it. That's the nice part.",[150,782,783],{},"At the start, the boards look like this:",[158,785,787],{"className":160,"code":786,"language":162,"meta":163,"style":163},"decode(\"fen\", start, { bitboards: true }).bytes \u002F\u002F 96 bytes, in hex 000000000000ff00 0000000000000042 0000000000000024 0000000000000081 0000000000000008 0000000000000010 00ff000000000000 4200000000000000 2400000000000000 8100000000000000 0800000000000000 1000000000000000\n",[154,788,789],{"__ignoreMap":163},[167,790,791,793,795,797,800],{"class":169,"line":170},[167,792,195],{"class":194},[167,794,198],{"class":177},[167,796,201],{"class":184},[167,798,799],{"class":177},", start, { bitboards: true }).bytes ",[167,801,802],{"class":207},"\u002F\u002F 96 bytes, in hex 000000000000ff00 0000000000000042 0000000000000024 0000000000000081 0000000000000008 0000000000000010 00ff000000000000 4200000000000000 2400000000000000 8100000000000000 0800000000000000 1000000000000000\n",[150,804,805],{},"The first board is white pawns. The bitboards match python-chess.",[150,807,808],{},"And they encode back into a FEN. As with the 64-byte board, options supply the fields after it.",[158,810,812],{"className":160,"code":811,"language":162,"meta":163,"style":163},"encode(\"fen\", bytes, { bitboards: true, turn: \"b\", castling: \"KQkq\", enPassant: \"e3\" }) \u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F4P3\u002F8\u002FPPPP1PPP\u002FRNBQKBNR b KQkq e3 0 1\"\n",[154,813,814],{"__ignoreMap":163},[167,815,816,818,820,822,825,827,829,831,833,835,837],{"class":169,"line":170},[167,817,414],{"class":194},[167,819,198],{"class":177},[167,821,201],{"class":184},[167,823,824],{"class":177},", bytes, { bitboards: true, turn: ",[167,826,471],{"class":184},[167,828,474],{"class":177},[167,830,438],{"class":184},[167,832,480],{"class":177},[167,834,483],{"class":184},[167,836,441],{"class":177},[167,838,839],{"class":207},"\u002F\u002F \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F4P3\u002F8\u002FPPPP1PPP\u002FRNBQKBNR b KQkq e3 0 1\"\n",[150,841,842,844],{},[154,843,590],{}," works both ways too. Decode a diagram to bitboards, or encode bitboards to a diagram.",[150,846,847],{},"Bitboards going in must be 96 bytes. Two pieces on one square get refused too.",[158,849,851],{"className":160,"code":850,"language":162,"meta":163,"style":163},"encode(\"fen\", new Uint8Array(64), { bitboards: true }) \u002F\u002F throws: fen: twelve bitboards are 96 bytes, not 64\n",[154,852,853],{"__ignoreMap":163},[167,854,855,857,859,861,863,866,869,872],{"class":169,"line":170},[167,856,414],{"class":194},[167,858,198],{"class":177},[167,860,201],{"class":184},[167,862,514],{"class":177},[167,864,865],{"class":173},"new",[167,867,868],{"class":194}," Uint8Array",[167,870,871],{"class":177},"(64), { bitboards: true }) ",[167,873,874],{"class":207},"\u002F\u002F throws: fen: twelve bitboards are 96 bytes, not 64\n",[150,876,877,878,881],{},"A pawn and the black king both on e1 throws ",[154,879,880],{},"fen: e1 holds both P and k; one piece a square",". Cosy, but no.",[150,883,884,887,888,891],{},[154,885,886],{},"identify"," never guesses ",[154,889,890],{},"bitboards",". It's the same board again, so it would turn up twice.",[232,893,895],{"id":894},"what-does-it-refuse","What does it refuse?",[150,897,898,899,902],{},"Bad notation gets a precise complaint. ",[154,900,901],{},"DecodeError.index"," points at the guilty character, not just the field.",[158,904,906],{"className":160,"code":905,"language":162,"meta":163,"style":163},"decode(\"fen\", \"rnbqkbnr\u002Fpppppppp\u002F44\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\") \u002F\u002F throws: fen: \"4\" (U+0034) at index 19 follows another count; add them up\ndecode(\"fen\", \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w kqKQ - 0 1\") \u002F\u002F throws: fen: \"kqKQ\" at index 46 is not castling rights, \"K\" (U+004B) at index 48 is out of place; use K, Q, k and q, each once and in that order, or -\ndecode(\"fen\", \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq e4 0 1\") \u002F\u002F throws: fen: \"e4\" at index 51 is not an en passant square, \"4\" (U+0034) at index 52 is out of place; use a square on rank 3 or 6, or -\n",[154,907,908,927,945],{"__ignoreMap":163},[167,909,910,912,914,916,918,921,924],{"class":169,"line":170},[167,911,195],{"class":194},[167,913,198],{"class":177},[167,915,201],{"class":184},[167,917,514],{"class":177},[167,919,920],{"class":184},"\"rnbqkbnr\u002Fpppppppp\u002F44\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"",[167,922,923],{"class":177},") ",[167,925,926],{"class":207},"\u002F\u002F throws: fen: \"4\" (U+0034) at index 19 follows another count; add them up\n",[167,928,929,931,933,935,937,940,942],{"class":169,"line":191},[167,930,195],{"class":194},[167,932,198],{"class":177},[167,934,201],{"class":184},[167,936,514],{"class":177},[167,938,939],{"class":184},"\"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w kqKQ - 0 1\"",[167,941,923],{"class":177},[167,943,944],{"class":207},"\u002F\u002F throws: fen: \"kqKQ\" at index 46 is not castling rights, \"K\" (U+004B) at index 48 is out of place; use K, Q, k and q, each once and in that order, or -\n",[167,946,947,949,951,953,955,958,960],{"class":169,"line":211},[167,948,195],{"class":194},[167,950,198],{"class":177},[167,952,201],{"class":184},[167,954,514],{"class":177},[167,956,957],{"class":184},"\"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq e4 0 1\"",[167,959,923],{"class":177},[167,961,962],{"class":207},"\u002F\u002F throws: fen: \"e4\" at index 51 is not an en passant square, \"4\" (U+0034) at index 52 is out of place; use a square on rank 3 or 6, or -\n",[150,964,965,966,969,970,973,974,514,976,514,979,514,981,984],{},"FEN writes an empty rank as ",[154,967,968],{},"8",", not consecutive counts like ",[154,971,972],{},"44",". Castling letters follow ",[154,975,328],{},[154,977,978],{},"Q",[154,980,332],{},[154,982,983],{},"q"," order. An en passant square must be on rank 3 or 6. That's the square a pawn skips on its double step.",[150,986,987,988,990,991,994,995,997],{},"The codec also rejects ranks with the wrong number of squares and boards without exactly eight ranks. It rejects a turn other than ",[154,989,499],{}," or ",[154,992,993],{},"b",", and a move number of ",[154,996,520],{},". Each error names where the problem is.",[150,999,1000,1001,241],{},"Encoding requires exactly 64 bytes, each a piece letter or ",[154,1002,241],{},[158,1004,1006],{"className":160,"code":1005,"language":162,"meta":163,"style":163},"encode(\"fen\", \"hello\") \u002F\u002F throws: fen: a board is 64 bytes, not 5\n",[154,1007,1008],{"__ignoreMap":163},[167,1009,1010,1012,1014,1016,1018,1021,1023],{"class":169,"line":170},[167,1011,414],{"class":194},[167,1013,198],{"class":177},[167,1015,201],{"class":184},[167,1017,514],{"class":177},[167,1019,1020],{"class":184},"\"hello\"",[167,1022,923],{"class":177},[167,1024,1025],{"class":207},"\u002F\u002F throws: fen: a board is 64 bytes, not 5\n",[150,1027,1028],{},"It checks notation, not chess legality. Two white kings, nine queens, or pawns on rank 8 all pass. The arbiter can take the day off.",[232,1030,1032],{"id":1031},"can-identify-spot-a-fen","Can identify spot a FEN?",[150,1034,1035],{},"Yes, and it hands the fields back too.",[158,1037,1039],{"className":160,"code":1038,"language":162,"meta":163,"style":163},"identify(\"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\")[0] \u002F\u002F encoding \"fen\", with fields in details\n",[154,1040,1041],{"__ignoreMap":163},[167,1042,1043,1045,1047,1050,1053],{"class":169,"line":170},[167,1044,886],{"class":194},[167,1046,198],{"class":177},[167,1048,1049],{"class":184},"\"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"",[167,1051,1052],{"class":177},")[0] ",[167,1054,1055],{"class":207},"\u002F\u002F encoding \"fen\", with fields in details\n",[150,1057,1058,1059,1061],{},"It never guesses ",[154,1060,772],{},". Every layout reads the same board, so a guess would list one position three times.",[232,1063,1065],{"id":1064},"aliases-subpath-and-cli","Aliases, subpath and CLI",[150,1067,1068,1069,500,1072,1075,1076,1078,1079,1082,1083,500,1085,1088,1089,241],{},"The aliases ",[154,1070,1071],{},"forsyth",[154,1073,1074],{},"forsythedwards"," name ",[154,1077,148],{},". The ",[154,1080,1081],{},"@agntn\u002Fencodings\u002Fchess"," subpath exports ",[154,1084,148],{},[154,1086,1087],{},"FEN_TURNS"," alongside ",[154,1090,378],{},[158,1092,1096],{"className":1093,"code":1094,"language":1095,"meta":163,"style":163},"language-sh shiki shiki-themes encodings encodings encodings","encodings decode fen \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"\n","sh",[154,1097,1098],{"__ignoreMap":163},[167,1099,1100,1103,1105,1108],{"class":169,"line":170},[167,1101,1102],{"class":194},"encodings",[167,1104,281],{"class":184},[167,1106,1107],{"class":184}," fen",[167,1109,1110],{"class":184}," \"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR w KQkq - 0 1\"\n",[150,1112,1113,1114,500,1117,241],{},"The CLI prints the 64 bytes on stdout. It prints fields on stderr, one per line, such as ",[154,1115,1116],{},"turn: w",[154,1118,1119],{},"castling: KQkq",[150,1121,1122],{},"The bytes are printable, so the board goes back in as plain text.",[158,1124,1126],{"className":1093,"code":1125,"language":1095,"meta":163,"style":163},"encodings encode fen RNBQKBNRPPPPPPPP................................pppppppprnbqkbnr --castling KQkq --en-passant e3 --turn b\n",[154,1127,1128],{"__ignoreMap":163},[167,1129,1130,1132,1135,1137,1140,1143,1146,1149,1152,1155],{"class":169,"line":170},[167,1131,1102],{"class":194},[167,1133,1134],{"class":184}," encode",[167,1136,1107],{"class":184},[167,1138,1139],{"class":184}," RNBQKBNRPPPPPPPP................................pppppppprnbqkbnr",[167,1141,1142],{"class":184}," --castling",[167,1144,1145],{"class":184}," KQkq",[167,1147,1148],{"class":184}," --en-passant",[167,1150,1151],{"class":184}," e3",[167,1153,1154],{"class":184}," --turn",[167,1156,1157],{"class":184}," b\n",[150,1159,1160,1161,1164,1165,514,1168,514,1171,514,1174,514,1177,514,1180,514,1183,500,1186,241],{},"That prints ",[154,1162,1163],{},"rnbqkbnr\u002Fpppppppp\u002F8\u002F8\u002F8\u002F8\u002FPPPPPPPP\u002FRNBQKBNR b KQkq e3 0 1",". The flags are ",[154,1166,1167],{},"--layout",[154,1169,1170],{},"--diagram",[154,1172,1173],{},"--bitboards",[154,1175,1176],{},"--turn",[154,1178,1179],{},"--castling",[154,1181,1182],{},"--en-passant",[154,1184,1185],{},"--halfmove",[154,1187,1188],{},"--fullmove",[1190,1191,1192],"style",{},"html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}html pre.shiki code .scIB-, html code.shiki .scIB-{--shiki-light:var(--shiki-token-comment);--shiki-default:var(--shiki-token-comment);--shiki-dark:var(--shiki-token-comment)}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":163,"searchDepth":191,"depth":191,"links":1194},[1195,1196,1197,1198,1199,1200,1201],{"id":234,"depth":191,"text":235},{"id":382,"depth":191,"text":383},{"id":583,"depth":191,"text":584},{"id":681,"depth":191,"text":682},{"id":894,"depth":191,"text":895},{"id":1031,"depth":191,"text":1032},{"id":1064,"depth":191,"text":1065},"Chess positions in FEN as 64 bytes of piece letters or twelve piece bitboards. Castling and clocks in details and a board diagram too","md",null,{},true,{"title":136,"description":1202},"7jo0ejLT9opJWwtdPwlW1VcZ7EqjmmaBGiLAQWevwcY",[1210,1204],{"title":132,"path":133,"stem":134,"description":1211,"children":-1},"Chess squares as bytes, with a choice of board numbering",1794584245042]