From fcd2f7d62a3cb3eff449602b3ccb80367a61c7af Mon Sep 17 00:00:00 2001 From: Tibor Bizjak Date: Tue, 3 Sep 2019 20:50:52 +0200 Subject: [PATCH] added is_empty method, cleaned Game repr --- chess.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chess.py b/chess.py index 85ec1b8..2ebcdf3 100644 --- a/chess.py +++ b/chess.py @@ -39,11 +39,12 @@ class Game: for rank in ranks: r += rank + " |" for file in files: - piece = self.board[file+rank] - if piece.piece == None: - r += " " + sq = file+rank + r += " " + if self.is_empty(sq): + r += " " else: - r += " " + repr(piece) + r += repr(self.board[sq]) r += "\n" r += " +" + "-"*16 + "\n" r += " "*4 + " ".join(list(files)) @@ -61,6 +62,10 @@ class Game: for sq in cross(files, "78"): self.board[sq].color = "black" + def is_empty(self, sq): + return self.board[sq].piece == None + + def test():