-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
executable file
·76 lines (60 loc) · 1.61 KB
/
board.py
File metadata and controls
executable file
·76 lines (60 loc) · 1.61 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
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
#!/usr/bin/python
#
import sys
def from_fenstring(fenstr):
a = fenstr.split('/')
board = []
for rowstr in a:
rowline = []
for piece in rowstr:
if piece.isdigit():
for j in xrange(int(piece)):
rowline.append(' ')
else:
rowline.append(piece)
board.append(rowline)
return board
def row_desc(r):
def conv(c):
return [[' ']*int(x) if x.isdigit() else x for x in c]
def flatten(arr):
return [item for sublist in arr for item in sublist]
return flatten(conv(r))
def row_desc2(r):
result = []
for elem in r:
if elem.isdigit():
for q in [' ']*int(elem):
result.append(q)
else:
result.append(elem)
return result
def fen_desc(F):
board = []
for q in F:
board.append(row_desc2(q))
return board
L = '+---+---+---+---+---+---+---+---+'
M = '| | | | | | | | |'
# 2 6 10
sq = [(2,0),(6,1),(10,2),(14,3),(18,4),(22,5),(26,6),(30,7)]
def draw_board(fenstring):
board = fen_desc(fenstring.split('/'))
for row in xrange(8):
print L
i = 0
for x in M:
def in_sq(n):
for qq in sq:
if n == qq[0]:
return qq[1]
return None
if in_sq(i) is not None:
ident = board[row][in_sq(i)]
sys.stdout.write(ident)
else:
sys.stdout.write(x)
i = i + 1
print "\n",
print L
draw_board(sys.argv[1])