Rework board display and human interaction

This commit is contained in:
Yorick Barbanneau 2023-12-21 23:09:04 +01:00
parent d846549bb7
commit 507964cd6b
2 changed files with 27 additions and 15 deletions

View file

@ -103,7 +103,7 @@ class HumanPlayerEngine(PlayerEngine):
move = None
while move is None:
user_input = input("Please enter player {} move, `print` to display board and `help` possible moves : ".format(
self.get_player_name(self.player)
self._get_player_name(self.player)
))
move = self.validate_input(user_input, board)
return move
@ -114,23 +114,33 @@ class HumanPlayerEngine(PlayerEngine):
@param input: string
@return: array
"""
@staticmethod
def validate_input(input, board):
def validate_input(self, input, board):
if input == 'print':
print(board.show_board())
print("\n{}".format(board.show_board()))
return None
if input == 'help':
print('{}'.format(board.legal_moves()))
text = "Possible move:"
for m in board.legal_moves():
text += " {}{}".format(chr(65+m[1]), m[2])
print(text)
return None
if len(input) != 2:
self.logger.error("Input coordinate (A1 for example), help or print")
return None
x = int(input[0])
x = ord(input[0]) - 65
y = int(input[1])
if not board.is_valid_move(board._nextPlayer, x, y):
return None
try:
if not board.is_valid_move(board._nextPlayer, x, y):
self.logger.error("Move is not possible at this place")
return None
except IndexError:
self.logger.error("Invalid input must be [A-J][0-9] (was {})".format(input))
return None
return [board._nextPlayer, x, y]