diff --git a/.gitignore b/.gitignore index 4462af2dc..f1da99214 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /.gradle/ /build/ /out/ +/.metadata/ +/.settings/ diff --git a/build.gradle b/build.gradle index 9fbd4947f..62eb0a3f7 100644 --- a/build.gradle +++ b/build.gradle @@ -163,6 +163,16 @@ task tiltyardRequestFarm(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath } +task batchValidator(type: JavaExec) { + main = 'org.ggp.base.apps.validator.BatchValidator' + classpath = sourceSets.main.runtimeClasspath +} + +task validator(type: JavaExec) { + main = 'org.ggp.base.apps.validator.Validator' + classpath = sourceSets.main.runtimeClasspath +} + task player(type: JavaExec) { main = 'org.ggp.base.apps.player.Player' classpath = sourceSets.main.runtimeClasspath diff --git a/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java b/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java index 07bc7db3a..ee43a922d 100644 --- a/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java +++ b/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java @@ -11,20 +11,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.JTextField; -import javax.swing.ListSelectionModel; +import javax.swing.JTextPane; import javax.swing.border.TitledBorder; import org.ggp.base.player.GamePlayer; @@ -34,9 +30,7 @@ import org.ggp.base.server.event.ServerConnectionErrorEvent; import org.ggp.base.server.event.ServerIllegalMoveEvent; import org.ggp.base.server.event.ServerTimeoutEvent; -import org.ggp.base.util.game.CloudGameRepository; import org.ggp.base.util.game.Game; -import org.ggp.base.util.game.GameRepository; import org.ggp.base.util.gdl.grammar.GdlPool; import org.ggp.base.util.logging.GamerLogger; import org.ggp.base.util.match.Match; @@ -44,6 +38,8 @@ import org.ggp.base.util.observer.Observer; import org.ggp.base.util.reflection.ProjectSearcher; import org.ggp.base.util.symbol.grammar.SymbolPool; +import org.ggp.base.util.ui.GameSelector; +import org.ggp.base.util.ui.GameSelector.NamedItem; import org.ggp.base.util.ui.NativeUI; import org.ggp.base.util.ui.PublishButton; @@ -87,9 +83,13 @@ public void run() { private final JTextField playClockTextField; private final JTextField startClockTextField; + private final JTextPane gameDescription; private final JButton runButton; - private final JList selectedGame; + private final java.util.Map name2availableGame; + private final java.util.Map canvasNameToGameKey; + private final GameSelector gameSelector; + private final JCheckBox flipRoles; private final PublishButton publishButton; @@ -100,8 +100,6 @@ public void run() { private List> gamers = null; private final JTextField computerAddress; - private final GameRepository theRepository; - public Kiosk() { super(new GridBagLayout()); @@ -110,23 +108,25 @@ public Kiosk() NativeUI.setNativeUI(); GamerLogger.setFileToDisplay("GamePlayer"); - SortedSet theAvailableGames = new TreeSet(); + name2availableGame = new java.util.HashMap(); + canvasNameToGameKey = new java.util.HashMap(); + + flipRoles = new JCheckBox("Flip roles?"); Set> theAvailableCanvasList = ProjectSearcher.GAME_CANVASES.getConcreteClasses(); for(Class availableCanvas : theAvailableCanvasList) { try { GameCanvas theCanvas = availableCanvas.newInstance(); - theAvailableGames.add(new AvailableGame(theCanvas.getGameName(), theCanvas.getGameKey(), availableCanvas)); + String gameKey = theCanvas.getGameKey(); + String canvasName = theCanvas.getGameName(); + AvailableGame availableGame = new AvailableGame(canvasName, gameKey, availableCanvas); + name2availableGame.put(canvasName, availableGame); + canvasNameToGameKey.put(canvasName, gameKey); } catch(Exception e) { ; } } - flipRoles = new JCheckBox("Flip roles?"); - - selectedGame = new JList(theAvailableGames.toArray(new AvailableGame[0])); - selectedGame.setSelectedIndex(0); - selectedGame.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - JScrollPane selectedGamePane = new JScrollPane(selectedGame); + gameSelector = new GameSelector(canvasNameToGameKey); computerAddress = new JTextField("player.ggp.org:80"); playerComboBox = new JComboBox(); @@ -156,6 +156,11 @@ public Kiosk() startClockTextField = new JTextField("30"); playClockTextField = new JTextField("10"); + + gameDescription = new JTextPane(); + gameDescription.setPreferredSize(new Dimension(0, 0)); + gameSelector.getGameList().addItemListener(this); + managerPanel = new JPanel(new GridBagLayout()); startClockTextField.setColumns(15); @@ -171,8 +176,12 @@ public Kiosk() managerPanel.add(new JLabel("Play Clock:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); managerPanel.add(playClockTextField, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); managerPanel.add(flipRoles, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); + managerPanel.add(new JLabel("Repository:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); + managerPanel.add(gameSelector.getRepositoryList(), new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); managerPanel.add(new JLabel("Game:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); - managerPanel.add(selectedGamePane, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 5.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 5, 5)); + managerPanel.add(gameSelector.getGameList(), new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); + managerPanel.add(new JLabel("Description:"), new GridBagConstraints(0, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); + managerPanel.add(gameDescription, new GridBagConstraints(0, nRowCount++, 2, 1, 1.0, 5.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 5, 5)); managerPanel.add(new JLabel("Publishing:"), new GridBagConstraints(0, nRowCount, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); managerPanel.add(publishButton, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 5, 5)); //managerPanel.add(new ConsolePanel(), new GridBagConstraints(0, nRowCount++, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 5, 5)); @@ -195,11 +204,6 @@ public Kiosk() } catch(Exception e) { e.printStackTrace(); } - - // This is where we get the rulesheets from. Each game has a corresponding - // game (with rulesheet) stored on this repository server. Changing this is - // likely to break things unless you know what you're doing. - theRepository = new CloudGameRepository("http://games.ggp.org/base/"); } class AvailableGame implements Comparable { @@ -301,8 +305,8 @@ public void actionPerformed(ActionEvent e) { GdlPool.drainPool(); SymbolPool.drainPool(); - AvailableGame theGame = selectedGame.getSelectedValue(); - Game game = theRepository.getGame(theGame.kifFile); + AvailableGame theGame = name2availableGame.get(((NamedItem)gameSelector.getGameList().getSelectedItem()).theName); + Game game = gameSelector.getSelectedGameRepository().getGame(theGame.kifFile); if (game == null) { JOptionPane.showMessageDialog(this, "Cannot load game data for " + theGame.kifFile, "Error", JOptionPane.ERROR_MESSAGE); @@ -398,6 +402,12 @@ public void itemStateChanged(ItemEvent e) { } validate(); } + if(e.getSource() == gameSelector.getGameList()) { + Game selectedGame = gameSelector.getSelectedGame(); + if ( selectedGame != null) { + gameDescription.setText(selectedGame.getDescription()); + } + } } @Override @@ -413,4 +423,4 @@ public void observe(Event event) { System.err.println("Connection error when communicating with role [" + x.getRole() + "]."); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/ggp/base/util/ui/GameSelector.java b/src/main/java/org/ggp/base/util/ui/GameSelector.java index dae1a97b8..349113e9b 100644 --- a/src/main/java/org/ggp/base/util/ui/GameSelector.java +++ b/src/main/java/org/ggp/base/util/ui/GameSelector.java @@ -32,7 +32,9 @@ public class GameSelector implements ActionListener { GameRepository theSelectedRepository; Map theCachedRepositories; - class NamedItem { + java.util.Map restrictionNameToKey = null; + + public static class NamedItem { public final String theKey; public final String theName; @@ -47,7 +49,7 @@ public String toString() { } } - public GameSelector() { + void init() { theGameList = new JComboBox(); theGameList.addActionListener(this); @@ -60,6 +62,14 @@ public GameSelector() { theRepositoryList.addItem("games.ggp.org/stanford"); theRepositoryList.addItem("Local Game Repository"); } + public GameSelector() { + init(); + } + + public GameSelector(java.util.Map restrictionNameToKey) { + this.restrictionNameToKey = restrictionNameToKey; + init(); + } @Override public void actionPerformed(ActionEvent e) { @@ -85,10 +95,14 @@ public GameRepository getSelectedGameRepository() { public void repopulateGameList() { GameRepository theRepository = getSelectedGameRepository(); - List theKeyList = new ArrayList(theRepository.getGameKeys()); + List theKeyList; + theKeyList = new ArrayList(theRepository.getGameKeys()); Collections.sort(theKeyList); theGameList.removeAllItems(); for (String theKey : theKeyList) { + if ( restrictionNameToKey != null && ! restrictionNameToKey.containsValue(theKey)) { + continue; + } Game theGame = theRepository.getGame(theKey); if (theGame == null) { continue; @@ -99,7 +113,20 @@ public void repopulateGameList() { } if (theName.length() > 24) theName = theName.substring(0, 24) + "..."; - theGameList.addItem(new NamedItem(theKey, theName)); + + if ( restrictionNameToKey == null) { + theGameList.addItem(new NamedItem(theKey, theName)); + } + else { + for (String name: restrictionNameToKey.keySet()) { + String key = restrictionNameToKey.get(name); + //System.out.println("theKey: "+theKey+", theName: "+theName+", name:"+name + ", key: " + key); + if ( theKey.equals(key)) { + //System.out.println("key: " + key + ", name" + name); + theGameList.addItem(new NamedItem(theKey, name)); + } + } + } } }