- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在用java编写一个Boggle程序,但我很难让它找到每个可能的单词。
它几乎找到了所有这些,但我一生都无法弄清楚为什么它不能找到所有这些。
private void findWords( TreeSet<String> foundWords, String word, Tile t ){
int i=t.getRow();
int j=t.getCol();
//Make sure the tile isn't visited
if(visited[i][j]) return;
//Set the current tile to visited
visited[i][j]=true;
//Decide what the current word is
if(t.getLetter().equalsIgnoreCase("q")) word=word+"qu";
else word=word+t.getLetter();
//If the string is a word
if(Boggle.dictionary.search(word)==1){
//If the word length is greater than or equal to the prefix length
if(word.length()>=Dictionary.prefixLength){
//If the word has not already been found
if(!foundWords.contains(word)){
//Add the word to the found list
foundWords.add(word);
}
}
}
//Recurse through all neighbor tiles
for(int curRow=0; curRow<=nRows; curRow++){
for(int curCol=0; curCol<=nCols; curCol++){
//Make sure it is not out of bounds
if((i+curRow<nRows)&&(j+curCol<nCols)){
findWords(foundWords, word, board[i + curRow][j + curCol]);
findWords(foundWords, word, board[i - curRow][j - curCol]);
findWords(foundWords, word, board[i + curRow][curCol]);
findWords(foundWords, word, board[i - curRow][curCol]);
findWords(foundWords, word, board[curRow][j + curCol]);
findWords(foundWords, word, board[curRow][j - curCol]);
findWords(foundWords, word, board[i + curRow][j - curCol]);
findWords(foundWords, word, board[i - curRow][j + curCol]);
}
}
}
//Reset the tile to be not visited
visited[i][j] = false;
}
这是有问题的方法;它会递归地在 Boggle 板上查找单词。
有人知道为什么它只找到大约 75% 的单词吗?
如果需要,我可以附加更多代码。
最佳答案
我建议编写一些测试用例 - 我总是发现这样做可以立即找到问题,或者至少允许您使用调试器单步执行代码,并找到现实与您的期望不同的地方。
编辑:另外,你的两个 for 循环看起来很奇怪。您不应该查看每个方向上 -1,0 和 1 的偏移量(并折扣 0,0),而不是 0 -> nRows 吗?看来您只朝一个方向看。
关于java - 我的 Boggle 程序找不到所有有效单词 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12921953/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!