From 1079aca0bdb6cdc2e81b09546766d201817246a3 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 20 Aug 2014 09:01:57 -0400 Subject: [PATCH] Fix up board with unicode characters. --- justcheckers/game/board.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/justcheckers/game/board.py b/justcheckers/game/board.py index f5bde17..2a0ef98 100644 --- a/justcheckers/game/board.py +++ b/justcheckers/game/board.py @@ -59,7 +59,7 @@ class Board(object): def __init__(self, size=rules.Rules.STANDARD_BOARD_SIZE, mirrored=False): self.board_size = size - self._board = [[]] + self._board = [[Square.EMPTY for y in xrange(0, self.board_size)] for x in xrange(0, self.board_size)] # /** # * Clears the board of pieces. Creates a brand new empty board already laid @@ -324,30 +324,31 @@ class Board(object): # * @return A string representing the current board state. # */ def __str__(self): + # Prepare for output with a nice looking to banner. output = " " for row in xrange(0, self.board_size): if row < 9: - output = '{}{}{}'.format(output, " ", row + 1) + output = '{} {} '.format(output, row + 1) else: - output = '{}{}{}'.format(output, " ", row + 1) + output = '{} {}'.format(output, row + 1) output = output + "\n\n" output_atom = { - Square.WHITE: "## ", - Square.EMPTY: "__ ", - Square.LIGHT_PAWN: "LP ", - Square.LIGHT_KING: "LK ", - Square.DARK_PAWN: "DP ", - Square.DARK_KING:"DK ", + Square.WHITE: u"\u2588\u2588\u2588", + Square.EMPTY: u" ", + Square.LIGHT_PAWN: u" \u2659 ", + Square.LIGHT_KING: u" \u2654 ", + Square.DARK_PAWN: u" \u265F ", + Square.DARK_KING: u" \u265A ", } # Go row by row, printing out the row number and the board's state. for row in xrange(0, self.board_size): if row < 9: - output = '{}{}{}'.format(output, " ", row + 1) + output = u'{}{} '.format(output, row + 1) else: - output = '{}{}{}'.format(output, " ", row + 1) + output = u'{}{} '.format(output, row + 1) # // Get current row's state. for col in xrange(0, self.board_size):