Ejemplo n.º 1
0
  public String wordTester(IAutoPlayer player, ILexicon lex, ArrayList<Integer> log, int count) {

    BoggleBoardFactory.setRandom(new Random(12345));
    log.clear();
    double start = System.currentTimeMillis();
    int hiScore = 0;
    BoggleBoard hiBoard = null;
    for (int k = 0; k < count; k++) {
      BoggleBoard board = BoggleBoardFactory.getBoard(5);
      player.clear();
      player.findAllValidWords(board, lex, MIN_WORD);
      log.add(player.getScore());
      if (player.getScore() > hiScore) {
        hiScore = player.getScore();
        hiBoard = board;
      }
    }

    double end = System.currentTimeMillis();
    int max = Collections.max(log);
    return String.format(
        "%s %s\t count: %d\tmax: %d\ttime: %f" + hiBoard.toString(),
        player.getClass().getName(),
        lex.getClass().getName(),
        count,
        max,
        (end - start) / 1000.0);
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    ILexicon lex = new SimpleLexicon();
    InputStream is = lex.getClass().getResourceAsStream("/ospd3.txt");
    ProgressMonitorInputStream pmis = StoppableReader.getMonitorableStream(is, "reading...");
    Scanner s = new Scanner(pmis);
    ArrayList<String> list = new ArrayList<String>();
    while (s.hasNext()) {
      list.add(s.next().toLowerCase());
    }
    BoggleStats bs = new BoggleStats();

    bs.runTests(lex, list);
    lex = new BinarySearchLexicon();
    bs.runTests(lex, list);
    lex = new TrieLexicon();
    bs.runTests(lex, list);
    //        TrieLexicon trieLex = new TrieLexicon();
    //        System.out.println(trieLex.nodeCount());
    //        System.out.println(trieLex.oneWayCount());
    //        CompressedTrieLexicon comTrieLex = new CompressedTrieLexicon();
    //        System.out.println(comTrieLex.nodeCount());
    //        System.out.println(comTrieLex.oneWayCount());
  }
Ejemplo n.º 3
0
  /**
   * Read word list from file with name WORDLISTFILENAME, and pass a Set containing those words to
   * the computer player to intialize its lexicon.
   */
  private void initLexicon(InputStream stream) {

    ProgressMonitorInputStream pmis;
    ProgressMonitor progress = null;
    pmis = new ProgressMonitorInputStream(this, "reading words", stream);
    progress = pmis.getProgressMonitor();
    progress.setMillisToDecideToPopup(10);
    Scanner s = new Scanner(pmis);
    myLexicon.load(s);
    try {
      pmis.close();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null, "Error Closing Stream", "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
Ejemplo n.º 4
0
 public void runTests(ILexicon lex, ArrayList<String> list) {
   lex.load(list);
   doTests(lex);
 }