package cmsc433.p3;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
/**
* The Test class is for testing the grid solver.
* It will take as arguments a grid, a dictionary, and time
* limit, and compute a solution to that grid that is compatible
* with the given dictionary, within the given time limit.
*/
public class Test {
private static final String GRIDNAME = "public_grid_1.txt";
private static final String DICTNAME = "dict_animals.txt";
private JLabel[][] leftLabels;
private JLabel[][] rightLabels;
private JSlider timeSlider;
private JLabel leftRuntimeLabel;
private JLabel leftScoreLabel;
private JCheckBox checkBox;
private JLabel rightRuntimeLabel;
private JLabel rightScoreLabel;
public static void main(String[] args)
{
Dictionary dict;
Grid board;
if (args.length > 0) {
dict = Dictionary.makeDict(args[0]);
} else {
dict = Dictionary.makeDict(DICTNAME);
}
if (args.length > 1) {
board = Grid.makeGrid(args[1]);
} else {
board = Grid.makeGrid(GRIDNAME);
}
new Test(dict, board);
}
public Test(Dictionary dict, Grid board)
{
displayGui(dict,board);
}
public void displayGui(Dictionary dict, Grid board)
{
int numRows = board.numRows();
int numCols = board.numCols();
JFrame frame = new JFrame("Grid");
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel gridPanel = new JPanel(new GridLayout(1,2));
JPanel leftGridPanel = new JPanel(new GridLayout(numRows,numCols));
JPanel rightGridPanel = new JPanel(new GridLayout(numRows,numCols));
JPanel buttonPanel = new JPanel(new GridLayout(2,1));
JPanel runPanel = new JPanel(new GridLayout(1,6));
leftLabels = new JLabel[numRows][numCols];
rightLabels = new JLabel[numRows][numCols];
for(int y=0;y paths = sol.getPaths();
for(int i=0;i points = paths.get(i).getPoints();
for(int j=0;j points = paths.get(i).getPoints();
for(int j=0;j paths = sol.getPaths();
leftRuntimeLabel.setText(Long.toString(stopTime-startTime));
leftScoreLabel.setText(Integer.toString(board.score(dict, paths)));
startTime = System.currentTimeMillis();
Solution solST = null;
if(checkBox.isSelected())
{
solST = STGridSolver.solve(board, dict, timeSlider.getValue());
List pathsST = solST.getPaths();
stopTime = System.currentTimeMillis();
rightRuntimeLabel.setText(Long.toString(stopTime-startTime));
rightScoreLabel.setText(Integer.toString(board.score(dict, pathsST)));
}
displayBoard(dict, board, sol, solST);
}
}
public static Color intToColor(int id)
{
switch(id%9)
{
case 0: return Color.red;
case 1: return Color.orange;
case 2: return Color.yellow;
case 3: return Color.green;
case 4: return Color.cyan;
case 5: return Color.blue;
case 6: return Color.magenta;
case 7: return Color.pink;
case 8: return Color.lightGray;
default: return Color.darkGray;
}
}
}