diff options
Diffstat (limited to 'imago/gameLogic/gameBoard.py')
-rw-r--r-- | imago/gameLogic/gameBoard.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/imago/gameLogic/gameBoard.py b/imago/gameLogic/gameBoard.py index 611c4cb..d0e22a6 100644 --- a/imago/gameLogic/gameBoard.py +++ b/imago/gameLogic/gameBoard.py @@ -110,9 +110,12 @@ class GameBoard: containing the vertices where stones were captured. """ - if (row < 0 or row >= self.getBoardHeight() - or col < 0 or col >= self.getBoardWidth()): - raise RuntimeError("[ERROR] Move and capture: out of bounds (%d, %d)" % (row, col)) + try: + if (row < 0 or row >= self.getBoardHeight() + or col < 0 or col >= self.getBoardWidth()): + raise RuntimeError("[ERROR] Move and capture: out of bounds (%d, %d)" % (row, col)) + except Exception as err: + raise RuntimeError("[ERROR] Move and capture: Wrong input: %s" % err) self.board[row][col] = player @@ -273,8 +276,8 @@ class GameBoard: return False return True - def printBoard(self): - """Print the board.""" + def toString(self): + """Returns a representation of the state of the board as a string.""" colTitle = 'A' rowTitlePadding = 2 if self.getBoardHeight() >= 10: @@ -289,7 +292,7 @@ class GameBoard: colTitle = chr(ord(colTitle)+1) if colTitle == "I": # Skip I colTitle = "J" - print(rowText) + output = rowText # Print rows rowTitle = self.getBoardHeight() @@ -297,11 +300,17 @@ class GameBoard: rowText = "" for col in row: rowText += cellToString(col) + " " - print(str(rowTitle) + " " * rowTitlePadding + rowText) + output += '\n%d%s%s' % (rowTitle, " " * rowTitlePadding, rowText) rowTitle -= 1 if rowTitle == 9: rowTitlePadding += 1 + return output + + def printBoard(self): + """Print the board.""" + print(self.toString()) + def cellToString(code): """Returns the text representation of a cell.""" if code == Player.WHITE: |