FEN's for other games

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

FEN's for other games

Post by MOBMAT »

I've implemented a number of game engines using MCTS (not yet chess) and I have the need to set up test positions from time to time. Having FEN-like capabilities would be nice, and easy to implement, but I didn't want to reinvent the wheel or create yet another format that might not be in use by others. Is anyone maintaining a list of FEN-like notations for other games? Is this something others would be interested in?
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: FEN's for other games

Post by Ferdy »

Could you tell us an example of what these other games are?

Download winboard, run it and load Fairy-Max. File->New Variant, select your variant, then Edit->Copy Position to Clipboard.

Examples:

Variant Falcon
[d]rnbfqkfbnr/pppppppppp/10/10/10/10/PPPPPPPPPP/RNBFQKFBNR w KQkq - 0 1

Variant Seirawan
[d]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[HEhe] w KGFDCBQkgfdcbq - 0 1

Load Sjaak, Crazywa and other engines with variants supports and do the same.

Be noted that winboard shogi fen and usi fen are not the same.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: FEN's for other games

Post by hgm »

What 'other games' are you talking about? WinBoard supports a whole range of chess variants, and 'support' also means that copy/pasting of positions through FENs, and transmitting them to the engine should work. The WinBoard Alien Edition even supports some games that are not chess variants (Checkers/Draughts, Amazons, Othello/Reversi, Go); it also uses FEN to describe their positions.

'Forsyth Notation' to describe a board position is quite universal; in principal it would work with any two-player game where board cells can be occupied by single pieces, which can be identified by a single letter code. Even for non-square boards, as long as there is an agreed-upon way to scan the board. Some games (especially chess variants) have some 'hidden game state', such as castling or e.p. rights, and 50-move counter. These require extra fields in the FEN to specify. In variants where pieces still participating in the game can be off board, a field should be present to indicate what the players have 'in hand'. (The 'hand' is not just an extra ordinary board square, because typically it can contain multiple pieces.)

Extra FEN fields used by WinBoard are the hand (immediately after the board, between brackets []), and the 'remaining checks counter' (N+M) for variant 3check. The castling field is generalized to a 'virginity field', indicating which pieces have not moved yet, when that is relevant (e.g. in Seirawan Chess, whether you still can gate hand pieces there). In games with Berolina Pawns the e.p. field has to indicate both the square moved through, and the Pawn that moved.

To prevent proliferation of piece IDs in games where pieces that move the same are yet different, there are some extra notation devices in the board part. E.g. in Crazyhouse it is important to know whether a Queen is a promoted Pawn (which will revert to Pawn on capture), or a real Queen, and a tilde (~) suffix behind a piece will indicate that (Q~ vs Q). In Shogi almost all piece types promote, and a promoted X is usually indicated as +X in the FEN. Even if the move of a +X would be identical to that of some other participating piece Y (because on capture, +X would revert to x, while Y would stay y, when they get in hand).

So the main concern is to have an agreed-upon ID for each participating piece type. When there are many piece types, this sometimes forces the use of unnatural IDs (like A for Reverse Chariot in Chu Shogi, which has 21 unpromoted piece types). When there are more than 26 piece types the latest versions of WinBoard offer the possibility to use 'dressed letters' as piece ID, i.e. a letter followed by a quote or exclamation point, to triple the maximum number of piece types.
MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

Re: FEN's for other games

Post by MOBMAT »

I did say (not yet Chess), so pick one. checkers, othello, clobber, breakthrough, GO. anything BUT chess. FEN was designed to provide a solution for chess. I am proposing a similar solution for other games. I never want to believe I'm the first person to think of something, so hence the question. I'll use TTT as an example:

XXO/OOX/X2 O

The same idea applies to any game. <board position> <stm> <extras>
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: FEN's for other games

Post by hgm »

This violates the FEN standard in several ways:
* You indicate empty squares separately, instead of combining a contiguous range and write their number
* You use upper ccase for both players
* You indicate the same piece type by different IDs

