1/* Part of SWISH 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (c) 2014-2016, VU University Amsterdam 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright 17 notice, this list of conditions and the following disclaimer in 18 the documentation and/or other materials provided with the 19 distribution. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33*/ 34 35:- module(swish_render_tiles, 36 [ term_rendering//3 % +Term, +Vars, +Options 37 ]). 38:- use_module(library(http/html_write)). 39:- use_module('../render'). 40 41:- register_renderer(tiles, "Render chess board representations").
60term_rendering(Term, _Vars, _Options) --> 61 { is_map(Term,Tiles), 62 Term=..[_,_|Rows], 63 length(Rows, N), 64 LineHeight0 is ceiling(500/N), 65 (LineHeight0>32-> 66 LineHeight=LineHeight0 67 ; 68 LineHeight=32 69 ) 70 }, 71 html(div([ style('display:inline-block;' 72 ), 73 'data-render'('Tile map') 74 ], 75 [table(\tiles(Rows,Tiles,LineHeight)), 76 \tile_map_style 77 ])). 78 79is_map(Term,Tiles) :- 80 Term=..[map,Tiles,R1|Rows], 81 is_list(Tiles), 82 R1=..[_|Row1], 83 length(Row1,W), 84 maplist(row_length(W),Rows). 85 86row_length(W,Row):- 87 Row=..[row|R], 88 length(R,W). 89 90tiles([],_Tiles,_Width) --> []. 91tiles([H|T],Tiles,Width) --> 92 {H=..[_|Row]}, 93 html(tr(\nrow(Row,Tiles,Width))), 94 tiles(T,Tiles,Width). 95 96nrow([],_Tiles,_Width) --> !. 97nrow([Tile|TTiles],Tiles,Width) --> 98 { member(tile(Tile,URL),Tiles) }, 99 html(td(img([src(URL),alt(Tile),width(Width)],[]))), 100 nrow(TTiles,Tiles,Width). 101 102 103tile_map_style --> 104 html({|html|| 105<style> 106table { border-collapse: collapse; padding: 0px; } 107table tr td { padding: 0px; border-collapse: collapse;} 108</style> 109 |})
SWISH chessboard renderer
Render chessboards. Currently only deals with the N-queens problem. This file is nevertheless called
chess.pl
because it should be trivial to extend this to more general chess positions.The styling is a small modification of CSS3 Chess Board */