Skip to content

Commit

Permalink
fix bug in make_move
Browse files Browse the repository at this point in the history
  • Loading branch information
xXUnique31Xx committed Jul 1, 2024
1 parent 5cd52b4 commit 17ab686
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ def move(self):
same_score.sort()
x_move, y_move = same_score[0][0]
output.close()
self.board.move_piece(x_move, y_move)
return x_move, y_move
2 changes: 1 addition & 1 deletion controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def start_game(self):
if self.board.ai:
while self.board.check_for_king():
if self.board.currently_playing == 'Black':
self.player_black.make_move()
self.player_black.make_move(self.board)
else:
self.get_input()
else:
Expand Down
19 changes: 16 additions & 3 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,20 @@ def __init__(self, color, board, view, enemy):
self.game_ai = GameAI(board, view, color, enemy)
self.view = view

def make_move(self):
def make_move(self, board, update=True):
"""Method to make a move."""
self.game_ai.move()
self.view.update_board()
start_pos, goal_pos = self.game_ai.move()

piece = board.board_state[start_pos]
if piece and piece.colour == self.color:
if piece.check_legal_move(goal_pos):
board.update_positions(piece, start_pos, goal_pos, update)
board.toggle_player()
else:
GameView.display_message('Illegal move! Please try again!')
self.game_manager.get_input()
else:
GameView.display_message('There is no piece of your color on this space. Please try again!')
self.game_manager.get_input()
if update:
self.view.update_board()

0 comments on commit 17ab686

Please sign in to comment.