There is an example [1] of an APL chess board built with a Grid control and Unicode.
Here's a side-by-side comparison of the same approach done in J.
ChessPieces←⊃'♔♕♖♗♘♙' '♚♛♜♝♞♟' Officers←3 5 4 2 1 4 5 3 ⋄ Pawns←6 White Black←1 2 ix←Black White∘.,Officers,8⍴Pawns Pieces←4 8⍴ChessPieces[0 ¯8⌽ix] Board←(2⌽4/1 0)⍀Pieces 'Chess' ⎕WC 'Form' 'Uni-Chess Beta'(40 20)(341 381)'Pixel' 'Chess' ⎕WS 'Font' 'Arial Unicode MS' 30 'Chess.Board' ⎕WC 'Grid' Board (0 0) Chess.Size Chess.Board.(TitleWidth CellWidths←60 40) Chess.Board.ColTitles←,¨'ΑΒΓΔΕΖΗΘ' Chess.Board.BCol←(192 192 192)(127 127 127) Chess.Board.CellTypes←(⍳8)⌽8 8⍴2 1 Chess.Board.RowTitles←,¨⎕UCS 8543+⌽⍳8 Chess.Board.(Values[5 7;3]←Values[7 5;3])achessbrd.txt |
load 'grid'
Pieces=: uucp"1 '♟♜♞♝♛♚',:'♙♖♘♗♕♔'
'Officers Pawns Black White'=: 1 2 3 4 5 3 2 1;0;0;1
Board=: (, _6&{.)/ Pieces {~ (Black,White);each(; |.)Officers,:Pawns
F=: ('Arial Unicode MS';'DejaVu Sans';'sansserif'){::~(;:'Win Linux')i.<UNAME
G=: ,:'cellcolor' ; }."1]2|i.8 9
G=: G,'hdrcol' ; < <"0 uucp 'ΑΒΓΔΕΖΗΘ'
G=: G,'hdrrow' ; < <"0]4 u: 8544+i._8
G=: G,'cellfonts' ; < <'"',F,'" 16'
G=: G,'hdrfont' ; '"',F,'" 16'
G grid <"0 Board=. Board (<6 4;2) }~ (<4 6;2) { Board
wd 'pn *J Chess Board'
jchessbrd.txt |
|
|
References
Morten Kromberg, Unicode Support for APL, Vector 24, N°1, 2009
Thanks to RicSherlock for suggestions regarding the Grid options and cross-platform font support.
Contributed by OlegKobchenko
