From e8b7c50b366b92e33088f44fcd0e236c199175a1 Mon Sep 17 00:00:00 2001 From: bo198214 Date: Fri, 29 Jan 2021 09:54:12 +0100 Subject: [PATCH 1/5] save workstate --- .../java/org/ggp/base/apps/kiosk/Kiosk.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) 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..0414229c7 100644 --- a/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java +++ b/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java @@ -35,6 +35,7 @@ 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.LocalGameRepository; import org.ggp.base.util.game.Game; import org.ggp.base.util.game.GameRepository; import org.ggp.base.util.gdl.grammar.GdlPool; @@ -46,6 +47,7 @@ import org.ggp.base.util.symbol.grammar.SymbolPool; import org.ggp.base.util.ui.NativeUI; import org.ggp.base.util.ui.PublishButton; +import org.ggp.base.util.ui.GameSelector; import com.google.common.collect.Lists; @@ -110,12 +112,24 @@ public Kiosk() NativeUI.setNativeUI(); GamerLogger.setFileToDisplay("GamePlayer"); + GameSelector gameSelector = new GameSelector(); + JComboBox repositoryList = gameSelector.getRepositoryList(); + // 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/"); + theRepository = new LocalGameRepository(); + Set gameKeys = theRepository.getGameKeys(); + SortedSet theAvailableGames = new TreeSet(); 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(); + if (gameKeys.contains(gameKey)) { + theAvailableGames.add(new AvailableGame(theCanvas.getGameName(), theCanvas.getGameKey(), availableCanvas)); + } } catch(Exception e) { ; } @@ -171,6 +185,8 @@ 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("Game 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(repositoryList, 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(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)); @@ -195,11 +211,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 { @@ -413,4 +424,4 @@ public void observe(Event event) { System.err.println("Connection error when communicating with role [" + x.getRole() + "]."); } } -} \ No newline at end of file +} From e5ffa7f79f803aafaf5059a6ca26124966e10c9f Mon Sep 17 00:00:00 2001 From: bo198214 Date: Sat, 30 Jan 2021 00:09:20 +0100 Subject: [PATCH 2/5] Now all the Canvases are shown that have a corresponding gameKey on the Repository --- .../java/org/ggp/base/apps/kiosk/Kiosk.java | 52 +++++++------------ .../org/ggp/base/util/ui/GameSelector.java | 35 +++++++++++-- 2 files changed, 49 insertions(+), 38 deletions(-) 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 0414229c7..1df482cc7 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,15 @@ 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.border.TitledBorder; import org.ggp.base.player.GamePlayer; @@ -34,10 +29,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.LocalGameRepository; 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; @@ -45,9 +37,10 @@ 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; -import org.ggp.base.util.ui.GameSelector; import com.google.common.collect.Lists; @@ -91,7 +84,10 @@ public void run() { private final JTextField startClockTextField; 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; @@ -102,8 +98,6 @@ public void run() { private List> gamers = null; private final JTextField computerAddress; - private final GameRepository theRepository; - public Kiosk() { super(new GridBagLayout()); @@ -112,35 +106,25 @@ public Kiosk() NativeUI.setNativeUI(); GamerLogger.setFileToDisplay("GamePlayer"); - GameSelector gameSelector = new GameSelector(); - JComboBox repositoryList = gameSelector.getRepositoryList(); - // 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/"); - theRepository = new LocalGameRepository(); - Set gameKeys = theRepository.getGameKeys(); + name2availableGame = new java.util.HashMap(); + canvasNameToGameKey = new java.util.HashMap(); - SortedSet theAvailableGames = new TreeSet(); + flipRoles = new JCheckBox("Flip roles?"); Set> theAvailableCanvasList = ProjectSearcher.GAME_CANVASES.getConcreteClasses(); for(Class availableCanvas : theAvailableCanvasList) { try { GameCanvas theCanvas = availableCanvas.newInstance(); String gameKey = theCanvas.getGameKey(); - if (gameKeys.contains(gameKey)) { - theAvailableGames.add(new AvailableGame(theCanvas.getGameName(), theCanvas.getGameKey(), availableCanvas)); - } + 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(); @@ -186,9 +170,9 @@ public Kiosk() 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("Game 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(repositoryList, new GridBagConstraints(1, nRowCount++, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, 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("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)); @@ -312,8 +296,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); 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)); + } + } + } } } From 4cc9c7dfc286e0b3e97641283e7cf7b01f8e988f Mon Sep 17 00:00:00 2001 From: bo198214 Date: Sat, 30 Jan 2021 00:14:38 +0100 Subject: [PATCH 3/5] Validator is now also in gradle --- build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From 052bf3e85aff77a56f5cfa8a70835bf9cc038aae Mon Sep 17 00:00:00 2001 From: bo198214 Date: Sat, 30 Jan 2021 00:28:31 +0100 Subject: [PATCH 4/5] git ignores now .settings und .metadata from eclipse IDE --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4462af2dc..f1da99214 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /.gradle/ /build/ /out/ +/.metadata/ +/.settings/ From 3206cf4a4cea130652216b98c97f91dad56b24fe Mon Sep 17 00:00:00 2001 From: bo198214 Date: Sat, 30 Jan 2021 14:06:52 +0100 Subject: [PATCH 5/5] Added TextPane for game description. --- .../java/org/ggp/base/apps/kiosk/Kiosk.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 1df482cc7..ee43a922d 100644 --- a/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java +++ b/src/main/java/org/ggp/base/apps/kiosk/Kiosk.java @@ -20,6 +20,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.JTextPane; import javax.swing.border.TitledBorder; import org.ggp.base.player.GamePlayer; @@ -82,6 +83,7 @@ public void run() { private final JTextField playClockTextField; private final JTextField startClockTextField; + private final JTextPane gameDescription; private final JButton runButton; private final java.util.Map name2availableGame; @@ -154,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); @@ -169,10 +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("Game 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(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(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)); @@ -393,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