The maximum character length of a FEN string

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

The maximum character length of a FEN string

Post by sje »

In case if you were wondering, the maximum character length of a FEN string is 92 including a trailing ASCII NUL byte. This is an upper bound, and in fact there may be a lesser upper bound.

At least this limit is what I'm using. I challenge anyone to come up with a counterexample.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: The maximum character length of a FEN string

Post by hgm »

lf2gekg2fl/a1s1tx1tsc1a/mv2r2d1rvm/pppp4p1pp/4ppp1i3/3i1nop4/8R3/3I1N4q1/PPPP1P3+p1P/M6D3M/AVB1TOXT1V1A/LFCSGKEGSCFL w - 0 49

:lol:
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: The maximum character length of a FEN string

Post by sje »

The maximum length is even larger for Taikyoku shogi with 1,296 squares and with each man needing at least two ideographs and each ideograph needing at least two bytes.

Also, how does one handle the issue of lower/upper case differences with ideographs?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: The maximum character length of a FEN string

Post by hgm »

Indeed, you put the finger on a very sore spot. I don't really know a good solution for this. Westerners playing those games tend to use a 'Forsyth notation' that separates all the (1- or 2-char) piece IDs by commas. The color is then indicated by writing the ID with all capitals or all lower case. (And there is a + prefix to the piece names for promoted pieces, like is usual in SFEN for Shogi, so pieces IDs can actually be 3 char.)

/L,3,G,1,K,2,G,1,L/
RC,1,C,1,KY,S,DE,BT,3,RC/
6,LN,5/
3,+gb,4,+gb,1,SM,1/
P,5,ln,3,b,P/
10,dh,1/
1,b,10/
12/12/
7,r,4/
12/12/

I experimented with using a : prefix to indicate a two-letter ID will follow (so that 1-letter names can be used as normal, and there is backward compatibility), but it looks ugly and is quite unreadable.

L:FLCSGK:DEGSC:FLL/:RV1B1:BT:KN:PH:BT1B1:RV/:SM:VMR:DH:DK:LN:FK:DK:DHR:VM:SM/PPPPPPPPPPPP/3:GB4:GB3 /12/12/3:gb4:gb3/pppppppppppp/:sm:vmr:dh:dk:fk:ln:dk:dhr:vm:sm/:rv1b1:bt:ph:kn:bt1b1:rv/l:flcsg:dekgsc:fll

The comma-separated notation at least looked somewhat readable.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: The maximum character length of a FEN string

Post by sje »

David Forsyth did the original FN for purposes of 19th century telegraphy; a good solution for those days when both radio and oceanic cable telegrams were necessary and expensive. I extended this to FEN to include a bit more data and with the goals of keeping human readability and an easy one line cut-and-paste.

I don't' see how those goals can be met for any shogi which approaches the Taikyoku expanse. I would just send an entire board diagram, 36 lines long of (36 * (2 + 1 + 1)) = 144 characters each. Each board cell would use two characters for the man, a an up/down character for the facing (color), and a space separator between cells. In the shogi spirit, I'd use ideograms as would be used by a native language human player. At the bottom of the diagram, there would be the state data for side-to-move and move number.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Notation for games with facing pieces

Post by sje »

Notation for games with facing pieces needs a means of indicating the orientation of a piece. Say that the first moving player is called First (最初に) and the opponent is named Second (二番目に (?)). Diagrammed pieces belonging to First would have an up arrow (↑ / UPWARDS ARROW / Unicode: U+2191, UTF-8: E2 86 91) suffix and each Second piece would have a down arrow (↓ / DOWNWARDS ARROW / Unicode: U+2193, UTF-8: E2 86 93) suffix.

Another idea would be to use colors like red for First and blue for Second. But too many people have color vision deficiencies for this to be wholly practical. Using font attributes like slant, bold, etc. seems even more problematic.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Notation for games with facing pieces

Post by hgm »

Indeed, it is great that the Chinese 'alphabet' has so many characters, but unfortunately they miss the distinction lower-case / upper-case...
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Another idea for ideographs

Post by sje »

Another idea for ideographs is to select from the large family of Unicode Emoji glyphs.

Here are some of the Emoji object glyphs; they may not display properly in some browsers:

🎍💝🎎🎒🎓🎏🎆🎇🎐🎑🎃👻🎅🎄🎁🎋🎉🎊🎈🎌🔮🎥📷📹📼💿📀💽💾💻🔍
📱☎📞📟📠📡📺📻🔊🔉🔈🔇🔔🔕📢📣⏳⌛⏰⌚🔓🔒🔏🔐🔑🔎💡🔦🔆🔅🔌🔋🛁🛀🚿
🚽🔧🔩🔨🚪🚬💣🔫🔪💊💉💰💴💵💷💶💳💸📲📧📥📤✉📩📨📯📫📪📬📭
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Rationale

Post by sje »

The reason I took the time to calculate the maximum character length of a FEN string was that I had been using a 256 character limit for a general text line several places in Symbolic. But this is really sloppy programming, as was use of a 4,096 character limit for an extra huge text line.

These limits are now gone and exact values are used depending on context. In places where no limit can be ascertained, a dynamic allocation is performed.

----

Have you noticed how the Emoji glyphs can be scaled? I can enlarge the Pager (📟) to read the displayed phone number easily.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Unicode chess glyphs

Post by sje »

Standard Unicode chess glyphs:

♔♕♖♗♘♙♚♛♜♝♞♟

Small, aren't they?

Can they be enlarged? Huge size:

♔♕♖♗♘♙♚♛♜♝♞♟

Can they be shrunk? Tiny size:

♔♕♖♗♘♙♚♛♜♝♞♟