首先 - 是的,这是一个家庭作业 - 但它主要是一个理论问题,而不是一个实际问题,我只是要求确认我是否正确思考或任何提示,如果我不正确。
我被要求编译一个简单的 Sudoku 求解器(在Prolog上,但现在并不那么重要),唯一的限制是它必须使用使用Best-First Algorithm的启发式函数。我能想出的唯一启发式函数解释如下:
1. Select an empty cell.
1a. If there are no empty cells and there is a solution return solution.
Else return No.
2. Find all possible values it can hold. %% It can't take values currently assigned to cells on the same line/column/box.
3. Set to all those values a heuristic number starting from 1.
4. Pick the value whose heuristic number is the lowest && you haven't checked yet.
4a. If there are no more values return no.
5. If a solution is not found: GoTo 1.
Else Return Solution.
// I am sorry for errors in this "pseudo code." If you want any clarification let me know.
那么我这样做是对的还是有其他方法而我的方法是错误的?提前致谢。