我是初级程序员,我正在尝试使用我在此处找到的现有代码创建自己的数独生成器 http://ostermiller.org/qqwing/QQWing.java.html我将它放在包中的单独文件中。
我不知道该怎么做。我试图用正确的数独数字填充我的板,但它只填充零。这是我的代码:
QQWing wing = new QQWing();
try {
wing.generatePuzzle();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Create the layout
TableLayout table = new TableLayout(this);
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
table.setLayoutParams(lp); // This line has no effect! WHYYYY?!
table.setStretchAllColumns(true);
EditText editText[][] = new EditText[9][9];
for (int i = 0; i < 9; ++i)
{
TableRow row = new TableRow(this);
for (int j = 0; j < 9; ++j)
{
editText[i][j] = new EditText(this);
editText[i][j].setText(String.valueOf(wing.puzzle[i*9+j]));
editText[i][j].setWidth(50);
row.addView(editText[i][j]);
}
table.addView(row);
}
最佳答案
我是 Stephen Ostermiller,QQWing 的作者。
我很高兴地向大家报告,此问题已在 QQWing 1.3.3 版本中得到修复。 Java API 得到了相当大的改进:
Exception
不再抛出- 随机数生成器自动初始化
- 已放入
com.qqwing
包
这是使用QQWing的Test.java
:
import com.qqwing.*;
public class Test {
public static void main(String[] args){
QQWing qq = new QQWing();
qq.generatePuzzle();
System.out.println(qq.getPuzzleString());
}
}
可以这样编译运行:
$ javac -classpath qqwing-1.3.3.jar Test.java && java -classpath .:qqwing-1.3.3.jar Test
. . 5 | 8 . . | 3 4 .
. . 6 | . 7 . | . 2 1
3 . 8 | 2 . . | . . .
-------|-------|-------
. . . | 4 6 5 | . 1 .
. . . | . . . | . . .
. 7 . | 1 3 . | 6 8 .
-------|-------|-------
. . . | . . . | 1 3 .
. . 4 | . . . | 2 . .
. . . | . . . | . 5 6
latest version of QQWing can be downloaded 来自 QQWing website .
关于java - QQWing 在我的 Android 应用程序中生成只有零的数独谜题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14685035/