Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def queen_left(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_col > 0:
- current_col -= step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_right(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_col < size - 1:
- current_col += step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_up(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row > 0:
- current_row -= step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_down(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row < size - 1:
- current_row += step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_up_right(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row > 0 and current_col < size - 1:
- current_row -= step
- current_col += step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_up_left(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row > 0 and current_col > 0:
- current_row -= step
- current_col -= step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_down_right(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row < size - 1 and current_col < size - 1:
- current_row += step
- current_col += step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- def queen_down_left(k_row, k_col, field_, step=1):
- current_row, current_col = k_row, k_col
- while current_row < size - 1 and current_col > 0:
- current_row += step
- current_col -= step
- if field_[current_row][current_col] == 'Q':
- return current_row, current_col
- return False
- size = 8
- king_row, king_col = None, None
- field = []
- queens = []
- for row in range(size):
- field.append(input().split())
- if 'K' in field[row]:
- king_row, king_col = row, field[row].index('K')
- functions_reference_list = [queen_left, queen_right, queen_up, queen_down, queen_down_left, queen_down_right,
- queen_up_left, queen_up_right]
- for function in functions_reference_list:
- if function(king_row, king_col, field):
- queens.append(list(function(king_row, king_col, field)))
- if not queens:
- print('The king is safe!')
- else:
- print(*queens, sep='\n')
Advertisement
Add Comment
Please, Sign In to add comment