Variant Chess in FENipulator

Thu 2012.01.12
by brian hefele

FENipulator 1.5-1.7 have been released, and they are all about chess variants. The full changelog reveals all the saucy details, but I’ll point out the big ones here. First, in order to accommodate certain chess variants, two fairy pieces have been added to the unicode and simple piecesets — the archbishop and the chancellor. They correspond to FEN a and c, and are represented as such in the simple set. In the unicode set, the archbishop is a bishop rotated 90º, and the chancellor a rook rotated 90º. Additionally, my friend and sometimes design partner Alex Coblentz has illustrated six or seven new piecesets which I am slowly building into files and adding as time permits. They’re pretty awesome, and I’m pretty excited about them.


960 (Fischer Random) Chess

The first variant to make its way into FENipulator is 960 chess. 960 is a randomized opening, adhering to certain rules — home ranks match between players, bishops are counter-color, king is always between rooks. Castling in 960 is as in orthodox chess (that is, the file the king and rook end up on are the same as in orthodox), which meant a major rewrite of the castling code. New functions were thrown in to determine where the king sits on the board — this is necessary to determine if a rook is a- or h-side. A king must also be able to move onto himself now, because castling in 960 can mean the king (or the rook) never moves.


Large Boards (and Small Boards)

Previous to v1.6, boards were largely hardcoded to be 8×8. Presentation of a smaller board may have been possible, but moving sure wasn’t. Larger boards were out of the question. The board is now entirely flexible, allowing board sizes from 1×1 to 26×26. Theoretically, the code will allow for board size up to 99×99, but files start outputting character codes that confuse it right now — best to stick to only an alphabet’s worth. Several shortcuts have been programmed in for large board variants — submitting ‘gothic,’ ‘embassy,’ ‘capablanca,’ or ‘grand’ for FEN results in the opening boards for the respective games. Unfortunately no custom castling rules have been implemented yet — I’m unsure how castling works in Gothic and Capablanca chess, and Embassy chess will require custom rules. If all three are the same, one rule can exist for a 10-wide board, otherwise I’m not sure how I’ll handle it. In the meantime, castling can be achieved manually by resetting the turn value in FEN and performing two moves. Grand chess doesn’t allow castling, so there is no issue there.


Alice Chess (and Ms. Alice Chess)

Version 1.7 brings a rather fun variant, Alice Chess, playable at fenipulator.brhfl.com/alice.php. Alice is played on two boards, with every move transferring to the opposite board. Every move must be legal on the board it’s played on, and every destination space must be empty on the opposite board. This condition is not yet checked for validity, but probably will be in the future (can be a hassle to keep track of manually). A straight drop (or zero move) is possible (for the variant Ms. Alice Chess) by picking a piece to move, and then clicking it again as the destination. All moves on FENipulator Alice should be done on the same board — then FENipulator Alice handles the transfer. Two shortcuts to common variants are available here as well, by entering ‘small’ or ‘opposite’ into the FEN box. Small is a variant playable on a single board (though FENipulator Alice presents it as two half-boards), and opposite is a variant where black and white start on opposite boards.Since FENipulator works exclusively by manipulating FEN data, a specialized FEN must be used to track two boards. Since I’ve not seen an official solution to this, FENipulator separates both boards with a pipe (|), resulting in a starting FEN board representation of rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR|8/8/8/8/8/8/8/8. There are mixed beliefs bout castling and en passant in Alice, and for now, for the sake of getting the code working at all, neither are possible in FENipulator Alice.

Next up in the short-term are the aforementioned validity checks for Alice, castling and en passant in Alice, and castling on large boards. Also, for the sake of chess problems, &c. a third turn state will be added, allowing universal movement. Shortcuts will be added for orthodox, 960, and Alice, and a page outlining all variant shortcuts will be made. Board flipping is going to be moved to the Options page, with options for always, white, black, and never. After these changes, code needs to be cleaned up, and a core file should be made for code shared between standard and Alice FENipulator. This will help in the future if other board variants are necessary (Omega, for instance).

FENipulator

Thu 2012.01.05
by brian hefele

FENipulator is my latest project, a chess board application written in PHP. I call it a chess board application and not a chess application, because of its dumb nature. With a few small exceptions, it does not care about (or, frankly, know) the rules of chess. It does not, generally speaking, validate anything. It assumes the players are smart and honest enough to play by the rules. It also does not keep track of anything that isn’t a component of Forsyth-Edwards Notation(FEN). It is not connected to a database, it has no sense of state. Rather, it relies entirely on being passed FEN via HTTP-GET. It takes in FEN, allows the player to make a move, and generates new FEN based on the move made.

Let me back up a little bit, and say that as much as I love gaming, chess is almost certainly my favorite game. Correspondence chess systems online have all proven too heavy and complicated for my taste. I decided last night to implement an extremely simple system myself, a system that just simplified the process of getting the state of a chess board back and forth among two players. Play is simple — white clicks a piece to select it, clicks a space to move it to, reviews her move, and copies/pastes a link to the current board state to black. The link can be sent over email, IM, Twitter, whatever. Black does the same, and so on until the game is over. Because no state is ever saved on the server, there’s no overhead for an individual game. Thus, there’s no incentive (or, possibility even) for me to make games time out after so much inactivity, etc. It is, perhaps easiest to simply think of FENipulator as an interface to viewing and manipulating FEN data — hence the name.

Simplicity exists in many aspects of FENipulator. Aside from the aforementioned lack of a database, FENipulator also makes zero use of Javascript. There are no images, pieces are all represented by text. If one wanted, one could use images for pieces and spaces, as all of that is defined in CSS. Every space is a span, every piece is an :after pseudo-element attached to that span. For users who like their board flipped, a setting for this is possible using vendor-specific CSS transforms. Thus, flipping is not available on IE or older browsers, but for users of modern browsers, the possibility is there.

Update: Version 1.4 has all the short-term improvements taken care of except figuring out how I’m going to license the thing (see footnote). I got a bit carried away. Anyway, without going into the full changelog, here’s what has happened since v0.9: pawn promotion (to queen only); en passant (works on board and is recorded in FEN); POST is now used for sending move to/from data instead of GET, this meant switching the spaces from <a> to <button>; some classes added to CSS, making board-flipping easier and more things possible with board display (active state now exists after a move, showing to and from); board state URLs go through urlencode(), so everything validates now; and finally, no spaces are ‘live’ after a move has been made — the user must either choose to send the link or reset the board (the earlier behavior where the user could essentially change their move was unintentional and unpredictable). Anyway, read the footnote about licensing, then download it here, or just play.

As I have not yet determined how to license FENipulator, currently all rights are reserved. This will change soon, I promise. Also, know that while I have tested it, and it should not be able to cause any damage, I assume no liability or responsibility for its installation and/or use.