WinBoard would allow the latter. But a Tic-Tac-Toe engine for WinBoard (I don't think there exists one) would have to use

XXx/xxX/X2 b

Or, possibly

XXo/ooX/X2 b
MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

Re: FEN's for other games

Post by MOBMAT »

Thanks, Harm, now we are getting somewhere.
I appreciate your input. I think the FEN standard can work.
* You indicate empty squares separately, instead of combining a contiguous range and write their number
I had corrected my post to change the "--" to a 2.

It appears the main decision is to what to refer to the piece types in games where the pieces aren't really named. In the description of games, they usually refer to them as pieces, marks, etc., and different authors are not consistent. Checkers though, for example has 2 piece types, the "checker" piece and the "kings", so it is logical to refer to the kings by using a 'k' and a 'K', and the non-kings with a c/C
In Amazons, there are queens (q and Q) and arrows (a and A).

PS, I didn't see your post about Winboard, I will research their implementation.
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
User avatar
Ajedrecista
Posts: 1966
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: FEN's for other games.

Post by Ajedrecista »

Hello:
MOBMAT wrote: Wed Aug 21, 2019 3:38 pm Thanks, Harm, now we are getting somewhere.
I appreciate your input. I think the FEN standard can work.
* You indicate empty squares separately, instead of combining a contiguous range and write their number
I had corrected my post to change the "--" to a 2.

It appears the main decision is to what to refer to the piece types in games where the pieces aren't really named. In the description of games, they usually refer to them as pieces, marks, etc., and different authors are not consistent. Checkers though, for example has 2 piece types, the "checker" piece and the "kings", so it is logical to refer to the kings by using a 'k' and a 'K', and the non-kings with a c/C
In Amazons, there are queens (q and Q) and arrows (a and A).

PS, I didn't see your post about Winboard, I will research their implementation.
Just for the record, FEN for checkers already exists:

Portable Draughts Notation (PDN).

This FEN is based on a numbered board, which can be seen here. However, there are more variants of checkers and the squares can be named in a different way. The example shown above is valid for English draughts/American checkers. Just for comparison, please take a look on the numbered board of Spanish draughts from the cover page of a book of 1597:

Image

Where low numbers stand for white pieces at the start of the game, that are first to move in Spanish draughts; just the opposite that English draughts, where low numbers stand for black pieces at the start of the game, that are first to move. Not to mention the squares where checkers are played: light on right for both variants (like chess) but light squares in Spanish variant and dark squares in English/American variant.

There are some clues about checkers/draughts variants at Wikipedia and Internet, including different board sizes like for example 10x10 (International draughts) or 12x12 (Canadian checkers).

There are some valuable links at the bottom of the Wikipedia article about PDN (External links) that give more details of PDN specifications. A list of codes for variants can be found at the Wikipedia article of PDN.

Good luck with other games such as Othello/Reversi, Connect-Four and Go!

Regards from Spain.

Ajedrecista.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: FEN's for other games

Post by hgm »

I suppose this can be summarized by saying that PDN doesn't use any FEN in its FEN tag, but a completely different notation.

Of course one of the peculiarity of most Checkers/Draughts variants is that they only use one shade of a checkered board. It would be a bit wasteful to mention the unused squares as empty squares in the position encoding. Assuming the board topology is known, it would be more compact to encode it as a 4x8 or 5x10 board.

Note that the same holds for chess variants with an irregular board shape. Such as Omega Chess, which has the Wizard squares dangling from the corners. Assuming the board shape is known, this would allow encoding positions as a FEN with only two elements on the 1st and 12th rank, and 10 on the remaining ranks. In WinBoard protocol, however, the FEN is also used to define board topology in variants for which the GUI does not know it (in the 'setup' command). So it really must use a full 12x12 FEN for Omega Chess positions, indicating the unused squares along the edges as 'holes' by means of an asterisk.

As to the naming of pieces: this indeed is a major problem with engine-defined variants. Two engines might implement the same variant, but use different IDs for the pieces. This can already happen in Chess, because different languages use different names for the sam piece. But it is worse in chess variants, where the same piece can be known under many different names in the same language (e.g. Archbishop = Cardinal; Chancellor = Marshall).