forked from niklasf/python-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_output.py
More file actions
33 lines (29 loc) · 1.18 KB
/
html_output.py
File metadata and controls
33 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
"""Renders scholar's mate in the file `scholars_mate.html`."""
import chess
import chess.html
import chess.svg
def main():
board = chess.Board()
chess.Move.from_uci("a8a1") in board.legal_moves
board.push_san("e4")
board.push_san("e5")
board.push_san("Qh5")
board.push_san("Nc6")
board.push_san("Bc4")
board.push_san("Nf6")
board.push_san("Qxf7")
table = chess.html.board(board, lastmove=board.peek(),
check=board.pieces(chess.KING,chess.BLACK).pop())
svg = chess.svg.board(board, lastmove=board.peek(), size=800,
check=board.pieces(chess.KING,chess.BLACK).pop())
html = """<!doctype html><html><head><title>python-chess output</title>
<style>h1{{text-align:center;}}section,footer{{width:850px;margin:auto}}
{0}</style></head><body><section><h1>HTML Table Output</h1>{1}</section>
<section><h1>SVG Output</h1>{2}</section><footer>Generated by
<code>python-chess/examples/html_output.py</code></footer>
""".format(chess.html.DEFAULT_STYLE, table, svg)
with open('scholars_mate.html', 'w') as f:
f.write(html)
if __name__ == '__main__':
main()