Display game board with Board.show_board()

This commit is contained in:
Yorick Barbanneau 2023-12-15 01:43:44 +01:00
parent 7b49cac308
commit 3784faeaed
2 changed files with 14 additions and 3 deletions

View file

@ -35,14 +35,13 @@ class HumanPlayerEngine(PlayerEngine):
user_input = input("Please enter player {} move, `print` to display board and `help` possible moves : ".format( user_input = input("Please enter player {} move, `print` to display board and `help` possible moves : ".format(
self.get_player_name(board._nextPlayer) self.get_player_name(board._nextPlayer)
)) ))
move = self.validate_input(user_input, board, player) move = self.validate_input(user_input, board)
print("{}".format(move))
return move return move
@staticmethod @staticmethod
def validate_input(input, board): def validate_input(input, board):
if input == 'print': if input == 'print':
print("\n{}".format(board.__str__)) print(board.show_board())
return None return None
if input == 'help': if input == 'help':

View file

@ -216,6 +216,18 @@ class Board:
else: else:
return '.' return '.'
def show_board(self):
display = " |"
for x in range(self.get_board_size()):
display += "{}|".format(str(x))
display += "\n"
for x in range(self.get_board_size()):
display += "{}|".format(str(x))
for y in range(self.get_board_size()):
display += "{}|".format(self._piece2str(self._board[x][y]))
display += "\n"
return display
def __str__(self): def __str__(self):
toreturn="" toreturn=""
for l in self._board: for l in self._board: