I think the bug may be found in Player.hide_ships(), but I'm not sure. I think the fact that we're iterating on the contents of self.ship_list while also popping from self.ship_list in the same loop may be the cause. Chat said that it doesn't reread the list every iteration, but idk if I believe it...
Even if it did reread it though, if we're popping the front of the list then it should restart on the proper one, right?
Chat suggested it might be a recursion issue, so I restructured Player.hide_ships() like so to avoid it:
def hide_ships(self):
for _ship in self.ship_list: # Hide all ships
while True:
print(f"Player {self.id} - Hiding their {self.selected_ship()}...")
self.print_board(self.board)
coord = input("Hide the ship: ")
if coord in self.list_of_synonyms_for_quit_lol: # QUIT GAME?
exit()
if self.valid_coord(coord):
# coord = "a5"
# coord => GameObject.letter_to_row_index_map => __hide_ship(0,5) => col, row
# TODO: UPDATE THIS COMMENT (AND FUNCTION) FROM 05 WHEN ROW NUMBERS CHANGE
self.__hide_ship(int(self.letter_to_row_index_map[coord[0].upper()]), int(coord[1])) # Not to be confused with hide_ships()
# self.print_board(self.board)
break
We're getting an output like this ATM. It skips hiding ships.
I think the bug may be found in
Player.hide_ships()
, but I'm not sure. I think the fact that we're iterating on the contents ofself.ship_list
while also popping fromself.ship_list
in the same loop may be the cause. Chat said that it doesn't reread the list every iteration, but idk if I believe it... Even if it did reread it though, if we're popping the front of the list then it should restart on the proper one, right?Chat suggested it might be a recursion issue, so I restructured
Player.hide_ships()
like so to avoid it:This still didn't fix it though, so idk.