This python 2 code snippet uses unicode chess symbols and box drawings symbols to display a chessboard in a terminal. With a terminal profile having a monospace font of size 20 or more, it looks quite usable to play chess.
Related Article:os.listdir with Unicode in Python 3
is a solved Python discussion thread by soltak that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: python, unicode.
I tried running the code in Python 2.5, but there was an error:
♙♘♗♖♕♔♚♛♜♝♞♟
│ ─ ┌ ┐ └ ┘ ┬ ┴ ├ ┤ ┼
Traceback (most recent call last):
File "C:/Users/Owen/Desktop/chess/chess8.py", line 52, in <module>
print game(start_position)
File "C:/Users/Owen/Desktop/chess/chess8.py", line 47, in <lambda>
game = lambda squares: "\n".join(_game(squares))
File "C:/Users/Owen/Desktop/chess/chess8.py", line 42, in _game
yield inter(*position[0])
File "C:/Users/Owen/Desktop/chess/chess8.py", line 24, in inter
return vbar + u''.join((tpl.format(pieces[a]) for a in args))
File "C:/Users/Owen/Desktop/chess/chess8.py", line 24, in <genexpr>
return vbar + u''.join((tpl.format(pieces[a]) for a in args))
AttributeError: 'unicode' object has no attribute 'format'
It has been a long time since I last used python 2.5. Can't you upgrade to 2.7 ? The following should work for 2.5: replace line 28 with tpl = u' %s ' + vbar and replace tpl.format(pieces[a]) with tpl % pieces[a] in line 39. The format() method appeared in 2.6. It is now widely used.
Hi, I am probably having some compability issues with my python 3, but if I run the script I get the following error message:
File "/home/user/Dokumente/Python/scripts/PyEncyclopedia/Snippets/chessboard.py", line 15
pieces = u''.join(unichr(9812 + x) for x in range(12))
^
SyntaxError: invalid syntax
I checked it, and as far as I can see everything seems fine. Any ideas?
But thanks for the snippet at any rate, I was able to take quite a lot for myself from it!