过去几周我一直在玩数独游戏。 游戏中有很多功能,如:玩游戏,打印数独,解决数独。
求解功能使用传统的回溯,但这不是问题,问题是我需要游戏能够产生一个人道可解的数独,因为我需要一个能够解决数独作为人类的方法会做的。
如果有人能帮助我找出如何做到这一点的机制,我将非常感激。
答案 0 :(得分:3)
在Andrew Stuart's Sudoku page上很好地呈现并解释了压倒性的人类玩家 Sudoku 解决策略集合:
**Show Possibles** 1: Hidden Singles 2: Naked Pairs/Triples 3: Hidden Pairs/Triples 4: Naked Quads 5: Pointing Pairs 6: Box/Line Reduction **Tough Strategies** 7: X-Wing 8: Simple Colouring 9: Y-Wing 10: Sword-Fish 11: XYZ Wing **Diabolical Strategies** 12: X-Cycles 13: XY-Chain 14: 3D Medusa 15: Jelly-Fish 16: Unique Rectangles 17: Extended Unique Rect. 18: Hidden Unique Rect's 19: WXYZ Wing 20: Aligned Pair Exclusion **Extreme Strategies** 21: Grouped X-Cycles 22: Empty Rectangles 23: Finned X-Wing 24: Finned Sword-Fish 25: Altern. Inference Chains 26: Sue-de-Coq 27: Digit Forcing Chains 28: Nishio Forcing Chains 29: Cell Forcing Chains 30: Unit Forcing Chains 31: Almost Locked Sets 32: Death Blossom 33: Pattern Overlay Method 34: Quad Forcing Chains **"Trial and Error"** 35: Bowman's Bingo
作为一个相当频繁的玩家,我会将战略11之外的所有内容评判为“再也没有乐趣了”。但这可能是一个品味问题。
答案 1 :(得分:1)
如果你只需要一个快速的随机数独游戏,你可以使用一种特殊的方式来创建一个有效的数独模式,我使用我刚才想到的以下算法:
You initialize an array with a randomized set of the numbers 1 to 9,
technically it's easier if you initialize 3 arrays each with 3 length.
You can have these numbers be randomized, thus create a different sudoku.
[1 2 3] [4 5 6] [7 8 9]
Then you shift these:
[7 8 9] [1 2 3] [4 5 6]
[4 5 6] [7 8 9] [1 2 3]
Then you shift the numbers inside the arrays:
[3 1 2] [6 4 5] [9 7 8]
Then you shift the arrays themselves again:
[9 7 8] [3 1 2] [6 4 5]
[6 4 5] [9 7 8] [3 1 2]
Then you shift the numbers inside the arrays:
[2 3 1] [5 6 4] [8 9 7]
Then you shift the arrays again:
[8 9 7] [2 3 1] [5 6 4]
[5 6 4] [8 9 7] [2 3 1]
你将获得最终的数独表:
[1 2 3] [4 5 6] [7 8 9]
[7 8 9] [1 2 3] [4 5 6]
[4 5 6] [7 8 9] [1 2 3]
[3 1 2] [6 4 5] [9 7 8]
[9 7 8] [3 1 2] [6 4 5]
[6 4 5] [9 7 8] [3 1 2]
[2 3 1] [5 6 4] [8 9 7]
[8 9 7] [2 3 1] [5 6 4]
[5 6 4] [8 9 7] [2 3 1]
哪个有效。之后,您可以取出一些数字,并且可以使用您已经拥有的算法进行检查,无论是单个解决方案还是多个解决方案。如果删除某个数字会产生多个,则撤消它并结束删除,或尝试删除另一个。