-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing.py
97 lines (80 loc) · 1.84 KB
/
printing.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from termcolor import colored, cprint
from board import colors, pieces, getBoard
print_white = lambda x: cprint( x, "white", "on_green" )
print_black = lambda x: cprint( x, "grey", "on_green" )
print_red = lambda x: cprint( x, "red" )
print_info = lambda x: print( x )
text_white = lambda x: colored( x, "white", "on_green" )
text_black = lambda x: colored( x, "grey", "on_green" )
text_info = lambda x: x
bgcol = "on_green" #Ugly global code
def text_board( x, col = "" ):
global bgcol
if col == "":
out = colored( x + " ", "grey", bgcol )
elif col == colors["white"]:
out = colored( x + " ", "white", bgcol )
else:
out = colored( x + " ", "grey", bgcol )
if bgcol == "on_green":
bgcol = "on_blue"
else:
bgcol = "on_green"
return out
def newline_board():
global bgcol
if bgcol == "on_green":
bgcol = "on_blue"
else:
bgcol = "on_green"
return "\n"
def clearScreen():
global bgcol
bgcol = "on_green"
os.system( "clear" )
piecesPrint = {
# colors["white"]: {
# "p": "♙",
# "r": "♖",
# "k": "♘",
# "b": "♗",
# "x": "♔",
# "q": "♕"
# },
colors["black"]: {
"p": "♟",
"r": "♜",
"k": "♞",
"b": "♝",
"x": "♚",
"q": "♛"
},
colors["white"]: {
"p": "♟",
"r": "♜",
"k": "♞",
"b": "♝",
"x": "♚",
"q": "♛"
}
}
def printBoard():
text = ""
i = 9
text += text_info( " a b c d e f g h\n" )
for row in getBoard():
i -= 1
text += text_info( str( i ) + " " )
for piece in row:
if piece == " ":
text += text_board( " " )
else:
text += text_board( piecesPrint[ piece[1] ][ piece[0] ], piece[1] )
#elif piece[1] == colors["white"]:
# text += text_white( piece[0] ) + text_white( " " )
#elif piece[1] == colors["black"]:
# text += text_black( piece[0] ) + text_black( " " )
text += newline_board()
clearScreen()
print( text + "\n" )