Skip to content

Instantly share code, notes, and snippets.

@Recursing
Created July 29, 2019 11:31
Show Gist options
  • Save Recursing/4837fe2ad1921286cf299145367b00f5 to your computer and use it in GitHub Desktop.
Save Recursing/4837fe2ad1921286cf299145367b00f5 to your computer and use it in GitHub Desktop.
Test terminal colors
def print_pos(board):
print()
uni_pieces = {
"r": "♜", "n": "♞", "b": "♝", "q": "♛", "k": "♚", "p": "♟",
"R": "♖", "N": "♘", "B": "♗", "Q": "♕", "K": "♔", "P": "♙", ".": "·"}
colors = ["\x1b[48;5;255m", "\x1b[48;5;253m"]
sc, ec = "\x1b[0;30;107m", "\x1b[0m"
for i, row in enumerate(board.split()):
colored = [colors[(i + c) % 2] + uni_pieces[p] for c, p in enumerate(row)]
print(" ", sc, 8 - i, " ".join(colored), ec)
print(" ", sc, " a b c d e f g h", ec, "\n")
initial = (
" \n" # 0 - 9
" \n" # 10 - 19
" rnbqkbnr\n" # 20 - 29
" pppppppp\n" # 30 - 39
" ........\n" # 40 - 49
" ........\n" # 50 - 59
" ........\n" # 60 - 69
" ........\n" # 70 - 79
" PPPPPPPP\n" # 80 - 89
" RNBQKBNR\n" # 90 - 99
" \n" # 100 -109
" \n" # 110 -119
)
pos1 = """ \n
.k.r...r
p.p...p.
..pbbppn
........
........
..N.BN..
PPP..PPP
..KR...R
\n"""
pos2 = """ \n
r...kbnr
ppp..ppp
..n.b.Q.
........
........
..N..B..
PPP..PPP
R.B.K.NR
\n"""
print_pos(initial)
print_pos(pos1)
print_pos(pos2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment