added is_empty method, cleaned Game repr
parent
8868e919b5
commit
fcd2f7d62a
11
chess.py
11
chess.py
|
@ -39,11 +39,12 @@ class Game:
|
||||||
for rank in ranks:
|
for rank in ranks:
|
||||||
r += rank + " |"
|
r += rank + " |"
|
||||||
for file in files:
|
for file in files:
|
||||||
piece = self.board[file+rank]
|
sq = file+rank
|
||||||
if piece.piece == None:
|
r += " "
|
||||||
|
if self.is_empty(sq):
|
||||||
r += " "
|
r += " "
|
||||||
else:
|
else:
|
||||||
r += " " + repr(piece)
|
r += repr(self.board[sq])
|
||||||
r += "\n"
|
r += "\n"
|
||||||
r += " +" + "-"*16 + "\n"
|
r += " +" + "-"*16 + "\n"
|
||||||
r += " "*4 + " ".join(list(files))
|
r += " "*4 + " ".join(list(files))
|
||||||
|
@ -61,6 +62,10 @@ class Game:
|
||||||
for sq in cross(files, "78"):
|
for sq in cross(files, "78"):
|
||||||
self.board[sq].color = "black"
|
self.board[sq].color = "black"
|
||||||
|
|
||||||
|
def is_empty(self, sq):
|
||||||
|
return self.board[sq].piece == None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
|
Loading…
Reference in New Issue