import java.util.Set;
import java.util.TreeSet;
import java.util.Scanner;
import java.io.File;

/**
 * Class that provides the basic functionality of a Boggle game.
 *   @author Dave Reed
 *   @version 4/1/13
 */
public class BoggleGame {
    private final static String DICT_FILE = "dictionary.txt";
    private BoggleBoard board;
    private Set<String> guessedWords;
    private Set<String> unguessedWords;
    
    /** 
     * Creates a new instance of BoggleGame. 
     */
    public BoggleGame() {
        this.board = new BoggleBoard();
        this.guessedWords = new TreeSet<String>();
        this.unguessedWords = new TreeSet<String>();
        
        try {
            Scanner dictFile = new Scanner(new File(DICT_FILE));
            while (dictFile.hasNext()) {
                String nextWord = dictFile.next();
                if (this.board.findWord(nextWord)) {
                    this.unguessedWords.add(nextWord);
                }
            }
            dictFile.close();
        }
        catch (java.io.FileNotFoundException e) {
            System.out.println("DICTIONARY FILE NOT FOUND");
        }
    }
    
    /**
     * Determines whether a word is stored in the board and has not yet 
     * been guessed.
     *   @param word the word to be searched for
     *   @return true if word is on the board and has not been previously 
     *           guessed; else false
     */
    public boolean makeGuess(String word) {
        if (this.unguessedWords.contains(word)) {
            this.unguessedWords.remove(word);
            this.guessedWords.add(word);
            return true;
        }
        return false;
    }
    
    /**
     * Returns the set of words from the board that have been guessed so far.
     */
    public Set<String> getGuessedWords() {
        return this.guessedWords;
    }
    
    /**
     * Returns the set of words from the board that have not yet been guessed.
     */
    public Set<String> getUnguessedWords() {
        return this.unguessedWords;
    }

    /**
     * Returns a string representation of the boggle board.
     */
    public String getBoard() {
        return this.board.toString();
    }
}
