我想对我应该如何构建我的功能评论的建议。是不是我现在的描述太深入了?在
下面的代码是用于解决n皇后问题的算法。在def hill_climbing(initial_board):
"""
While the current Board object has lower heuristic value successors, neighbour is randomly assigned to one.
If the current Board's heuristic value is less than or equal to its neighbour's, the current Board object is
returned. Else, the current variable is assigned the neighbour Board object and the while loop continues until
either the current Board has no better successors, or current's h value is less than or equal to all of its
successors.
:param initial_board: A Board object with a randomly generated state, and successor_type of "best".
i.e. a start state
:return: A Board object that has no further successors. i.e. a goal state (Local/Global Minimum)
"""
current = initial_board
while current.has_successors():
neighbour = Board(current.get_random_successor(), "best")
if neighbour.value() >= current.value():
return current
current = neighbour
return current