Skip to content

Instantly share code, notes, and snippets.

@Nocks
Last active January 25, 2017 13:28
Show Gist options
  • Save Nocks/7b2498d078800eceff3ff70493611da4 to your computer and use it in GitHub Desktop.
Save Nocks/7b2498d078800eceff3ff70493611da4 to your computer and use it in GitHub Desktop.
def process_placement(self, player):
for current_ship in player.ships:
player.current_ship_name = current_ship[0]
player.current_ship_length = current_ship[1]
player.current_ship = current_ship
while True:
# Placement_point is the input from the player (a2, d3, etc)
placement_point = self.ask_for_placement(
player.name,
player.current_ship_name,
player.current_ship_length
)
player.current_placement_point = placement_point
# Check to see if the input from the player is in the right format
if self.validate_placement(player.current_placement_point):
# Convert player input into a format that can be used
cordinate = self.convert_ship_spot(player.current_placement_point)
player.current_cordinate = cordinate
# Ask player whether ship is vertical dor horizontal
orientation = self.ask_for_orientation(current_ship[0])
player.current_orientation = orientation
# if correctly placed, then break
if player.board.check_board_range(current_ship[1], placement_point, cordinate, orientation):
generated_occupied_spots = player.board.generate_occupied_spots(
player,
current_ship,
cordinate,
orientation)
# The prints here is just for me to keep track of what's going on
print(generated_occupied_spots)
for occupied_spot in generated_occupied_spots:
# The prints here is just for me to keep track of what's going on
print(occupied_spot)
print(player.occupied_spots)
if not occupied_spot in player.occupied_spots:
player.board.update_occupied_spots(player, occupied_spot)
break
else:
print("\n***Sorry! {} overlaps with another ship at {}***"
.format(current_ship[0], placement_point))
continue
else:
print("\n***Sorry! {} cannot fit on the board at {}***"
.format(current_ship[0], placement_point))
continue
else:
print(self.error_input.format(placement_point))
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment