contents = getContents();
50 | if(contents == null)
51 | return "(MachineState with null contents)";
52 | else
53 | return contents.toString();
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o)
58 | {
59 | if ((o != null) && (o instanceof MachineState))
60 | {
61 | MachineState state = (MachineState) o;
62 | return state.getContents().equals(getContents());
63 | }
64 |
65 | return false;
66 | }
67 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/statemachine/Move.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.statemachine;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.ggp.base.util.gdl.factory.GdlFactory;
6 | import org.ggp.base.util.gdl.grammar.GdlTerm;
7 | import org.ggp.base.util.symbol.factory.exceptions.SymbolFormatException;
8 |
9 | /**
10 | * A Move represents a possible move that can be made by a role. Each
11 | * player makes exactly one move on every turn. This includes moves
12 | * that represent passing, or taking no action.
13 | *
14 | * Note that Move objects are not intrinsically tied to a role. They
15 | * only express the action itself.
16 | */
17 | @SuppressWarnings("serial")
18 | public class Move implements Serializable
19 | {
20 | protected final GdlTerm contents;
21 |
22 | public Move(GdlTerm contents)
23 | {
24 | this.contents = contents;
25 | }
26 |
27 | public static Move create(String contents) {
28 | try {
29 | return new Move(GdlFactory.createTerm(contents));
30 | } catch (SymbolFormatException e) {
31 | throw new IllegalArgumentException("Could not parse as move: " + contents, e);
32 | }
33 | }
34 |
35 | @Override
36 | public boolean equals(Object o)
37 | {
38 | if ((o != null) && (o instanceof Move)) {
39 | Move move = (Move) o;
40 | return move.contents.equals(contents);
41 | }
42 |
43 | return false;
44 | }
45 |
46 | public GdlTerm getContents()
47 | {
48 | return contents;
49 | }
50 |
51 | @Override
52 | public int hashCode()
53 | {
54 | return contents.hashCode();
55 | }
56 |
57 | @Override
58 | public String toString()
59 | {
60 | return contents.toString();
61 | }
62 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/statemachine/exceptions/GoalDefinitionException.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.statemachine.exceptions;
2 |
3 | import org.ggp.base.util.statemachine.MachineState;
4 | import org.ggp.base.util.statemachine.Role;
5 |
6 | @SuppressWarnings("serial")
7 | public final class GoalDefinitionException extends Exception
8 | {
9 |
10 | private final Role role;
11 | private final MachineState state;
12 |
13 | public GoalDefinitionException(MachineState state, Role role)
14 | {
15 | this.state = state;
16 | this.role = role;
17 | }
18 |
19 | public Role getRole()
20 | {
21 | return role;
22 | }
23 |
24 | public MachineState getState()
25 | {
26 | return state;
27 | }
28 |
29 | @Override
30 | public String toString()
31 | {
32 | return "Goal is poorly defined for " + role + " in " + state;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/statemachine/exceptions/MoveDefinitionException.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.statemachine.exceptions;
2 |
3 | import org.ggp.base.util.statemachine.MachineState;
4 | import org.ggp.base.util.statemachine.Role;
5 |
6 | @SuppressWarnings("serial")
7 | public final class MoveDefinitionException extends Exception
8 | {
9 |
10 | private final Role role;
11 | private final MachineState state;
12 |
13 | public MoveDefinitionException(MachineState state, Role role)
14 | {
15 | this.state = state;
16 | this.role = role;
17 | }
18 |
19 | public Role getRole()
20 | {
21 | return role;
22 | }
23 |
24 | public MachineState getState()
25 | {
26 | return state;
27 | }
28 |
29 | @Override
30 | public String toString()
31 | {
32 | return "There are no legal moves defined for " + role + " in " + state;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/statemachine/exceptions/TransitionDefinitionException.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.statemachine.exceptions;
2 |
3 | import java.util.List;
4 |
5 | import org.ggp.base.util.statemachine.MachineState;
6 | import org.ggp.base.util.statemachine.Move;
7 |
8 |
9 | @SuppressWarnings("serial")
10 | public final class TransitionDefinitionException extends Exception
11 | {
12 |
13 | private final List moves;
14 | private final MachineState state;
15 |
16 | public TransitionDefinitionException(MachineState state, List moves)
17 | {
18 | this.state = state;
19 | this.moves = moves;
20 | }
21 |
22 | public List getMoves()
23 | {
24 | return moves;
25 | }
26 |
27 | public MachineState getState()
28 | {
29 | return state;
30 | }
31 |
32 | @Override
33 | public String toString()
34 | {
35 | return "Transition is poorly defined for " + moves + " in " + state;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/statemachine/implementation/prover/result/ProverResultParser.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.statemachine.implementation.prover.result;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import org.ggp.base.util.gdl.grammar.GdlConstant;
9 | import org.ggp.base.util.gdl.grammar.GdlPool;
10 | import org.ggp.base.util.gdl.grammar.GdlSentence;
11 | import org.ggp.base.util.gdl.grammar.GdlTerm;
12 | import org.ggp.base.util.statemachine.MachineState;
13 | import org.ggp.base.util.statemachine.Move;
14 | import org.ggp.base.util.statemachine.Role;
15 |
16 |
17 | public final class ProverResultParser {
18 |
19 | public List toMoves(Set results)
20 | {
21 | List moves = new ArrayList();
22 | for (GdlSentence result : results)
23 | {
24 | moves.add(new Move(result.get(1)));
25 | }
26 |
27 | return moves;
28 | }
29 |
30 | public List toRoles(List results)
31 | {
32 | List roles = new ArrayList();
33 | for (GdlSentence result : results)
34 | {
35 | GdlConstant name = (GdlConstant) result.get(0);
36 | roles.add(new Role(name));
37 | }
38 |
39 | return roles;
40 | }
41 |
42 | public MachineState toState(Set results)
43 | {
44 | Set trues = new HashSet();
45 | for (GdlSentence result : results)
46 | {
47 | trues.add(GdlPool.getRelation(GdlPool.TRUE, new GdlTerm[] { result.get(0) }));
48 | }
49 | return new MachineState(trues);
50 | }
51 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/symbol/factory/exceptions/SymbolFormatException.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.symbol.factory.exceptions;
2 |
3 | @SuppressWarnings("serial")
4 | public final class SymbolFormatException extends Exception
5 | {
6 |
7 | private final String source;
8 |
9 | public SymbolFormatException(String source)
10 | {
11 | this.source = source;
12 | }
13 |
14 | public String getSource()
15 | {
16 | return source;
17 | }
18 |
19 | @Override
20 | public String toString()
21 | {
22 | return "Improperly formatted symbolic expression: " + source;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/symbol/grammar/Symbol.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.symbol.grammar;
2 |
3 | public abstract class Symbol
4 | {
5 |
6 | @Override
7 | public abstract String toString();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/symbol/grammar/SymbolAtom.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.symbol.grammar;
2 |
3 | public final class SymbolAtom extends Symbol
4 | {
5 |
6 | private final String value;
7 |
8 | SymbolAtom(String value)
9 | {
10 | this.value = value.intern();
11 | }
12 |
13 | public String getValue()
14 | {
15 | return value;
16 | }
17 |
18 | @Override
19 | public String toString()
20 | {
21 | return value;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/symbol/grammar/SymbolList.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.symbol.grammar;
2 |
3 | import java.util.List;
4 |
5 | public final class SymbolList extends Symbol
6 | {
7 |
8 | private final List contents;
9 |
10 | SymbolList(List contents)
11 | {
12 | this.contents = contents;
13 | }
14 |
15 | public Symbol get(int index)
16 | {
17 | return contents.get(index);
18 | }
19 |
20 | public int size()
21 | {
22 | return contents.size();
23 | }
24 |
25 | @Override
26 | public String toString()
27 | {
28 | StringBuilder sb = new StringBuilder();
29 |
30 | sb.append("( ");
31 | for (Symbol symbol : contents)
32 | {
33 | sb.append(symbol.toString() + " ");
34 | }
35 | sb.append(")");
36 |
37 | return sb.toString();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/ui/CloseableTabs.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.ui;
2 |
3 | import java.awt.Color;
4 | import java.awt.Graphics;
5 | import java.awt.GridBagConstraints;
6 | import java.awt.GridBagLayout;
7 | import java.awt.Insets;
8 | import java.awt.image.BufferedImage;
9 |
10 | import javax.swing.AbstractAction;
11 | import javax.swing.ImageIcon;
12 | import javax.swing.JButton;
13 | import javax.swing.JComponent;
14 | import javax.swing.JLabel;
15 | import javax.swing.JPanel;
16 | import javax.swing.JTabbedPane;
17 |
18 | public class CloseableTabs {
19 | private static final int CLOSE_ICON_SIZE = 8;
20 |
21 | public static void addClosableTab(JTabbedPane tabPane, JComponent tabContent, String tabName, AbstractAction closeAction) {
22 | JPanel tabTopPanel = new JPanel(new GridBagLayout());
23 | tabTopPanel.setOpaque(false);
24 |
25 | JButton btnClose = new JButton();
26 | BufferedImage img = new BufferedImage(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
27 | Graphics g = img.getGraphics();
28 | g.setColor(Color.BLACK);
29 | g.drawLine(0, CLOSE_ICON_SIZE-1, CLOSE_ICON_SIZE-1, 0);
30 | g.drawLine(0, 0, CLOSE_ICON_SIZE-1, CLOSE_ICON_SIZE-1);
31 | btnClose.setIcon(new ImageIcon(img));
32 | btnClose.addActionListener(closeAction);
33 |
34 | tabTopPanel.add(new JLabel(tabName), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
35 | tabTopPanel.add(btnClose, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 4, 0, 0), 0, 0));
36 |
37 | tabPane.addTab(tabName, tabContent);
38 | tabPane.setTabComponentAt(tabPane.getTabCount()-1, tabTopPanel);
39 | }
40 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/ui/JLabelBold.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.ui;
2 |
3 | import java.awt.Font;
4 |
5 | import javax.swing.JLabel;
6 |
7 | public class JLabelBold extends JLabel {
8 | private static final long serialVersionUID = 1L;
9 | public JLabelBold(String text) {
10 | super(text);
11 | setFont(new Font(getFont().getFamily(), Font.BOLD, getFont().getSize()+2));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/ui/JLabelHyperlink.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.ui;
2 |
3 | import java.awt.Cursor;
4 | import java.awt.event.MouseEvent;
5 | import java.awt.event.MouseListener;
6 | import java.io.IOException;
7 |
8 | import javax.swing.JLabel;
9 |
10 | public class JLabelHyperlink extends JLabel implements MouseListener {
11 | private static final long serialVersionUID = 1L;
12 | private final String url;
13 | public JLabelHyperlink(String text, String url) {
14 | super(text);
15 | this.url = url;
16 | addMouseListener(this);
17 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
18 | }
19 | @Override
20 | public void mouseClicked(MouseEvent arg0) {
21 | try {
22 | java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
23 | } catch (IOException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 | @Override
28 | public void mouseEntered(MouseEvent arg0) {
29 | ;
30 | }
31 | @Override
32 | public void mouseExited(MouseEvent arg0) {
33 | ;
34 | }
35 | @Override
36 | public void mousePressed(MouseEvent arg0) {
37 | ;
38 | }
39 | @Override
40 | public void mouseReleased(MouseEvent arg0) {
41 | ;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/util/ui/NativeUI.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.ui;
2 |
3 | import javax.swing.UIManager;
4 |
5 | /**
6 | * NativeUI is a simple user-interface wrapper around the snippet of code
7 | * that configures the Java UI to adopt the look-and-feel of the operating
8 | * system that it's running on. This is wrapped into its own separate class
9 | * because it's used in a number of different places (all of the graphical
10 | * applications) and it's useful to edit it centrally.
11 | *
12 | * @author Sam Schreiber
13 | */
14 | public class NativeUI {
15 | public static void setNativeUI() {
16 | try {
17 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
18 | } catch (Exception e) {
19 | System.err.println("Unable to set native look and feel.");
20 | // e.printStackTrace();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/validator/GameValidator.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.validator;
2 |
3 | import java.util.List;
4 |
5 | import org.ggp.base.util.game.Game;
6 |
7 | public interface GameValidator {
8 | public List checkValidity(Game theGame) throws ValidatorException;
9 | }
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/validator/OPNFValidator.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.validator;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.PrintStream;
5 | import java.util.List;
6 |
7 | import org.ggp.base.util.game.Game;
8 | import org.ggp.base.util.propnet.factory.OptimizingPropNetFactory;
9 |
10 | import com.google.common.collect.ImmutableList;
11 |
12 | public final class OPNFValidator implements GameValidator
13 | {
14 | @Override
15 | public List checkValidity(Game theGame) throws ValidatorException {
16 | PrintStream stdout = System.out;
17 | System.setOut(new PrintStream(new ByteArrayOutputStream()));
18 | try {
19 | if (OptimizingPropNetFactory.create(theGame.getRules()) == null) {
20 | throw new ValidatorException("Got null result from OPNF");
21 | }
22 | } catch (Exception e) {
23 | throw new ValidatorException("OPNF Exception: " + e, e);
24 | } finally {
25 | System.setOut(stdout);
26 | }
27 | return ImmutableList.of();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/validator/ValidatorException.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.validator;
2 |
3 | @SuppressWarnings("serial")
4 | public class ValidatorException extends Exception {
5 | public ValidatorException(String explanation) {
6 | super("Validator: " + explanation);
7 | }
8 |
9 | public ValidatorException(String explanation, Throwable t) {
10 | super("Validator: " + explanation, t);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/ggp/base/validator/ValidatorWarning.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.validator;
2 |
3 | public class ValidatorWarning {
4 | private final String warningMessage;
5 |
6 | public ValidatorWarning(String warningMessage) {
7 | this.warningMessage = warningMessage;
8 | }
9 |
10 | @Override
11 | public String toString() {
12 | return warningMessage;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/resources/external/JythonConsole/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/src/main/resources/external/JythonConsole/__init__.py
--------------------------------------------------------------------------------
/src/main/resources/external/JythonConsole/tip.py:
--------------------------------------------------------------------------------
1 | from java.awt import Color, Dimension
2 | from javax.swing import JWindow, JTextArea, JScrollPane
3 |
4 | __author__ = "Don Coleman "
5 | __cvsid__ = "$Id: tip.py,v 1.3 2003/05/01 03:43:53 dcoleman Exp $"
6 |
7 | class Tip(JWindow):
8 | """
9 | Window which provides the user with information about the method.
10 | For Python, this shows arguments, and the documention
11 | For Java, this shows the signature(s) and return type
12 | """
13 | MAX_HEIGHT = 300
14 | MAX_WIDTH = 400
15 |
16 | def __init__(self, frame):
17 | JWindow.__init__(self, frame)
18 | self.textarea = JTextArea()
19 | # TODO put this color with all the other colors
20 | self.textarea.setBackground(Color(225,255,255))
21 | self.textarea.setEditable(0)
22 | self.jscrollpane = JScrollPane(self.textarea)
23 | self.getContentPane().add(self.jscrollpane)
24 |
25 | def setText(self, tip):
26 | self.textarea.setText(tip)
27 | self.textarea.setCaretPosition(0)
28 | #print >> sys.stderr, self.textarea.getPreferredScrollableViewportSize()
29 | self.setSize(self.getPreferredSize())
30 |
31 | def getPreferredSize(self):
32 | # need to add a magic amount to the size to avoid scrollbars
33 | # I'm sure there's a better way to do this
34 | MAGIC = 20
35 | size = self.textarea.getPreferredScrollableViewportSize()
36 | height = size.height + MAGIC
37 | width = size.width + MAGIC
38 | if height > Tip.MAX_HEIGHT:
39 | height = Tip.MAX_HEIGHT
40 | if width > Tip.MAX_WIDTH:
41 | width = Tip.MAX_WIDTH
42 | return Dimension(width, height)
43 |
44 | def showTip(self, tip, displayPoint):
45 | self.setLocation(displayPoint)
46 | self.setText(tip)
47 | self.show()
48 |
--------------------------------------------------------------------------------
/src/main/resources/external/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/src/main/resources/external/__init__.py
--------------------------------------------------------------------------------
/src/main/resources/org/ggp/base/apps/utilities/SampleKeys.json:
--------------------------------------------------------------------------------
1 | {"PK":"0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgjgpQmdHCwKOrM1KS3u4d6CwAqbr715o0ARK+bQKXH8aSXfQCPUdyjCG6KQ1CENr4VdBWS8UYvPlMcCmjfPQkFJ+u7XF7/TDuDgYMUDAC5qJ4UmMD49bzlE7nW+4dVHSUsJr2WWSMgh7vbSbvIUhpCsTxG0OxIcwZ0cY0NwnF2RVXBLVH1nsey4ExjtuyI3Jp21yKzX1CDUwhrczp69j4wVSEFzeiyfNk70SZhi14q5lxZ1O/h3ZlhnIAU5Ko7Cej9Kh6Xd6OfBriav4yBTBcVV+uPQvRsyAgRQpKe/5qVxCnVejcTpaNPXZcjH3GMB/F3IZPSVZ2uluaf1U3EPUrwIDAQAB", "SK":"0MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCCOClCZ0cLAo6szUpLe7h3oLACpuvvXmjQBEr5tApcfxpJd9AI9R3KMIbopDUIQ2vhV0FZLxRi8+UxwKaN89CQUn67tcXv9MO4OBgxQMALmonhSYwPj1vOUTudb7h1UdJSwmvZZZIyCHu9tJu8hSGkKxPEbQ7EhzBnRxjQ3CcXZFVcEtUfWex7LgTGO27IjcmnbXIrNfUINTCGtzOnr2PjBVIQXN6LJ82TvRJmGLXirmXFnU7+HdmWGcgBTkqjsJ6P0qHpd3o58GuJq/jIFMFxVX649C9GzICBFCkp7/mpXEKdV6NxOlo09dlyMfcYwH8Xchk9JVna6W5p/VTcQ9SvAgMBAAECggEAcMy5YN4Zuj3S3XlPPCfF2UqGbSWvBsDfRiIR2E/PEeTAHpf8y2WZEoYKtwdXMPtGPgLZhqmznSvsg7aAEEL9jacIRQ3mkj+SMsfUnQWb1fFeMpsFCo2CVywi2fPm8ymXaT0lM0I668BRgDktFpa0V4NBMkvOGQuKMEx0AKhT7Hwu4zWUSFWeeCb+pwyWlNSMUDJPIrVcbO2UnV9NxgneHLC3s2z+4k9ZwaMFbnu7bMQpPeCqr6uj0mwJfIcxwFjMIX1NeUjmQQdsvSFral7Cnzfk7Egu6CVo8toDWmSe0HNSb8+Hg7dXevvC4KK7vJ9ada+Uyp29InWNSacYJxdfEQKBgQC5I/T0Tk46XvwCE7ZCcJEsAkAV1v6Q5amdxIq6md5IdZt6hmrEVTyQp5cHl10cAi69IsXuTJme+dj8taGsHUXyI/NlmOp+lT8aghTc3ou9zCNpJEOS0upz/TFNebpEs6v7L037ALuWvvqJMmGbroBz/7B5rWoFjToGhtYl5kE0BQKBgQC0DwrzLenH//pQxffgaFnUV1d7UConx43UfhmOH/3Nymct+95gc9mrQSy/Vw51KLJID+XL2pY964U4dQpp+7s8mro8ZvX7hHOjPjLcsOoB6e0LXJZxLcKRc6p6/IS036xHmJkK621eqi1cFIjBOQLooIk3nkt4O9DUr22haxhYIwKBgHFKPm9sp1PyoZUHyOSZC0x5yAtVNwslbghbp2SOGUYPqWdtb1Hasqf11WZQyioEb+NOrv2mI+7zBkOFRXwToaSNOTh3PS7eVvH6nZeWGr62dwi0pyDmLY9yZMP68+9sXpXjGX25shCJprdje/UO8A2LbcrXQeRJyjMKOWqRnl6dAoGAfDyA3qeITdIGQeNGk9UMXiHhn5kBbS8YYkybj1/tfCeyp5zIpB5rSumOWXtU42uwD17AvLZWweSWqAzBobzqRPexlmmoQeHy8+i/qVx8KdPhFdzNhMwBGuEG+RLw8ef+8+uLdWhZr16WK5mTfla69g2GgBS9l/kVrxpX929wfacCgYEAtBHWmjuj37ZRen6f9XyTtFAzz7aYcvo6J7ZWciI8bi1XCi5eDQ3f2noCw7ztxHa1pZTgT03iPK63it4LqbMK4vVUmr6BmoxjTdcaFjmX9Es/BXm/8bhXGA1iBFkk+zscX/d7w9WVHHbbA5jcaaKYxzR2liKpdNnRKeHpc7+0Zak="}
--------------------------------------------------------------------------------
/src/main/resources/sample_gamer.clj:
--------------------------------------------------------------------------------
1 | (ns gamer_namespace
2 | (:import [org.ggp.base.player.gamer.statemachine StateMachineGamer]
3 | [org.ggp.base.util.statemachine.implementation.prover ProverStateMachine]))
4 |
5 | ;; An implementation of a sample random gamer in Clojure.
6 | ;; -Sam Schreiber
7 | (defn SampleClojureGamer []
8 | (proxy [StateMachineGamer] []
9 | ;; NOTE: the implicit 'this symbol is bound to the local class.
10 |
11 | (getInitialStateMachine []
12 | (ProverStateMachine.))
13 |
14 | (stateMachineSelectMove [timeout]
15 | (let [state-machine (.getStateMachine this)
16 | current-state (.getCurrentState this)
17 | role (.getRole this)
18 | random-move (.getRandomMove state-machine
19 | current-state
20 | role)]
21 | random-move))
22 |
23 | (stateMachineMetaGame [timeout]
24 | (println "SampleClojureGamer metagame called"))
25 |
26 | (stateMachineAbort []
27 | (println "SampleClojureGamer abort called"))
28 |
29 | (stateMachineStop []
30 | (println "SampleClojureGamer stop called"))))
31 |
--------------------------------------------------------------------------------
/src/main/resources/sample_gamer.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sam
3 | '''
4 |
5 | import random
6 |
7 | from org.ggp.base.util.statemachine import MachineState
8 | from org.ggp.base.util.statemachine.implementation.prover import ProverStateMachine
9 | from org.ggp.base.player.gamer.statemachine import StateMachineGamer
10 |
11 | class SamplePythonGamer(StateMachineGamer):
12 |
13 | def getName(self):
14 | pass
15 |
16 | def stateMachineMetaGame(self, timeout):
17 | pass
18 |
19 | def stateMachineSelectMove(self, timeout):
20 | moves = self.getStateMachine().getLegalMoves(self.getCurrentState(), self.getRole())
21 | selection = random.choice(moves)
22 | return selection
23 |
24 | def stateMachineStop(self):
25 | pass
26 |
27 | def stateMachineAbort(self):
28 | pass
29 |
30 | def getInitialStateMachine(self):
31 | return ProverStateMachine()
--------------------------------------------------------------------------------
/src/main/resources/scripts.py:
--------------------------------------------------------------------------------
1 | # This is a library of short scripts for use in the Python console.
2 | # These should make is easier to experiment with the GGP base classes
3 | # from a Python command line.
4 | #
5 | # -Sam
6 |
7 | from org.ggp.base.util.game import GameRepository
8 | from org.ggp.base.util.statemachine.implementation.prover import ProverStateMachine
9 |
10 | def load_game(game_name):
11 | game_description = GameRepository.getDefaultRepository().getGame(game_name).getRules()
12 | machine = ProverStateMachine()
13 | machine.initialize(game_description)
14 | return machine
15 |
16 | def display_random_walk(machine):
17 | state = machine.getInitialState()
18 | while not machine.isTerminal(state):
19 | print state
20 | state = machine.getRandomNextState(state)
21 |
--------------------------------------------------------------------------------
/src/main/scala/org/ggp/base/scala/player/gamer/statemachine/SampleRandomGamer.scala:
--------------------------------------------------------------------------------
1 | package org.ggp.base.scala.player.gamer.statemachine
2 |
3 | import org.ggp.base.player.gamer.statemachine.StateMachineGamer
4 | import org.ggp.base.util.game.Game
5 | import org.ggp.base.util.statemachine.implementation.prover.ProverStateMachine
6 | import org.ggp.base.util.statemachine.{Move, StateMachine}
7 |
8 | /**
9 | * Created by steve on 11/1/2015.
10 | */
11 | class SampleRandomGamer extends StateMachineGamer {
12 | def stateMachineSelectMove(l: Long): Move = {
13 | val sm = getStateMachine
14 | val state = getCurrentState
15 | val role = getRole
16 |
17 | sm.getRandomMove(state, role)
18 | }
19 |
20 | def stateMachineAbort(): Unit = {}
21 |
22 | def stateMachineMetaGame(l: Long): Unit = {}
23 |
24 | def stateMachineStop(): Unit = {}
25 |
26 | def getInitialStateMachine: StateMachine = new ProverStateMachine()
27 |
28 | def getName: String = "Sample Scala legal gamer"
29 |
30 | def preview(game: Game, l: Long): Unit = {}
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/player/gamer/clojure/ClojureGamerTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.player.gamer.clojure;
2 |
3 | import org.ggp.base.player.gamer.Gamer;
4 | import org.ggp.base.player.gamer.clojure.stubs.SampleClojureGamerStub;
5 | import org.ggp.base.util.game.GameRepository;
6 | import org.ggp.base.util.gdl.grammar.GdlPool;
7 | import org.ggp.base.util.match.Match;
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | /**
12 | * Unit tests for the ClojureGamer class, to verify that we can actually
13 | * instantiate a Clojure-based gamer and have it play moves in a game.
14 | *
15 | * @author Sam
16 | */
17 | public class ClojureGamerTest extends Assert {
18 | @Test
19 | public void testClojureGamer() {
20 | try {
21 | Gamer g = new SampleClojureGamerStub();
22 | assertEquals("SampleClojureGamer", g.getName());
23 |
24 | Match m = new Match("", -1, 1000, 1000, GameRepository.getDefaultRepository().getGame("ticTacToe"), "");
25 | g.setMatch(m);
26 | g.setRoleName(GdlPool.getConstant("xplayer"));
27 | g.metaGame(1000);
28 | assertTrue(g.selectMove(1000) != null);
29 | } catch(Exception e) {
30 | e.printStackTrace();
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/player/gamer/python/PythonGamerTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.player.gamer.python;
2 |
3 | import org.ggp.base.player.gamer.Gamer;
4 | import org.ggp.base.player.gamer.python.stubs.SamplePythonGamerStub;
5 | import org.ggp.base.util.game.GameRepository;
6 | import org.ggp.base.util.gdl.grammar.GdlPool;
7 | import org.ggp.base.util.match.Match;
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | /**
12 | * Unit tests for the PythonGamer class, to verify that we can actually
13 | * instantiate a Python-based gamer and have it play moves in a game.
14 | *
15 | * @author Sam
16 | */
17 | public class PythonGamerTest extends Assert {
18 | @Test
19 | public void testPythonGamer() {
20 | try {
21 | Gamer g = new SamplePythonGamerStub();
22 | assertEquals("SamplePythonGamer", g.getName());
23 |
24 | Match m = new Match("", -1, 1000, 1000, GameRepository.getDefaultRepository().getGame("ticTacToe"), "");
25 | g.setMatch(m);
26 | g.setRoleName(GdlPool.getConstant("xplayer"));
27 | g.metaGame(1000);
28 | assertTrue(g.selectMove(1000) != null);
29 | } catch(Exception e) {
30 | e.printStackTrace();
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/test/AllTests.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.test;
2 |
3 | import org.ggp.base.apps.logging.LogSummarizerTest;
4 | import org.ggp.base.apps.tiltyard.TiltyardRequestFarmTest;
5 | import org.ggp.base.player.gamer.clojure.ClojureGamerTest;
6 | import org.ggp.base.player.gamer.python.PythonGamerTest;
7 | import org.ggp.base.util.crypto.BaseCryptographyTest;
8 | import org.ggp.base.util.crypto.BaseHashingTest;
9 | import org.ggp.base.util.crypto.CanonicalJSONTest;
10 | import org.ggp.base.util.crypto.SignableJSONTest;
11 | import org.ggp.base.util.game.GameParsingTest;
12 | import org.ggp.base.util.gdl.model.DependencyGraphsTest;
13 | import org.ggp.base.util.gdl.model.SimpleSentenceFormTest;
14 | import org.ggp.base.util.gdl.scrambler.GdlRendererTest;
15 | import org.ggp.base.util.gdl.scrambler.GdlScramblerTest;
16 | import org.ggp.base.util.gdl.transforms.GdlCleanerTest;
17 | import org.ggp.base.util.http.HttpTest;
18 | import org.ggp.base.util.presence.InfoResponseTest;
19 | import org.ggp.base.util.statemachine.implementation.prover.ProverStateMachineTest;
20 | import org.ggp.base.validator.StaticValidationTest;
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.Suite;
23 |
24 | @RunWith(Suite.class)
25 | @Suite.SuiteClasses({
26 | BaseCryptographyTest.class,
27 | BaseHashingTest.class,
28 | CanonicalJSONTest.class,
29 | ClojureGamerTest.class,
30 | DependencyGraphsTest.class,
31 | GameParsingTest.class,
32 | GdlCleanerTest.class,
33 | GdlRendererTest.class,
34 | GdlScramblerTest.class,
35 | HttpTest.class,
36 | InfoResponseTest.class,
37 | LogSummarizerTest.class,
38 | NoTabsInRulesheetsTest.class,
39 | ProverStateMachineTest.class,
40 | PythonGamerTest.class,
41 | SignableJSONTest.class,
42 | SimpleSentenceFormTest.class,
43 | StaticValidationTest.class,
44 | TiltyardRequestFarmTest.class,
45 | })
46 | public class AllTests {
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/test/NoTabsInRulesheetsTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.test;
2 |
3 |
4 | import java.io.BufferedWriter;
5 | import java.io.File;
6 | import java.io.FileFilter;
7 | import java.io.FileWriter;
8 | import java.io.IOException;
9 |
10 | import org.ggp.base.util.files.FileUtils;
11 | import org.junit.Assert;
12 | import org.junit.Test;
13 |
14 |
15 | public class NoTabsInRulesheetsTest extends Assert {
16 | // Check that GGP-Base's games use spaces, not tabs.
17 | @Test
18 | public void testNoTabsInRulesheets() {
19 | File testGamesFolder = new File("games", "test");
20 | assertTrue(testGamesFolder.isDirectory());
21 |
22 | for (File gameFile : testGamesFolder.listFiles(new KifFileFilter())) {
23 | String fileContents = FileUtils.readFileAsString(gameFile);
24 | assertFalse("The game "+gameFile+" contains tabs. Run the main method in NoTabsInRulesheetsTest to fix this.", fileContents.contains("\t"));
25 | }
26 | }
27 |
28 | // Modify the test games to use spaces instead of tabs.
29 | public static void main(String[] args) throws Exception {
30 | File testGamesFolder = new File("games", "test");
31 | assertTrue(testGamesFolder.isDirectory());
32 |
33 | for (File gameFile : testGamesFolder.listFiles(new KifFileFilter())) {
34 | String fileContents = FileUtils.readFileAsString(gameFile);
35 | String newContents = fileContents.replaceAll("\t", " "); //four spaces
36 | overwriteFileWithString(gameFile, newContents);
37 | }
38 | }
39 |
40 | static void overwriteFileWithString(File file, String newContents) throws IOException {
41 | BufferedWriter writer = new BufferedWriter(new FileWriter(file));
42 | writer.append(newContents);
43 | writer.close();
44 | }
45 |
46 | static class KifFileFilter implements FileFilter {
47 | @Override
48 | public boolean accept(File pathname) {
49 | return pathname.getName().endsWith(".kif");
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/crypto/BaseCryptographyTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.crypto;
2 |
3 | import org.ggp.base.util.crypto.BaseCryptography.EncodedKeyPair;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * Unit tests for the BaseCryptography class, which implements
9 | * a wrapper for the use of asymmetric public/private key cryptography
10 | * for use in GGP.
11 | *
12 | * @author Sam
13 | */
14 | public class BaseCryptographyTest extends Assert {
15 | @Test
16 | public void testSimpleCryptography() throws Exception {
17 | // Not an ideal unit test because generating the key takes a while,
18 | // but it's useful to have test coverage at all so we'll make due.
19 | EncodedKeyPair theKeys = BaseCryptography.generateKeys();
20 | String theSK = theKeys.thePrivateKey;
21 | String thePK = theKeys.thePublicKey;
22 |
23 | String theData = "Hello world!";
24 | String theSignature = BaseCryptography.signData(theSK, theData);
25 | assertTrue(BaseCryptography.verifySignature(thePK, theSignature, theData));
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/crypto/BaseHashingTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.crypto;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | /**
7 | * Unit tests for the BaseHashing class, which implements some utility
8 | * functions for cryptographic hashing in GGP.
9 | *
10 | * @author Sam
11 | */
12 | public class BaseHashingTest extends Assert {
13 | @Test
14 | public void testHashesAreExpected() throws Exception {
15 | // Hash codes generated by "computeSHA1Hash" are persisted in several places.
16 | // It's important that we not change this hash function, or systems that depend
17 | // on these persisted hash codes will break in unexpected ways. This test is set
18 | // up to fail if the hashing algorithm ever changes.
19 | assertEquals(BaseHashing.computeSHA1Hash("hello world"), "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed");
20 | assertEquals(BaseHashing.computeSHA1Hash("12345678901"), "266dc053a8163e676e83243070241c8917f8a8a3");
21 | }
22 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/crypto/CanonicalJSONTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.crypto;
2 |
3 | import org.ggp.base.util.crypto.CanonicalJSON.CanonicalizationStrategy;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | /**
8 | * Unit tests for the CanonicalJSON class, which provides a
9 | * standard way for GGP systems to canonicalize JSON objects.
10 | * This is an important step in signing JSON objects.
11 | *
12 | * @author Sam
13 | */
14 | public class CanonicalJSONTest extends Assert {
15 | @Test
16 | public void testSimpleCanonicalization() {
17 | CanonicalizationStrategy theStrategy = CanonicalizationStrategy.SIMPLE;
18 |
19 | String a = CanonicalJSON.getCanonicalForm("{1:2,2:3,3:{2:5,c:4,7:9,a:6}}", theStrategy);
20 | assertEquals(a, CanonicalJSON.getCanonicalForm("{2:3,3:{c:4,7:9,2:5,a:6},1:2}", theStrategy));
21 | assertEquals(a, CanonicalJSON.getCanonicalForm("{3:{c:4,7:9,2:5,a:6},2:3,1:2}", theStrategy));
22 | assertEquals(a, CanonicalJSON.getCanonicalForm("{3:{7:9,c:4,2:5,a:6},1:2,2:3}", theStrategy));
23 | assertEquals(a, CanonicalJSON.getCanonicalForm("{2:3,3:{c:4,7:9,a:6,2:5},1:2}", theStrategy));
24 | assertEquals(a, "{\"1\":2,\"2\":3,\"3\":{\"2\":5,\"7\":9,\"a\":6,\"c\":4}}");
25 |
26 | String b = CanonicalJSON.getCanonicalForm("{'abc':3, \"def\":4, ghi:5}", theStrategy);
27 | assertEquals(b, CanonicalJSON.getCanonicalForm("{'def':4, abc:3, \"ghi\":5}", theStrategy));
28 | assertEquals(b, CanonicalJSON.getCanonicalForm("{\"def\":4, ghi:5, 'abc':3}", theStrategy));
29 | assertEquals(b, CanonicalJSON.getCanonicalForm("{abc:3, def:4, ghi:5}", theStrategy));
30 | assertEquals(b, CanonicalJSON.getCanonicalForm("{'abc':3, 'def':4, 'ghi':5}", theStrategy));
31 | assertEquals(b, CanonicalJSON.getCanonicalForm("{\"abc\":3, \"def\":4, \"ghi\":5}", theStrategy));
32 | assertEquals(b, "{\"abc\":3,\"def\":4,\"ghi\":5}");
33 | }
34 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/crypto/SignableJSONTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.crypto;
2 |
3 | import org.ggp.base.util.crypto.BaseCryptography.EncodedKeyPair;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | import external.JSON.JSONException;
8 | import external.JSON.JSONObject;
9 |
10 | /**
11 | * Unit tests for the SignableJSON class, which provides an easy way
12 | * for code to sign JSON objects using PK/SK pairs, and check whether
13 | * a particular object has been signed.
14 | *
15 | * @author Sam
16 | */
17 | public class SignableJSONTest extends Assert {
18 | @Test
19 | public void testSimpleSigning() throws JSONException {
20 | EncodedKeyPair p = BaseCryptography.generateKeys();
21 |
22 | JSONObject x = new JSONObject("{3:{7:9,c:4,2:5,a:6},1:2,2:3,moves:14,states:21,alpha:'beta'}");
23 | assertFalse(SignableJSON.isSignedJSON(x));
24 | SignableJSON.signJSON(x, p.thePublicKey, p.thePrivateKey);
25 | assertTrue(SignableJSON.isSignedJSON(x));
26 | assertTrue(SignableJSON.verifySignedJSON(x));
27 |
28 | JSONObject x2 = new JSONObject(x.toString().replace(",", ", ").replace("{", "{ ").replace("}", "} "));
29 | assertTrue(SignableJSON.isSignedJSON(x2));
30 | assertTrue(SignableJSON.verifySignedJSON(x2));
31 |
32 | JSONObject x3 = new JSONObject("{1:2,2:3,3:4}");
33 | assertFalse(SignableJSON.isSignedJSON(x3));
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/game/GameParsingTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.game;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | public class GameParsingTest extends Assert {
7 |
8 | @Test
9 | public void testParseGame() throws Exception {
10 | StringBuilder theRulesheet = new StringBuilder();
11 | theRulesheet.append("; comment\n");
12 | theRulesheet.append("(a b)\n");
13 | theRulesheet.append("; comment two\n");
14 | theRulesheet.append("(c d e) ; comment three\n");
15 | theRulesheet.append("(f g)\n");
16 | theRulesheet.append("(h i j)\n");
17 | assertEquals(4, Game.createEphemeralGame(Game.preprocessRulesheet(theRulesheet.toString())).getRules().size());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/gdl/model/DependencyGraphsTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.gdl.model;
2 |
3 | import java.util.List;
4 | import java.util.Set;
5 |
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | import com.google.common.collect.HashMultimap;
10 | import com.google.common.collect.ImmutableSet;
11 | import com.google.common.collect.Multimap;
12 | import com.google.common.collect.Sets;
13 |
14 | public class DependencyGraphsTest extends Assert {
15 | @Test
16 | public void testSafeToposort() throws Exception {
17 | Set allElements = Sets.newHashSet(1, 2, 3, 4, 5, 6, 7, 8);
18 | Multimap graph = HashMultimap.create();
19 |
20 | graph.put(2, 1);
21 | graph.put(3, 2);
22 | graph.put(4, 2);
23 | graph.put(5, 3);
24 | graph.put(5, 4);
25 | graph.put(3, 4);
26 | graph.put(4, 3);
27 | graph.put(4, 6);
28 | graph.put(6, 7);
29 | graph.put(7, 8);
30 | graph.put(8, 3);
31 |
32 | List> ordering = DependencyGraphs.toposortSafe(allElements, graph);
33 | assertEquals(4, ordering.size());
34 | assertEquals(ImmutableSet.of(1), ordering.get(0));
35 | assertEquals(ImmutableSet.of(2), ordering.get(1));
36 | assertEquals(ImmutableSet.of(3, 4, 6, 7, 8), ordering.get(2));
37 | assertEquals(ImmutableSet.of(5), ordering.get(3));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/gdl/model/SimpleSentenceFormTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.gdl.model;
2 |
3 | import java.util.List;
4 |
5 | import org.ggp.base.util.gdl.GdlUtils;
6 | import org.ggp.base.util.gdl.factory.GdlFactory;
7 | import org.ggp.base.util.gdl.grammar.GdlPool;
8 | import org.ggp.base.util.gdl.grammar.GdlSentence;
9 | import org.ggp.base.util.gdl.grammar.GdlTerm;
10 | import org.junit.Assert;
11 | import org.junit.Test;
12 |
13 | public class SimpleSentenceFormTest extends Assert {
14 | @Test
15 | public void testFunctionNesting() throws Exception {
16 | GdlSentence sentence = (GdlSentence) GdlFactory.create("(does player (combine foo (bar b b)))");
17 | SimpleSentenceForm form = SimpleSentenceForm.create(sentence);
18 | assertEquals(GdlPool.DOES, form.getName());
19 | assertEquals(4, form.getTupleSize());
20 | assertTrue(form.matches(sentence));
21 |
22 | List tuple = GdlUtils.getTupleFromSentence(sentence);
23 | assertEquals(sentence, form.getSentenceFromTuple(tuple));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/gdl/scrambler/GdlRendererTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.gdl.scrambler;
2 |
3 | import org.ggp.base.util.game.Game;
4 | import org.ggp.base.util.game.GameRepository;
5 | import org.ggp.base.util.gdl.grammar.Gdl;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 |
9 | /**
10 | * Unit tests for the GdlRenderer class, which provides a way
11 | * to render Gdl objects as Strings.
12 | *
13 | * @author Sam
14 | */
15 | public class GdlRendererTest extends Assert {
16 | /**
17 | * One important property for GdlRenderer is that it should generate
18 | * an identical rendering as if you had called the toString() method
19 | * on a Gdl object.
20 | */
21 | @Test
22 | public void testSimpleRendering() {
23 | GdlRenderer renderer = new GdlRenderer();
24 | GameRepository repo = GameRepository.getDefaultRepository();
25 | for (String gameKey : repo.getGameKeys()) {
26 | Game game = repo.getGame(gameKey);
27 | for(Gdl rule : game.getRules()) {
28 | assertEquals(rule.toString(), renderer.renderGdl(rule));
29 | }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/test/java/org/ggp/base/util/gdl/transforms/GdlCleanerTest.java:
--------------------------------------------------------------------------------
1 | package org.ggp.base.util.gdl.transforms;
2 |
3 | import java.util.List;
4 |
5 | import org.ggp.base.util.game.TestGameRepository;
6 | import org.ggp.base.util.gdl.grammar.Gdl;
7 | import org.ggp.base.util.statemachine.MachineState;
8 | import org.ggp.base.util.statemachine.Role;
9 | import org.ggp.base.util.statemachine.StateMachine;
10 | import org.ggp.base.util.statemachine.implementation.prover.ProverStateMachine;
11 | import org.ggp.base.validator.StaticValidator;
12 | import org.junit.Assert;
13 | import org.junit.Test;
14 |
15 | public class GdlCleanerTest extends Assert {
16 |
17 | @Test
18 | public void testCleanNotDistinct() throws Exception {
19 | List description = new TestGameRepository().getGame("test_clean_not_distinct").getRules();
20 | description = GdlCleaner.run(description);
21 |
22 | StaticValidator.validateDescription(description);
23 |
24 | StateMachine sm = new ProverStateMachine();
25 | sm.initialize(description);
26 | MachineState state = sm.getInitialState();
27 | assertEquals(1, sm.getRoles().size());
28 | Role player = sm.getRoles().get(0);
29 | assertEquals(1, sm.getLegalMoves(state, player).size());
30 | state = sm.getNextStates(state).get(0);
31 | assertTrue(sm.isTerminal(state));
32 | assertEquals(100, sm.getGoal(state, player));
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------