diff options
| author | Scott Gasch <[email protected]> | 2016-06-02 11:43:53 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2016-06-02 11:43:53 -0700 |
| commit | e3a192fd3a5b535e246deba540164e69cfdfa689 (patch) | |
| tree | 9d04abb1e09cc4424943a7f1331368545f024f6b /org/guru/boggle/Boggle.java | |
Diffstat (limited to 'org/guru/boggle/Boggle.java')
| -rw-r--r-- | org/guru/boggle/Boggle.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/org/guru/boggle/Boggle.java b/org/guru/boggle/Boggle.java new file mode 100644 index 0000000..b1dd13c --- /dev/null +++ b/org/guru/boggle/Boggle.java @@ -0,0 +1,52 @@ +package org.guru.boggle; + +import java.io.IOException; +import java.util.Set; + +public class Boggle implements Runnable { + + private final SimpleBoard board; + private final DictionaryTrie dict; + + public Boggle() throws IOException { + this.dict = new DictionaryTrie("/Users/scott/words"); + this.board = new SimpleBoard(); + } + + @Override + public void run() { + if (dict.containsWord("BUDDG")) { + System.out.println("wtf?"); + } + + for (BoardPosition p : board.allPositions()) { + System.out.println("Starting position " + p); + recurse(p, ""); + } + } + + public void recurse(BoardPosition p, String soFar) { + char letter = board.letterAt(p); + board.markUsed(p); + soFar = soFar + letter; + if (dict.containsWord(soFar)) { + System.out.println(soFar); + } + Set<Character> possibleSuccessors = dict.possibleSuccessorLetters(soFar); + for (BoardPosition q : board.adjacentUnusedNeighborPosition(p)) { + char potentialSuccessor = board.letterAt(q); + if (possibleSuccessors.contains(potentialSuccessor)) { + recurse(q, soFar); + } + } + board.clearUsed(p); + } + + public static void main(String args[]) { + try { + new Boggle().run(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} |
