/* PublicHw7Test.java */ /** Provides a simple way to initialize a hash table with random * SimpleBoards. For use when testing homework 7 * @author Daniel C. Silverstein */ import java.io.*; import java.math.*; public class PublicHw7Test { /** * Empties the given table, then inserts the given number of boards * into the table. * @param table is the hashtable to be initialized * @param numboards is the number of random boards to place in the table */ public static void initTable(HashTableChained table, int numboards) { table.makeEmpty(); for (int i = 0; i < numboards; i++) table.insert(randomBoard()); } /** * Generates a (reasonably) random 8 x 8 SimpleBoard */ private static SimpleBoard randomBoard() { SimpleBoard board = new SimpleBoard(); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { double fval = (Math.random() * 10); int value = (int) fval; board.setElementAt(x, y, value); } } return board; } }