Ejemplo n.º 1
0
  public int scoreOf(String word) {
    if (!dict.contains(word)) {
      return 0;
    }

    int length = word.length();

    if (length >= 0 && length <= 2) {
      return 0;
    }
    if (length >= 3 && length <= 4) {
      return 1;
    }
    if (length == 5) {
      return 2;
    }
    if (length == 6) {
      return 3;
    }
    if (length == 7) {
      return 5;
    }

    return 11;
  }
Ejemplo n.º 2
0
  private void dfs(int i, int j) {
    marked[i][j] = true;
    if (wordTo[i][j].length() > 2 && dict.contains(wordTo[i][j])) {
      wordsFromCell.add(wordTo[i][j]);
    }

    if (dict.keysWithPrefix(wordTo[i][j]).iterator().hasNext()) {
      Iterable<int[]> adj = adj(i, j);
      for (int[] a : adj) {
        if (!marked[a[0]][a[1]]) {
          String letter = board.getLetter(a[0], a[1]) + "";
          if (Objects.equals(letter, "Q")) {
            wordTo[a[0]][a[1]] = wordTo[i][j] + "QU";
          } else {
            wordTo[a[0]][a[1]] = wordTo[i][j] + letter;
          }
          dfs(a[0], a[1]);
        }
      }
    }
    marked[i][j] = false;
  }
Ejemplo n.º 3
0
 public BoggleSolver(String[] dictionary) {
   for (String word : dictionary) {
     dict.put(word, true);
   }
 }