├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs └── org.eclipse.ltk.core.refactoring.prefs ├── PROGRAMS ├── README ├── build.gradle ├── build.xml ├── cleanup.sh ├── config └── checkstyle │ └── checkstyle.xml ├── gameServerRunner.sh ├── games ├── games │ ├── connectFour │ │ ├── METADATA │ │ ├── connectFour.js │ │ ├── connectFour.kif │ │ ├── connectFour.txt │ │ └── connectFour.xsl │ ├── maze │ │ ├── METADATA │ │ ├── maze.kif │ │ └── maze.xsl │ └── ticTacToe │ │ ├── METADATA │ │ ├── ticTacToe.js │ │ ├── ticTacToe.kif │ │ ├── ticTacToe.txt │ │ └── ticTacToe.xsl ├── resources │ └── images │ │ ├── checkers │ │ ├── black_king.png │ │ ├── crown.png │ │ └── red_king.png │ │ ├── chess │ │ ├── Black_Bishop.png │ │ ├── Black_King.png │ │ ├── Black_Knight.png │ │ ├── Black_Pawn.png │ │ ├── Black_Queen.png │ │ ├── Black_Rook.png │ │ ├── White_Bishop.png │ │ ├── White_King.png │ │ ├── White_Knight.png │ │ ├── White_Pawn.png │ │ ├── White_Queen.png │ │ └── White_Rook.png │ │ ├── discs │ │ ├── black.png │ │ ├── blue.png │ │ ├── green.png │ │ ├── grey.png │ │ ├── orange.png │ │ ├── purple.png │ │ ├── red.png │ │ ├── teal.png │ │ ├── white.png │ │ └── yellow.png │ │ └── pentago │ │ ├── BlueCircleArrowCCW.png │ │ └── BlueCircleArrowCW.png └── test │ ├── connectFour.kif │ ├── simpleMutex.kif │ ├── test_case_1a.kif │ ├── test_case_1b.kif │ ├── test_case_2a.kif │ ├── test_case_2b.kif │ ├── test_case_2c.kif │ ├── test_case_3a.kif │ ├── test_case_3b.kif │ ├── test_case_3c.kif │ ├── test_case_3d.kif │ ├── test_case_3e.kif │ ├── test_case_3f.kif │ ├── test_case_4a.kif │ ├── test_case_5a.kif │ ├── test_case_5b.kif │ ├── test_case_5c.kif │ ├── test_case_5d.kif │ ├── test_case_5e.kif │ ├── test_clean_not_distinct.kif │ ├── test_distinct_beginning_rule.kif │ ├── test_invalid_function_arities_differ.kif │ ├── test_invalid_sentence_arities_differ.kif │ └── ticTacToe.kif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── Batik │ ├── batik-1.7.jar │ └── xml-apis-ext.jar ├── Clojure │ └── clojure.jar ├── FlyingSaucer │ └── core-renderer.jar ├── Guava │ ├── guava-14.0.1-sources.jar │ └── guava-14.0.1.jar ├── Htmlparser │ └── htmlparser-1.4.jar ├── JFreeChart │ ├── jcommon-1.0.17.jar │ └── jfreechart-1.0.14.jar ├── JGoodiesForms │ └── forms-1.2.1.jar ├── JUnit │ ├── hamcrest-core-1.3.jar │ └── junit-4.11.jar ├── Jython │ └── jython.jar ├── gdl-validation │ ├── gdl-validation-0.2.2-sources.jar │ ├── gdl-validation-0.2.2.jar │ └── java-cup-11b-runtime-2015.03.26.jar ├── javassist │ └── javassist.jar └── reflections │ └── reflections-0.9.9-RC1.jar ├── licences ├── Batik │ ├── Apache-2.0 │ └── xml-apis-ext.copyright ├── FlyingSaucer │ ├── LICENSE │ ├── LICENSE-LGPL-2.1.txt │ └── LICENSE-W3C-TEST ├── Htmlparser │ └── LICENSE ├── JSON │ └── LICENSE ├── JTidy │ └── LICENSE ├── Jython │ └── LICENSE ├── JythonConsole │ └── COPYING.txt └── LICENSE ├── overview.html ├── playerRunner.sh └── src ├── main ├── java │ ├── external │ │ ├── Base64Coder │ │ │ └── Base64Coder.java │ │ └── JSON │ │ │ ├── JSONArray.java │ │ │ ├── JSONException.java │ │ │ ├── JSONObject.java │ │ │ ├── JSONString.java │ │ │ ├── JSONTokener.java │ │ │ └── README │ └── org │ │ └── ggp │ │ └── base │ │ ├── apps │ │ ├── benchmark │ │ │ ├── EndgameCaseGenerator.java │ │ │ ├── ImportSanchoCases.java │ │ │ ├── PlayerTester.java │ │ │ └── PlayerTesterCases.java │ │ ├── consoles │ │ │ ├── ClojureConsole.java │ │ │ └── PythonConsole.java │ │ ├── kiosk │ │ │ ├── GameCanvas.java │ │ │ ├── GameGUI.java │ │ │ ├── Kiosk.java │ │ │ ├── KioskGamer.java │ │ │ ├── MoveSelectedEvent.java │ │ │ ├── games │ │ │ │ ├── BattleCanvas.java │ │ │ │ ├── BiddingTicTacToeCanvas.java │ │ │ │ ├── BlockerCanvas.java │ │ │ │ ├── BlokboxSimpleCanvas.java │ │ │ │ ├── BreakthroughCanvas.java │ │ │ │ ├── BreakthroughHolesCanvas.java │ │ │ │ ├── BreakthroughSmallCanvas.java │ │ │ │ ├── CephalopodCanvas.java │ │ │ │ ├── CheckersCanvas.java │ │ │ │ ├── CheckersSmallCanvas.java │ │ │ │ ├── CheckersTinyCanvas.java │ │ │ │ ├── ChessCanvas.java │ │ │ │ ├── ChickenTicTacToeCanvas.java │ │ │ │ ├── ConnectFiveCanvas.java │ │ │ │ ├── ConnectFourCanvas.java │ │ │ │ ├── FFACanvas.java │ │ │ │ ├── GoldenRectangleCanvas.java │ │ │ │ ├── KnightFightCanvas.java │ │ │ │ ├── KnightthroughCanvas.java │ │ │ │ ├── NumberTicTacToeCanvas.java │ │ │ │ ├── PawnWhoppingCanvas.java │ │ │ │ ├── PentagoCanvas.java │ │ │ │ ├── TTCC4Canvas.java │ │ │ │ ├── TTCC4SmallCanvas.java │ │ │ │ ├── TTCCanvas.java │ │ │ │ ├── TTTxNineCanvas.java │ │ │ │ ├── TicTacToeCanvas.java │ │ │ │ └── TicTacToeCanvas_Reference.java │ │ │ └── templates │ │ │ │ ├── CommonGraphics.java │ │ │ │ ├── GameCanvas_Chessboard.java │ │ │ │ ├── GameCanvas_FancyGrid.java │ │ │ │ └── GameCanvas_SimpleGrid.java │ │ ├── logging │ │ │ ├── ExampleLogSummarizer.java │ │ │ └── LogSummarizer.java │ │ ├── player │ │ │ ├── Player.java │ │ │ ├── PlayerRunner.java │ │ │ ├── ProxiedPlayerRunner.java │ │ │ ├── config │ │ │ │ ├── ConfigPanel.java │ │ │ │ └── EmptyConfigPanel.java │ │ │ ├── detail │ │ │ │ ├── DetailPanel.java │ │ │ │ ├── EmptyDetailPanel.java │ │ │ │ └── SimpleDetailPanel.java │ │ │ ├── match │ │ │ │ └── MatchPanel.java │ │ │ └── network │ │ │ │ └── NetworkPanel.java │ │ ├── research │ │ │ ├── Aggregation.java │ │ │ ├── Counter.java │ │ │ ├── FrequencyTable.java │ │ │ ├── Histogram.java │ │ │ ├── MatchArchiveProcessor.java │ │ │ └── WeightedAverage.java │ │ ├── server │ │ │ ├── Server.java │ │ │ ├── error │ │ │ │ └── ErrorPanel.java │ │ │ ├── history │ │ │ │ └── HistoryPanel.java │ │ │ ├── leaderboard │ │ │ │ └── LeaderboardPanel.java │ │ │ ├── scheduling │ │ │ │ ├── PendingMatch.java │ │ │ │ ├── Scheduler.java │ │ │ │ └── SchedulingPanel.java │ │ │ ├── states │ │ │ │ └── StatesPanel.java │ │ │ └── visualization │ │ │ │ ├── VisualizationPanel.java │ │ │ │ └── VizContainerPanel.java │ │ ├── tiltyard │ │ │ └── TiltyardRequestFarm.java │ │ ├── utilities │ │ │ ├── GameServerRunner.java │ │ │ └── SimpleGameSim.java │ │ └── validator │ │ │ ├── BatchValidator.java │ │ │ ├── OutcomePanel.java │ │ │ ├── Validator.java │ │ │ ├── ValidatorThread.java │ │ │ └── event │ │ │ ├── ValidatorFailureEvent.java │ │ │ └── ValidatorSuccessEvent.java │ │ ├── player │ │ ├── GamePlayer.java │ │ ├── event │ │ │ ├── PlayerDroppedPacketEvent.java │ │ │ ├── PlayerReceivedMessageEvent.java │ │ │ ├── PlayerSentMessageEvent.java │ │ │ └── PlayerTimeEvent.java │ │ ├── gamer │ │ │ ├── Gamer.java │ │ │ ├── clojure │ │ │ │ ├── ClojureGamer.java │ │ │ │ └── stubs │ │ │ │ │ └── SampleClojureGamerStub.java │ │ │ ├── event │ │ │ │ ├── GamerAbortedMatchEvent.java │ │ │ │ ├── GamerCompletedMatchEvent.java │ │ │ │ ├── GamerNewMatchEvent.java │ │ │ │ ├── GamerSelectedMoveEvent.java │ │ │ │ └── GamerUnrecognizedMatchEvent.java │ │ │ ├── exception │ │ │ │ ├── AbortingException.java │ │ │ │ ├── GamePreviewException.java │ │ │ │ ├── MetaGamingException.java │ │ │ │ ├── MoveSelectionException.java │ │ │ │ └── StoppingException.java │ │ │ ├── python │ │ │ │ ├── PythonGamer.java │ │ │ │ └── stubs │ │ │ │ │ └── SamplePythonGamerStub.java │ │ │ └── statemachine │ │ │ │ ├── StateMachineGamer.java │ │ │ │ ├── human │ │ │ │ ├── HumanGamer.java │ │ │ │ ├── event │ │ │ │ │ ├── HumanNewMovesEvent.java │ │ │ │ │ └── HumanTimeoutEvent.java │ │ │ │ └── gui │ │ │ │ │ └── HumanDetailPanel.java │ │ │ │ ├── random │ │ │ │ └── RandomGamer.java │ │ │ │ └── sample │ │ │ │ ├── SampleAlphabetGamer.java │ │ │ │ ├── SampleGamer.java │ │ │ │ ├── SampleMonteCarloGamer.java │ │ │ │ ├── SampleNoopGamer.java │ │ │ │ └── SampleSearchLightGamer.java │ │ ├── proxy │ │ │ ├── ProxyGamePlayer.java │ │ │ ├── ProxyGamePlayerClient.java │ │ │ ├── ProxyMessage.java │ │ │ └── WorkingResponseSelectedEvent.java │ │ └── request │ │ │ ├── factory │ │ │ ├── RequestFactory.java │ │ │ └── exceptions │ │ │ │ └── RequestFormatException.java │ │ │ └── grammar │ │ │ ├── AbortRequest.java │ │ │ ├── InfoRequest.java │ │ │ ├── PlayRequest.java │ │ │ ├── PreviewRequest.java │ │ │ ├── Request.java │ │ │ ├── StartRequest.java │ │ │ └── StopRequest.java │ │ ├── server │ │ ├── GameServer.java │ │ ├── event │ │ │ ├── ServerAbortedMatchEvent.java │ │ │ ├── ServerCompletedMatchEvent.java │ │ │ ├── ServerConnectionErrorEvent.java │ │ │ ├── ServerIllegalMoveEvent.java │ │ │ ├── ServerMatchUpdatedEvent.java │ │ │ ├── ServerNewGameStateEvent.java │ │ │ ├── ServerNewMatchEvent.java │ │ │ ├── ServerNewMovesEvent.java │ │ │ ├── ServerTimeEvent.java │ │ │ └── ServerTimeoutEvent.java │ │ ├── request │ │ │ └── RequestBuilder.java │ │ └── threads │ │ │ ├── AbortRequestThread.java │ │ │ ├── PlayRequestThread.java │ │ │ ├── PreviewRequestThread.java │ │ │ ├── RandomPlayRequestThread.java │ │ │ ├── RequestThread.java │ │ │ ├── StartRequestThread.java │ │ │ └── StopRequestThread.java │ │ ├── util │ │ ├── Pair.java │ │ ├── concurrency │ │ │ └── ConcurrencyUtils.java │ │ ├── configuration │ │ │ ├── GamerConfiguration.java │ │ │ └── ProjectConfiguration.java │ │ ├── crypto │ │ │ ├── BaseCryptography.java │ │ │ ├── BaseHashing.java │ │ │ ├── CanonicalJSON.java │ │ │ └── SignableJSON.java │ │ ├── files │ │ │ └── FileUtils.java │ │ ├── game │ │ │ ├── CloudGameRepository.java │ │ │ ├── Game.java │ │ │ ├── GameRepository.java │ │ │ ├── LocalGameRepository.java │ │ │ ├── RemoteGameRepository.java │ │ │ └── TestGameRepository.java │ │ ├── gdl │ │ │ ├── GdlUtils.java │ │ │ ├── GdlValidator.java │ │ │ ├── GdlVisitor.java │ │ │ ├── GdlVisitors.java │ │ │ ├── factory │ │ │ │ ├── GdlFactory.java │ │ │ │ └── exceptions │ │ │ │ │ └── GdlFormatException.java │ │ │ ├── grammar │ │ │ │ ├── Gdl.java │ │ │ │ ├── GdlConstant.java │ │ │ │ ├── GdlDistinct.java │ │ │ │ ├── GdlFunction.java │ │ │ │ ├── GdlLiteral.java │ │ │ │ ├── GdlNot.java │ │ │ │ ├── GdlOr.java │ │ │ │ ├── GdlPool.java │ │ │ │ ├── GdlProposition.java │ │ │ │ ├── GdlRelation.java │ │ │ │ ├── GdlRule.java │ │ │ │ ├── GdlSentence.java │ │ │ │ ├── GdlTerm.java │ │ │ │ └── GdlVariable.java │ │ │ ├── model │ │ │ │ ├── AbstractSentenceDomainModel.java │ │ │ │ ├── AbstractSentenceForm.java │ │ │ │ ├── CartesianSentenceFormDomain.java │ │ │ │ ├── DependencyGraphs.java │ │ │ │ ├── FullSentenceFormDomain.java │ │ │ │ ├── GameFlow.java │ │ │ │ ├── GameFlowTester.java │ │ │ │ ├── ImmutableSentenceDomainModel.java │ │ │ │ ├── ImmutableSentenceFormModel.java │ │ │ │ ├── SentenceDomainModel.java │ │ │ │ ├── SentenceDomainModelFactory.java │ │ │ │ ├── SentenceDomainModelOptimizer.java │ │ │ │ ├── SentenceDomainModels.java │ │ │ │ ├── SentenceForm.java │ │ │ │ ├── SentenceFormDomain.java │ │ │ │ ├── SentenceFormModel.java │ │ │ │ ├── SentenceFormModelFactory.java │ │ │ │ ├── SentenceForms.java │ │ │ │ ├── SentenceFormsFinder.java │ │ │ │ ├── SentenceModelUtils.java │ │ │ │ ├── SimpleSentenceForm.java │ │ │ │ └── assignments │ │ │ │ │ ├── AddibleFunctionInfo.java │ │ │ │ │ ├── AssignmentFunction.java │ │ │ │ │ ├── AssignmentIterationPlan.java │ │ │ │ │ ├── AssignmentIterator.java │ │ │ │ │ ├── AssignmentIteratorImpl.java │ │ │ │ │ ├── Assignments.java │ │ │ │ │ ├── AssignmentsFactory.java │ │ │ │ │ ├── AssignmentsImpl.java │ │ │ │ │ ├── FunctionInfo.java │ │ │ │ │ ├── FunctionInfoImpl.java │ │ │ │ │ ├── FunctionInfos.java │ │ │ │ │ ├── IterationOrderCandidate.java │ │ │ │ │ └── MutableFunctionInfo.java │ │ │ ├── scrambler │ │ │ │ ├── GdlRenderer.java │ │ │ │ ├── GdlScrambler.java │ │ │ │ ├── MappingGdlScrambler.java │ │ │ │ ├── NoOpGdlScrambler.java │ │ │ │ └── WordList.java │ │ │ └── transforms │ │ │ │ ├── CommonTransforms.java │ │ │ │ ├── CondensationIsolator.java │ │ │ │ ├── ConstantChecker.java │ │ │ │ ├── ConstantCheckerFactory.java │ │ │ │ ├── DeORer.java │ │ │ │ ├── DistinctAndNotMover.java │ │ │ │ ├── GdlCleaner.java │ │ │ │ ├── ImmutableConstantChecker.java │ │ │ │ ├── Relationizer.java │ │ │ │ ├── TransformTester.java │ │ │ │ ├── VariableConstrainer.java │ │ │ │ └── standalone │ │ │ │ ├── StandaloneDeORer.java │ │ │ │ └── StandaloneVariableConstrainer.java │ │ ├── http │ │ │ ├── HttpReader.java │ │ │ ├── HttpRequest.java │ │ │ └── HttpWriter.java │ │ ├── loader │ │ │ └── RemoteResourceLoader.java │ │ ├── logging │ │ │ ├── GamerLogger.java │ │ │ └── LogSummaryGenerator.java │ │ ├── match │ │ │ ├── Match.java │ │ │ └── MatchPublisher.java │ │ ├── observer │ │ │ ├── Event.java │ │ │ ├── Observer.java │ │ │ └── Subject.java │ │ ├── presence │ │ │ ├── InfoResponse.java │ │ │ ├── PlayerPresence.java │ │ │ └── PlayerPresenceManager.java │ │ ├── propnet │ │ │ ├── architecture │ │ │ │ ├── Component.java │ │ │ │ ├── PropNet.java │ │ │ │ └── components │ │ │ │ │ ├── And.java │ │ │ │ │ ├── Constant.java │ │ │ │ │ ├── Not.java │ │ │ │ │ ├── Or.java │ │ │ │ │ ├── Proposition.java │ │ │ │ │ └── Transition.java │ │ │ └── factory │ │ │ │ ├── LegacyPropNetFactory.java │ │ │ │ ├── OptimizingPropNetFactory.java │ │ │ │ ├── annotater │ │ │ │ └── PropNetAnnotater.java │ │ │ │ ├── converter │ │ │ │ └── PropNetConverter.java │ │ │ │ └── flattener │ │ │ │ ├── PropNetAnnotatedFlattener.java │ │ │ │ └── PropNetFlattener.java │ │ ├── prover │ │ │ ├── Prover.java │ │ │ └── aima │ │ │ │ ├── AimaProver.java │ │ │ │ ├── cache │ │ │ │ └── ProverCache.java │ │ │ │ ├── knowledge │ │ │ │ └── KnowledgeBase.java │ │ │ │ ├── renamer │ │ │ │ └── VariableRenamer.java │ │ │ │ ├── substituter │ │ │ │ └── Substituter.java │ │ │ │ ├── substitution │ │ │ │ └── Substitution.java │ │ │ │ └── unifier │ │ │ │ └── Unifier.java │ │ ├── reasoner │ │ │ ├── DifferentialForwardChainingReasoner.java │ │ │ ├── ForwardChainingReasoner.java │ │ │ └── gdl │ │ │ │ ├── GdlChainingReasoner.java │ │ │ │ └── GdlSentenceSet.java │ │ ├── reflection │ │ │ └── ProjectSearcher.java │ │ ├── statemachine │ │ │ ├── FailsafeStateMachine.java │ │ │ ├── MachineState.java │ │ │ ├── Move.java │ │ │ ├── Role.java │ │ │ ├── StateMachine.java │ │ │ ├── cache │ │ │ │ ├── CachedStateMachine.java │ │ │ │ └── TtlCache.java │ │ │ ├── exceptions │ │ │ │ ├── GoalDefinitionException.java │ │ │ │ ├── MoveDefinitionException.java │ │ │ │ └── TransitionDefinitionException.java │ │ │ ├── implementation │ │ │ │ ├── propnet │ │ │ │ │ └── SamplePropNetStateMachine.java │ │ │ │ └── prover │ │ │ │ │ ├── ProverStateMachine.java │ │ │ │ │ ├── query │ │ │ │ │ └── ProverQueryBuilder.java │ │ │ │ │ └── result │ │ │ │ │ └── ProverResultParser.java │ │ │ └── verifier │ │ │ │ └── StateMachineVerifier.java │ │ ├── symbol │ │ │ ├── factory │ │ │ │ ├── SymbolFactory.java │ │ │ │ └── exceptions │ │ │ │ │ └── SymbolFormatException.java │ │ │ └── grammar │ │ │ │ ├── Symbol.java │ │ │ │ ├── SymbolAtom.java │ │ │ │ ├── SymbolList.java │ │ │ │ └── SymbolPool.java │ │ └── ui │ │ │ ├── ChainingReplacedElementFactory.java │ │ │ ├── CloseableTabs.java │ │ │ ├── ConsolePanel.java │ │ │ ├── GameSelector.java │ │ │ ├── GameStateRenderer.java │ │ │ ├── JLabelBold.java │ │ │ ├── JLabelHyperlink.java │ │ │ ├── NativeUI.java │ │ │ ├── PlayerSelector.java │ │ │ ├── PublishButton.java │ │ │ ├── SVGReplacedElementFactory.java │ │ │ ├── table │ │ │ └── JZebraTable.java │ │ │ └── timer │ │ │ └── JTimerBar.java │ │ └── validator │ │ ├── BasesInputsValidator.java │ │ ├── GameValidator.java │ │ ├── OPNFValidator.java │ │ ├── SimulationValidator.java │ │ ├── StaticValidator.java │ │ ├── ValidatorException.java │ │ └── ValidatorWarning.java ├── resources │ ├── external │ │ ├── JythonConsole │ │ │ ├── __init__.py │ │ │ ├── console.py │ │ │ ├── history.py │ │ │ ├── introspect.py │ │ │ ├── jintrospect.py │ │ │ ├── popup.py │ │ │ └── tip.py │ │ └── __init__.py │ ├── org │ │ └── ggp │ │ │ └── base │ │ │ └── apps │ │ │ └── utilities │ │ │ └── SampleKeys.json │ ├── sample_gamer.clj │ ├── sample_gamer.py │ └── scripts.py └── scala │ └── org │ └── ggp │ └── base │ └── scala │ └── player │ └── gamer │ └── statemachine │ ├── SampleMonteCarloGamer.scala │ └── SampleRandomGamer.scala └── test └── java └── org └── ggp └── base ├── apps ├── logging │ └── LogSummarizerTest.java └── tiltyard │ └── TiltyardRequestFarmTest.java ├── player └── gamer │ ├── clojure │ └── ClojureGamerTest.java │ └── python │ └── PythonGamerTest.java ├── test ├── AllTests.java └── NoTabsInRulesheetsTest.java ├── util ├── crypto │ ├── BaseCryptographyTest.java │ ├── BaseHashingTest.java │ ├── CanonicalJSONTest.java │ └── SignableJSONTest.java ├── game │ └── GameParsingTest.java ├── gdl │ ├── model │ │ ├── DependencyGraphsTest.java │ │ └── SimpleSentenceFormTest.java │ ├── scrambler │ │ ├── GdlRendererTest.java │ │ └── GdlScramblerTest.java │ └── transforms │ │ └── GdlCleanerTest.java ├── http │ └── HttpTest.java ├── presence │ └── InfoResponseTest.java └── statemachine │ └── implementation │ └── prover │ └── ProverStateMachineTest.java └── validator └── StaticValidationTest.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /logs/ 3 | /ggp-base.jar 4 | /.gradle/ 5 | /build/ 6 | /out/ 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ggp-base 4 | 5 | 6 | 7 | org.eclipse.jdt.core.javanature 8 | org.scala-ide.sdt.core.scalanature 9 | 10 | 11 | 12 | org.eclipse.jdt.core.javabuilder 13 | 14 | 15 | 16 | org.scala-ide.sdt.core.scalabuilder 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | # 2 | #Sat Oct 18 20:29:45 PDT 2014 3 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 7 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 8 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 9 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 10 | eclipse.preferences.version=1 11 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | #Tue Mar 23 10:27:05 PDT 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 4 | -------------------------------------------------------------------------------- /cleanup.sh: -------------------------------------------------------------------------------- 1 | # This script is provided as a placeholder for a real cleanup script. 2 | # It is called by the Proxy between matches, and should clean up all 3 | # of the temporary files that the gamer might leave around, but that 4 | # don't need to be preserved between matches. 5 | # 6 | # If you are not using the Proxy, or your player does not generate 7 | # temporary files on disk, you can feel free to ignore this script. 8 | # Otherwise, it might be useful to override it with a version that 9 | # cleans up the temporary files. 10 | 11 | echo "Cleanup script called: no cleanup needed." -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /gameServerRunner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #This script allows the user to run the GameServerRunner app via Gradle. 3 | #Arguments: ./gameServerRunner etc. 4 | #Sample usage: ./gameServerRunner myTournament ticTacToe 60 15 127.0.0.1 9147 PlayerOne 127.0.0.1 9148 PlayerTwo 5 | #For a GUI-based server, try: ./gradlew server 6 | 7 | ./gradlew gameServerRunner -Pmyargs="$*" 8 | -------------------------------------------------------------------------------- /games/games/connectFour/METADATA: -------------------------------------------------------------------------------- 1 | { 2 | "gameName": "Connect Four", 3 | "rulesheet": "connectFour.kif", 4 | "stylesheet": "connectFour.xsl", 5 | "description": "connectFour.txt", 6 | "user_interface": "connectFour.js" 7 | } -------------------------------------------------------------------------------- /games/games/connectFour/connectFour.js: -------------------------------------------------------------------------------- 1 | // Game interface description. 2 | { 3 | [BOARD_INTERFACE_JS] 4 | 5 | // ============= GAME SPECIFIC ==================== 6 | 7 | getCellForMove: function(move) { 8 | return "cell_" + move[1] + "6"; 9 | }, 10 | 11 | getTargetsForMove: function(move) { 12 | return []; 13 | } 14 | } -------------------------------------------------------------------------------- /games/games/connectFour/connectFour.txt: -------------------------------------------------------------------------------- 1 | Two players (red and black) take turns. Each drops a disc of their color into the grid from 2 | the top. The first player to get four in a row (horizontally, vertically, or diagonally) wins. -------------------------------------------------------------------------------- /games/games/maze/METADATA: -------------------------------------------------------------------------------- 1 | { 2 | "gameName": "Maze", 3 | "rulesheet": "maze.kif", 4 | "stylesheet": "maze.xsl" 5 | } -------------------------------------------------------------------------------- /games/games/ticTacToe/METADATA: -------------------------------------------------------------------------------- 1 | { 2 | "gameName": "Tic-Tac-Toe", 3 | "rulesheet": "ticTacToe.kif", 4 | "stylesheet": "ticTacToe.xsl", 5 | "description": "ticTacToe.txt", 6 | "user_interface": "ticTacToe.js" 7 | } -------------------------------------------------------------------------------- /games/games/ticTacToe/ticTacToe.js: -------------------------------------------------------------------------------- 1 | // Game interface description. 2 | { 3 | [BOARD_INTERFACE_JS] 4 | 5 | // ============= GAME SPECIFIC ==================== 6 | 7 | getCellForMove: function(move) { 8 | return "cell_" + move[1] + move[2]; 9 | }, 10 | 11 | getTargetsForMove: function(move) { 12 | var targets = []; 13 | targets.push(document.getElementById("cell_" + move[3] + move[4])); 14 | 15 | return targets; 16 | } 17 | } -------------------------------------------------------------------------------- /games/games/ticTacToe/ticTacToe.txt: -------------------------------------------------------------------------------- 1 | The classic children's game. Two players take turns; each player makes their mark on one square 2 | of a 3x3 board each turn. Three marks in a row (horizontally, vertically, or diagonally) to win. -------------------------------------------------------------------------------- /games/resources/images/checkers/black_king.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/checkers/black_king.png -------------------------------------------------------------------------------- /games/resources/images/checkers/crown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/checkers/crown.png -------------------------------------------------------------------------------- /games/resources/images/checkers/red_king.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/checkers/red_king.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_Bishop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_Bishop.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_King.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_King.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_Knight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_Knight.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_Pawn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_Pawn.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_Queen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_Queen.png -------------------------------------------------------------------------------- /games/resources/images/chess/Black_Rook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/Black_Rook.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_Bishop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_Bishop.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_King.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_King.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_Knight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_Knight.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_Pawn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_Pawn.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_Queen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_Queen.png -------------------------------------------------------------------------------- /games/resources/images/chess/White_Rook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/chess/White_Rook.png -------------------------------------------------------------------------------- /games/resources/images/discs/black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/black.png -------------------------------------------------------------------------------- /games/resources/images/discs/blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/blue.png -------------------------------------------------------------------------------- /games/resources/images/discs/green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/green.png -------------------------------------------------------------------------------- /games/resources/images/discs/grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/grey.png -------------------------------------------------------------------------------- /games/resources/images/discs/orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/orange.png -------------------------------------------------------------------------------- /games/resources/images/discs/purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/purple.png -------------------------------------------------------------------------------- /games/resources/images/discs/red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/red.png -------------------------------------------------------------------------------- /games/resources/images/discs/teal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/teal.png -------------------------------------------------------------------------------- /games/resources/images/discs/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/white.png -------------------------------------------------------------------------------- /games/resources/images/discs/yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/discs/yellow.png -------------------------------------------------------------------------------- /games/resources/images/pentago/BlueCircleArrowCCW.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/pentago/BlueCircleArrowCCW.png -------------------------------------------------------------------------------- /games/resources/images/pentago/BlueCircleArrowCW.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/games/resources/images/pentago/BlueCircleArrowCW.png -------------------------------------------------------------------------------- /games/test/simpleMutex.kif: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; Simple Mutex Game 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | 5 | (role robot) 6 | 7 | (init h1) 8 | (init t1) 9 | 10 | (<= (legal robot a) (true h1) likely) 11 | (<= (legal robot a) (true h5) likely) 12 | (<= (legal robot a) (true h6) likely) 13 | (<= (legal robot b) (true h1) likely) 14 | (<= (legal robot b) (true h5) likely) 15 | (<= (legal robot b) (true h7) likely) 16 | (<= (legal robot c) (true h1) likely) 17 | (<= (legal robot d) (true h2) likely) 18 | (<= (legal robot d) (true h4) likely) 19 | 20 | (<= (next h2) (does robot a) (true h1) likely) 21 | (<= (next h3) (does robot b) (true h1) likely) 22 | (<= (next h4) (does robot c) (true h1) likely) 23 | (<= (next h5) (does robot d) (true h2) likely) 24 | (<= (next h5) (does robot d) (true h4) likely) 25 | (<= (next h6) (does robot a) (true h5) likely) 26 | (<= (next h7) (does robot b) (true h5) likely) 27 | (<= (next h8) (does robot a) (true h6) likely) 28 | (<= (next h8) (does robot b) (true h7) likely) 29 | 30 | (<= (next m1) (true h1)) 31 | (<= (next m2) (not (true h1))) 32 | 33 | (<= (next m3) (true h2)) 34 | (<= (next m4) (not (true h2))) 35 | 36 | (<= (next m5) (true h4)) 37 | (<= (next m6) (not (true h4))) 38 | 39 | (<= (next t2) (true t1)) 40 | (<= (next t1) (true t2)) 41 | 42 | (<= unlikely (true t1) (true t2)) 43 | (<= unlikely (true m1) (true m2)) 44 | (<= unlikely (true m3) (true m4)) 45 | (<= unlikely (true m5) (true m6)) 46 | (<= likely (not unlikely)) 47 | 48 | (<= (goal robot 100) (true h3)) 49 | (<= (goal robot 0) (not (true h3))) 50 | 51 | (<= terminal (true h3) likely) 52 | (<= terminal (true h8) likely) -------------------------------------------------------------------------------- /games/test/test_case_1a.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; Specifically, it tests a time-invariant goal rule. 3 | 4 | (role you) 5 | (init (state 0)) 6 | 7 | (<= (legal you proceed) 8 | (true (state 0))) 9 | 10 | (<= (next (state 1)) 11 | (does you proceed)) 12 | 13 | (<= terminal 14 | (true (state 1))) 15 | 16 | (<= (goal you 100)) -------------------------------------------------------------------------------- /games/test/test_case_1b.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; Specifically, it tests a time-invariant goal rule and uses legal in a proposition definition. 3 | 4 | (role you) 5 | 6 | (init (state 0)) 7 | 8 | (<= (legal you win) 9 | (true (state 0))) 10 | 11 | (<= (legal you lose) 12 | (true (state 0))) 13 | 14 | (<= (next (state 1)) 15 | (does you win)) 16 | 17 | (<= (next (state 2)) 18 | (does you lose)) 19 | 20 | (<= anylegalmoves 21 | (legal you ?x)) 22 | 23 | (<= terminal 24 | (true (state 1))) 25 | (<= terminal 26 | (not anylegalmoves)) 27 | 28 | (<= (goal you 100) 29 | (true (state 1))) 30 | (<= (goal you 0) 31 | (not (true (state 1))) 32 | (not anylegalmoves)) -------------------------------------------------------------------------------- /games/test/test_case_2a.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; Specifically, it tests proper handling of time-invariant true sentences 3 | ;; which are derived rather than outright stated. 4 | 5 | (role you) 6 | (init (state 0)) 7 | 8 | (valid_state 0) 9 | (valid_state 1) 10 | (valid_state 2) 11 | (valid_state 3) 12 | (valid_state 4) 13 | 14 | (succ 0 1) 15 | (succ 1 2) 16 | (succ 2 3) 17 | (succ 3 4) 18 | 19 | (<= (next_state ?x ?xn move_next) 20 | (valid_state ?x) 21 | (succ ?x ?xn)) 22 | 23 | (<= (legal you (move ?dir ?from ?to)) 24 | (true (state ?from)) 25 | (next_state ?from ?to ?dir)) 26 | 27 | (<= (next (state ?to)) 28 | (does you (move ?dir ?from ?to))) 29 | 30 | (<= terminal 31 | (true (state 4))) 32 | 33 | (goal you 100) -------------------------------------------------------------------------------- /games/test/test_case_2b.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | 3 | (role snake) 4 | 5 | (init (cell c1 b)) 6 | (init (cell c2 b)) 7 | (init (cell c3 b)) 8 | (init (cell c4 wall)) 9 | (init (cell c5 b)) 10 | (init (cell c6 b)) 11 | (init (cell c7 b)) 12 | (init (cell c8 b)) 13 | (init (cell c9 b)) 14 | 15 | (init (step 0)) 16 | (init (pos c6)) 17 | (init (tailpos c6)) 18 | 19 | (<= (nextcell ?x1 mov_left ?x2) 20 | (colinc ?x2 ?x1)) 21 | (<= (nextcell ?x1 mov_right ?x2) 22 | (colinc ?x1 ?x2)) 23 | 24 | (colinc c1 c2) (colinc c2 c3) (colinc c3 c4) (colinc c4 c5) (colinc c5 c6) (colinc c6 c7) (colinc c7 c8) (colinc c8 c9) (colinc c9 c1) 25 | 26 | ;; ------------ 27 | 28 | (<= (legal snake ?move) 29 | (true (pos ?x)) 30 | (nextcell ?x ?move ?xn) 31 | (maymove ?xn)) 32 | 33 | (<= (maymove ?x) 34 | (true (cell ?x b))) 35 | 36 | (<= (next (pos ?xn)) 37 | (does snake ?move) 38 | (true (pos ?x)) 39 | (nextcell ?x ?move ?xn)) 40 | 41 | (<= (next evenmove) 42 | (not (true evenmove))) 43 | 44 | (<= (next (cell ?x b)) 45 | (true evenmove) 46 | (true (tailpos ?x))) 47 | ;; (not (true (pos ?x))) 48 | 49 | (<= (next (cell ?x ?sym)) 50 | (true (cell ?x ?sym)) 51 | (not (true (pos ?x))) 52 | (not (true (tailpos ?x)))) 53 | 54 | (<= (next (cell ?x ?sym)) 55 | (true (cell ?x ?sym)) 56 | (not (true (pos ?x))) 57 | (not (true evenmove))) 58 | 59 | (<= (next (cell ?x ?move)) 60 | (does snake ?move) 61 | (true (pos ?x))) 62 | 63 | ;; ----------------- 64 | 65 | (<= (goal snake 0) 66 | (not (true (step 6)))) 67 | 68 | (<= (goal snake 100) 69 | (true (step 6))) 70 | 71 | (<= terminal 72 | (true (step 6))) 73 | 74 | (<= terminal 75 | (not exists_legal)) 76 | 77 | (<= exists_legal 78 | (legal snake ?move)) 79 | 80 | ;; ----------------- 81 | 82 | (<= (next (step ?y)) 83 | (true (step ?x)) 84 | (succ ?x ?y)) 85 | 86 | (succ 0 1) 87 | (succ 1 2) 88 | (succ 2 3) 89 | (succ 3 4) 90 | (succ 4 5) 91 | (succ 5 6) -------------------------------------------------------------------------------- /games/test/test_case_3a.kif: -------------------------------------------------------------------------------- 1 | ; Not actually clear this is a good test case; 2 | ; standard prover does "correct_failure", even 3 | ; though it seems like both should be correct. 4 | ; -Sam 5 | 6 | (role xplayer) 7 | 8 | (init (cell 1 1 b)) 9 | 10 | (<= open1 11 | (true (cell ?x ?y b))) 12 | (<= (open2) 13 | (true (cell ?x ?y b))) 14 | 15 | (<= (legal xplayer (move correct_correct)) 16 | open1 17 | open2) 18 | 19 | (<= (legal xplayer (move correct_failure)) 20 | open1 21 | (not open2)) 22 | 23 | (<= (legal xplayer (move failure_correct)) 24 | (not open1) 25 | open2) 26 | 27 | (<= (legal xplayer (move failure_failure)) 28 | (not open1) 29 | (not open2)) 30 | 31 | (<= (next ?x) 32 | (does xplayer (move ?x))) 33 | 34 | (<= (goal xplayer 100) 35 | (true correct_correct)) 36 | 37 | (<= (goal xplayer 75) 38 | (true correct_failure)) 39 | 40 | (<= (goal xplayer 50) 41 | (true failure_correct)) 42 | 43 | (<= (goal xplayer 25) 44 | (true failure_failure)) 45 | 46 | (<= terminal 47 | (not (true (cell 1 1 b)))) -------------------------------------------------------------------------------- /games/test/test_case_3b.kif: -------------------------------------------------------------------------------- 1 | ; This test case verifies that a state machine can handle 2 | ; the kind of distinct-based definitions that appear in 3 | ; the ticTacToeClassic game. These definitions are very 4 | ; broad and may be hard to handle in a bottom-up solver. 5 | 6 | (role xplayer) 7 | 8 | (cell 1 1) 9 | (<= terminal (cell 1 1)) 10 | (<= (legal xplayer noop) (cell 1 1)) 11 | (<= (goal xplayer 100) (cell 1 1)) 12 | 13 | (<= (distinctCell ?x ?y ?m ?n) (distinct ?y ?n)) 14 | (<= (distinctCell ?x ?y ?m ?n) (distinct ?x ?m)) -------------------------------------------------------------------------------- /games/test/test_case_3c.kif: -------------------------------------------------------------------------------- 1 | ; This test case ensures that a state machine behaves 2 | ; properly when presented with a proposition that isn't 3 | ; defined anywhere (i.e. "squee"). 4 | 5 | (role xplayer) 6 | 7 | (<= (legal xplayer lose) squee) 8 | (<= (legal xplayer win) (not squee)) 9 | 10 | (<= (next winner) (does xplayer win)) 11 | (<= (next loser) (does xplayer lose)) 12 | 13 | (<= (goal xplayer 100) (true winner)) 14 | (<= (goal xplayer 0) (true loser)) 15 | (<= terminal (or (true winner) (true loser))) -------------------------------------------------------------------------------- /games/test/test_case_3d.kif: -------------------------------------------------------------------------------- 1 | ; This test case ensures that a state machine can 2 | ; compute the initial state of a game correctly. 3 | 4 | (role xplayer) 5 | 6 | (init (cell alpha)) 7 | 8 | (<= (next (cell beta)) 9 | (not (true (cell alpha)))) 10 | 11 | (<= (legal xplayer lose) (true (cell beta))) 12 | (<= (legal xplayer win) (not (true (cell beta)))) 13 | 14 | (<= (next winner) (does xplayer win)) 15 | (<= (next loser) (does xplayer lose)) 16 | 17 | (<= (goal xplayer 100) (true winner)) 18 | (<= (goal xplayer 0) (true loser)) 19 | (<= terminal (or (true winner) (true loser))) -------------------------------------------------------------------------------- /games/test/test_case_3e.kif: -------------------------------------------------------------------------------- 1 | ; This test case ensures that a state machine can handle 2 | ; role variables in the "legal" and "goal" rules. 3 | 4 | (role xplayer) 5 | 6 | (cell 1 1) 7 | (<= terminal (cell 1 1)) 8 | (<= (legal ?p ?p) (cell 1 1)) 9 | (<= (goal ?p 100) (cell 1 1)) -------------------------------------------------------------------------------- /games/test/test_case_3f.kif: -------------------------------------------------------------------------------- 1 | ; This test case ensures that a state machine can handle 2 | ; role variables in the "legal" and "goal" rules, along 3 | ; with a restricted set of roles to which those apply. 4 | 5 | (role xplayer) 6 | (role yplayer) 7 | (role zplayer) 8 | 9 | (cell 1 1) 10 | (<= terminal (cell 1 1)) 11 | (<= (legal ?p ?p) (cell 1 1)) 12 | (<= (goal ?p 100) (on_list ?p)) 13 | (<= (goal ?p 0) (not (on_list ?p))) 14 | 15 | (on_list xplayer) 16 | (on_list zplayer) -------------------------------------------------------------------------------- /games/test/test_case_4a.kif: -------------------------------------------------------------------------------- 1 | ; This test case ensures that a gamer can handle 2 | ; "base" and "input" propositions. 3 | 4 | ( role robot ) 5 | ( base p ) 6 | ( base q ) 7 | ( input robot a ) 8 | ( init p ) 9 | ( legal robot a ) 10 | ( <= ( next q ) ( true p ) ) 11 | ( <= terminal ( true q ) ) 12 | ( goal robot 100 ) -------------------------------------------------------------------------------- /games/test/test_case_5a.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; This test case ensures that a player can handle complex 3 | ;; (yet legal) recursion. 4 | 5 | (role you) 6 | (init (state 0)) 7 | 8 | (r 0 0) 9 | (q 0) 10 | 11 | (<= (r ?v1 (f ?v1)) 12 | (r ?v2 ?v1) 13 | (q ?v2)) 14 | 15 | (<= (legal you proceed) 16 | (true (state 0)) 17 | (r (f 0) (f (f 0)))) 18 | 19 | (<= (next (state 1)) 20 | (does you proceed)) 21 | 22 | (<= terminal 23 | (true (state 1))) 24 | 25 | (goal you 100) -------------------------------------------------------------------------------- /games/test/test_case_5b.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; This test case ensures that a player (or state machine) 3 | ;; can handle certain patterns of doubled-up variables. 4 | ;; (This is a regression test for the ProverStateMachine.) 5 | 6 | (role you) 7 | (goal you 100) 8 | (next done) 9 | (<= terminal 10 | (true done)) 11 | (legal you (draw 1 1 1 2)) 12 | 13 | (<= (next (line ?x1 ?y1 ?x2 ?y2)) 14 | (does ?player (draw ?x1 ?y1 ?x2 ?y2))) 15 | 16 | (<= (h_drawn ?x1 ?y ?x2 ?y) 17 | (does ?player (draw ?x1 ?y ?x2 ?y))) 18 | (<= (next (box ?x1 ?y1)) 19 | (h_drawn ?x1 ?y1 ?x2 ?y1)) 20 | -------------------------------------------------------------------------------- /games/test/test_case_5c.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; This test case ensures that a player can handle complex 3 | ;; (yet legal) recursion. This is a regression test for the 4 | ;; ProverStateMachine. 5 | 6 | (role you) 7 | (init (state 0)) 8 | 9 | (r 0) 10 | (q 0) 11 | (q 1) 12 | 13 | (<= (r ?x) 14 | (r ?x) 15 | (q ?x)) 16 | 17 | (<= (p left) 18 | (p up)) 19 | (<= (p up) 20 | (p right)) 21 | (<= (p right) 22 | (p down)) 23 | (<= (p down) 24 | (p left)) 25 | 26 | 27 | (<= (legal you proceed) 28 | (true (state 0)) 29 | (r 0) 30 | (not (r 1)) 31 | (not (p left))) 32 | 33 | (<= (next (state 1)) 34 | (does you proceed)) 35 | 36 | (<= terminal 37 | (true (state 1))) 38 | 39 | (goal you 100) -------------------------------------------------------------------------------- /games/test/test_case_5d.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; This test case ensures that a player can handle complex 3 | ;; (yet legal) recursion. This is a regression test for the 4 | ;; ProverStateMachine. 5 | 6 | (role you) 7 | (<= (r ?x ?y) 8 | (s ?x ?y)) 9 | (<= (s ?x ?y) 10 | (r ?y ?x)) 11 | 12 | (r 1 2) 13 | 14 | (<= (init (rTrue ?x ?y)) (r ?x ?y)) 15 | (<= (init (sTrue ?x ?y)) (s ?x ?y)) 16 | 17 | (<= (legal you proceed) (true (sTrue 1 2))) 18 | 19 | (<= (next (state 1)) 20 | (does you proceed)) 21 | 22 | (<= terminal 23 | (true (state 1))) 24 | 25 | (<= (goal you 100)) -------------------------------------------------------------------------------- /games/test/test_case_5e.kif: -------------------------------------------------------------------------------- 1 | ;; This tests an edge case when handling GDL. 2 | ;; This test case ensures that a player can handle complex 3 | ;; (yet legal) recursion. This is a regression test for the 4 | ;; ProverStateMachine. 5 | 6 | ; The robot role should have seven legal moves. 7 | 8 | (role robot) 9 | 10 | (<= (legal robot (reduce ?x ?n)) 11 | (heap ?x ?m) 12 | (smaller ?n ?m)) 13 | 14 | (heap a 2) 15 | (heap b 0) 16 | (heap c 5) 17 | 18 | (<= (smaller ?x ?y) 19 | (succ ?x ?y)) 20 | (<= (smaller ?x ?y) 21 | (smaller ?z ?y) ; This is the part being tested 22 | (succ ?x ?z)) 23 | (succ 0 1) 24 | (succ 1 2) 25 | (succ 2 3) 26 | (succ 3 4) 27 | (succ 4 5) 28 | 29 | (next done) 30 | (<= terminal 31 | (true done)) 32 | (goal robot 100) 33 | -------------------------------------------------------------------------------- /games/test/test_clean_not_distinct.kif: -------------------------------------------------------------------------------- 1 | ; Test that the GdlCleaner can properly handle (not (distinct X Y)) 2 | 3 | (role player) 4 | 5 | (domain 1) 6 | (domain 2) 7 | (domain 3) 8 | 9 | (c 2) 10 | 11 | (<= a 12 | (not (distinct p p))) 13 | (<= (b ?x) 14 | (c ?y) 15 | (domain ?x) 16 | (not (distinct ?x ?y))) 17 | (<= (d 3) 18 | (c ?y) 19 | (not (distinct 3 ?y))) 20 | (<= (d 3) 21 | (c ?y) 22 | (not (distinct ?y 3))) 23 | (<= (e 3) 24 | (c ?y) 25 | (not (distinct 2 ?y))) 26 | (<= (f 3) 27 | (c ?y) 28 | (not (distinct ?y 2))) 29 | 30 | (<= z 31 | (not (distinct p q))) 32 | 33 | (<= success 34 | a 35 | (not (b 1)) 36 | (b 2) 37 | (not (d 3)) 38 | (e 3) 39 | (f 3) 40 | (not z)) 41 | (<= (goal player 100) 42 | success) 43 | (<= (goal player 0) 44 | (not success)) 45 | 46 | (legal player proceed) 47 | (<= (next done) 48 | (does player proceed)) 49 | (<= terminal 50 | (true done)) 51 | -------------------------------------------------------------------------------- /games/test/test_distinct_beginning_rule.kif: -------------------------------------------------------------------------------- 1 | ; This tests the appearance of distinct at the beginning of a rule. 2 | ; There should be 2 legal moves, not 4. 3 | (role you) 4 | 5 | (<= (foo ?a ?b) 6 | (distinct ?a ?b) 7 | (p ?a) 8 | (q ?b)) 9 | 10 | (p a) 11 | (p b) 12 | (q a) 13 | (q b) 14 | 15 | (<= (legal you (do ?a ?b)) 16 | (foo ?a ?b)) 17 | 18 | (next win) 19 | (<= terminal 20 | (true win)) 21 | (goal you 100) 22 | -------------------------------------------------------------------------------- /games/test/test_invalid_function_arities_differ.kif: -------------------------------------------------------------------------------- 1 | ; A sample .kif file with invalid GDL. 2 | ; The sentence arities differ, so the game is invalid 3 | ; according to the GDL specification. 4 | 5 | ( role robot ) 6 | ( init p ) 7 | ( legal robot (a 1) ) 8 | ( legal robot (a 2 3) ) 9 | ( <= ( next q ) ( true p ) ) 10 | ( <= terminal ( true q ) ) 11 | ( goal robot 100 ) 12 | -------------------------------------------------------------------------------- /games/test/test_invalid_sentence_arities_differ.kif: -------------------------------------------------------------------------------- 1 | ; A sample .kif file with invalid GDL. 2 | ; The sentence arities differ, so the game is invalid 3 | ; according to the GDL specification. 4 | 5 | ( role robot ) 6 | ( init p ) 7 | ( legal robot a ) 8 | ( <= ( next q ) ( true p ) ) 9 | ( <= terminal ( true q ) ) 10 | ( goal robot 100 ) 11 | 12 | ( foo bar ) 13 | ( foo bar bar ) 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 16 23:35:14 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip 7 | -------------------------------------------------------------------------------- /lib/Batik/batik-1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Batik/batik-1.7.jar -------------------------------------------------------------------------------- /lib/Batik/xml-apis-ext.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Batik/xml-apis-ext.jar -------------------------------------------------------------------------------- /lib/Clojure/clojure.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Clojure/clojure.jar -------------------------------------------------------------------------------- /lib/FlyingSaucer/core-renderer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/FlyingSaucer/core-renderer.jar -------------------------------------------------------------------------------- /lib/Guava/guava-14.0.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Guava/guava-14.0.1-sources.jar -------------------------------------------------------------------------------- /lib/Guava/guava-14.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Guava/guava-14.0.1.jar -------------------------------------------------------------------------------- /lib/Htmlparser/htmlparser-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Htmlparser/htmlparser-1.4.jar -------------------------------------------------------------------------------- /lib/JFreeChart/jcommon-1.0.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/JFreeChart/jcommon-1.0.17.jar -------------------------------------------------------------------------------- /lib/JFreeChart/jfreechart-1.0.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/JFreeChart/jfreechart-1.0.14.jar -------------------------------------------------------------------------------- /lib/JGoodiesForms/forms-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/JGoodiesForms/forms-1.2.1.jar -------------------------------------------------------------------------------- /lib/JUnit/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/JUnit/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/JUnit/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/JUnit/junit-4.11.jar -------------------------------------------------------------------------------- /lib/Jython/jython.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/Jython/jython.jar -------------------------------------------------------------------------------- /lib/gdl-validation/gdl-validation-0.2.2-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/gdl-validation/gdl-validation-0.2.2-sources.jar -------------------------------------------------------------------------------- /lib/gdl-validation/gdl-validation-0.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/gdl-validation/gdl-validation-0.2.2.jar -------------------------------------------------------------------------------- /lib/gdl-validation/java-cup-11b-runtime-2015.03.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/gdl-validation/java-cup-11b-runtime-2015.03.26.jar -------------------------------------------------------------------------------- /lib/javassist/javassist.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/javassist/javassist.jar -------------------------------------------------------------------------------- /lib/reflections/reflections-0.9.9-RC1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/lib/reflections/reflections-0.9.9-RC1.jar -------------------------------------------------------------------------------- /licences/FlyingSaucer/LICENSE-W3C-TEST: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/licences/FlyingSaucer/LICENSE-W3C-TEST -------------------------------------------------------------------------------- /licences/JSON/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002 JSON.org 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | The Software shall be used for Good, not Evil. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /licences/Jython/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggp-org/ggp-base/44db132b5f1aa8467b1b990914e2e3c64ecbd87b/licences/Jython/LICENSE -------------------------------------------------------------------------------- /licences/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Sam Schreiber. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the TurboTurtle GGP Project nor the names of its 15 | contributors may be used to endorse or promote products derived from this 16 | software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /playerRunner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #This script is a slightly nicer way to run the PlayerRunner app than via Gradle. 3 | #Sample usage: ./playerRunner.sh 9147 RandomGamer 4 | #For a GUI-based player runner, try: ./gradlew player 5 | 6 | #To change the JVM arguments for a player run from this script (including the 7 | #maximum heap size), modify the playerJvmArgs list in build.gradle. 8 | 9 | ./gradlew playerRunner -Pport=$1 -Pgamer=$2 10 | -------------------------------------------------------------------------------- /src/main/java/external/JSON/JSONException.java: -------------------------------------------------------------------------------- 1 | package external.JSON; 2 | 3 | /** 4 | * The JSONException is thrown by the JSON.org classes when things are amiss. 5 | * @author JSON.org 6 | * @version 2010-12-24 7 | */ 8 | public class JSONException extends Exception { 9 | private static final long serialVersionUID = 0; 10 | private Throwable cause; 11 | 12 | /** 13 | * Constructs a JSONException with an explanatory message. 14 | * @param message Detail about the reason for the exception. 15 | */ 16 | public JSONException(String message) { 17 | super(message); 18 | } 19 | 20 | public JSONException(Throwable cause) { 21 | super(cause.getMessage()); 22 | this.cause = cause; 23 | } 24 | 25 | @Override 26 | public Throwable getCause() { 27 | return this.cause; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/external/JSON/JSONString.java: -------------------------------------------------------------------------------- 1 | package external.JSON; 2 | /** 3 | * The JSONString interface allows a toJSONString() 4 | * method so that a class can change the behavior of 5 | * JSONObject.toString(), JSONArray.toString(), 6 | * and JSONWriter.value(Object). The 7 | * toJSONString method will be used instead of the default behavior 8 | * of using the Object's toString() method and quoting the result. 9 | */ 10 | public interface JSONString { 11 | /** 12 | * The toJSONString method allows a class to produce its own JSON 13 | * serialization. 14 | * 15 | * @return A strictly syntactically correct JSON text. 16 | */ 17 | public String toJSONString(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/consoles/ClojureConsole.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.consoles; 2 | 3 | import clojure.lang.RT; 4 | import clojure.lang.Symbol; 5 | import clojure.lang.Var; 6 | 7 | /** 8 | * ClojureConsole is a Clojure-based app that lets you interact with a Clojure 9 | * console that has full access to all of the Java classes in the project. 10 | * This allows you to quickly experiment with the classes, without having to 11 | * write a full-blown Java program. 12 | * 13 | * TODO: This could use some helper scripts, to allow it to quickly load game 14 | * rulesheets and so on. Right now you have to manually load everything 15 | * when you want to create a state machine that's initialized to a game, 16 | * which is pretty bothersome. 17 | * 18 | * @author Sam 19 | */ 20 | public class ClojureConsole { 21 | public static void main(String[] args) { 22 | Symbol CLOJURE_MAIN = Symbol.intern("clojure.main"); 23 | Var REQUIRE = RT.var("clojure.core", "require"); 24 | Var MAIN = RT.var("clojure.main", "main"); 25 | try { 26 | REQUIRE.invoke(CLOJURE_MAIN); 27 | MAIN.applyTo(RT.seq(new String[]{})); 28 | } catch(Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/consoles/PythonConsole.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.consoles; 2 | 3 | import org.python.util.PythonInterpreter; 4 | 5 | /** 6 | * PythonConsole is a Jython-based app that lets you interact with a Python 7 | * console that has full access to all of the Java classes in the project. 8 | * This allows you to quickly experiment with the classes, without having to 9 | * write a full-blown Java program. There are also helpful scripts so that 10 | * you can get started quickly. 11 | * 12 | * For example, try out: 13 | * 14 | * {@code >> display_random_walk(load_game('ticTacToe'))} 15 | * 16 | * This will load the game Tic-Tac-Toe and play through it randomly. 17 | * 18 | * This uses the JythonConsole implementation of a console with all of the 19 | * nice features like history, tab completion, et cetera. JythonConsole is an 20 | * external open source project, accessible at: 21 | * 22 | * http://code.google.com/p/jythonconsole/ 23 | * 24 | * The license for JythonConsole is available in the licenses/ directory. 25 | * 26 | * @author Sam 27 | */ 28 | public class PythonConsole { 29 | public static void main(String[] args) { 30 | PythonInterpreter interpreter = new PythonInterpreter(); 31 | interpreter.exec("from scripts import *"); 32 | interpreter.exec("import external.JythonConsole.console"); 33 | interpreter.exec("external.JythonConsole.console.main(locals())"); 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/MoveSelectedEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | import org.ggp.base.util.statemachine.Move; 5 | 6 | public class MoveSelectedEvent extends Event { 7 | private Move theMove; 8 | private boolean isFinal = false; 9 | 10 | public MoveSelectedEvent(Move m) { 11 | theMove = m; 12 | } 13 | 14 | public MoveSelectedEvent(Move m, boolean isFinal) { 15 | theMove = m; 16 | this.isFinal = isFinal; 17 | } 18 | 19 | public Move getMove() { 20 | return theMove; 21 | } 22 | 23 | public boolean isFinal() { 24 | return isFinal; 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/BreakthroughCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_Chessboard; 9 | 10 | 11 | public class BreakthroughCanvas extends GameCanvas_Chessboard { 12 | private static final long serialVersionUID = 1L; 13 | 14 | @Override 15 | public String getGameName() { return "Breakthrough"; } 16 | @Override 17 | protected String getGameKey() { return "breakthrough"; } 18 | 19 | @Override 20 | protected Set getFactsAboutCell(int xCell, int yCell) { 21 | return gameStateHasFactsMatching("\\( cellHolds " + xCell + " " + yCell + " (.*) \\)"); 22 | } 23 | 24 | @Override 25 | protected Set getLegalMovesForCell(int xCell, int yCell) { 26 | return gameStateHasLegalMovesMatching("\\( move " + xCell + " " + yCell + " (.*) \\)"); 27 | } 28 | 29 | 30 | @Override 31 | protected void renderCellContent(Graphics g, String theFact) { 32 | String[] cellFacts = theFact.split(" "); 33 | String cellType = cellFacts[4]; 34 | if(cellType.equals("b")) return; 35 | 36 | CommonGraphics.drawChessPiece(g, cellType.charAt(0) + "p"); 37 | } 38 | 39 | @Override 40 | protected void renderMoveSelectionForCell(Graphics g, int xCell, int yCell, String theMove) { 41 | int width = g.getClipBounds().width; 42 | int height = g.getClipBounds().height; 43 | 44 | String[] moveParts = theMove.split(" "); 45 | int xTarget = Integer.parseInt(moveParts[4]); 46 | int yTarget = Integer.parseInt(moveParts[5]); 47 | if(xCell == xTarget && yCell == yTarget) { 48 | g.setColor(new Color(0, 0, 255, 192)); 49 | g.drawRect(3, 3, width-6, height-6); 50 | CommonGraphics.fillWithString(g, "X", 3); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/ChickenTicTacToeCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_FancyGrid; 9 | 10 | 11 | // NOTE: I still don't fully understand how this game actually works. -Sam 12 | public class ChickenTicTacToeCanvas extends GameCanvas_FancyGrid { 13 | public static final long serialVersionUID = 0x1; 14 | 15 | @Override 16 | public String getGameName() { return "Tic-Tac-Toe (Chicken)"; } 17 | @Override 18 | protected String getGameKey() { return "chickentictactoe"; } 19 | @Override 20 | protected int getGridHeight() { return 3; } 21 | @Override 22 | protected int getGridWidth() { return 3; } 23 | 24 | @Override 25 | protected Set getFactsAboutCell(int xCell, int yCell) { 26 | return gameStateHasFactsMatching("\\( cell " + xCell + " " + yCell + " (.*) \\)"); 27 | } 28 | 29 | @Override 30 | protected Set getLegalMovesForCell(int xCell, int yCell) { 31 | return gameStateHasLegalMovesMatching("\\( mark " + xCell + " " + yCell + " \\)"); 32 | } 33 | 34 | @Override 35 | protected void renderCellContent(Graphics g, String theFact) { 36 | String[] cellFacts = theFact.split(" "); 37 | 38 | if(!cellFacts[4].equals("b")) { 39 | g.setColor(Color.BLACK); 40 | CommonGraphics.fillWithString(g, cellFacts[4], 1.2); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/ConnectFiveCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_Chessboard; 9 | 10 | 11 | public class ConnectFiveCanvas extends GameCanvas_Chessboard { 12 | public static final long serialVersionUID = 0x1; 13 | 14 | @Override 15 | public String getGameName() { return "Connect Five"; } 16 | @Override 17 | protected String getGameKey() { return "connect5"; } 18 | 19 | @Override 20 | protected Set getFactsAboutCell(int xCell, int yCell) { 21 | String xLetter = coordinateToLetter(xCell); 22 | String yLetter = coordinateToLetter(yCell); 23 | return gameStateHasFactsMatching("\\( cell " + xLetter + " " + yLetter + " (.*) \\)"); 24 | } 25 | 26 | @Override 27 | protected Set getLegalMovesForCell(int xCell, int yCell) { 28 | String xLetter = coordinateToLetter(xCell); 29 | String yLetter = coordinateToLetter(yCell); 30 | return gameStateHasLegalMovesMatching("\\( mark " + xLetter + " " + yLetter + " \\)"); 31 | } 32 | 33 | @Override 34 | protected void renderCellContent(Graphics g, String theFact) { 35 | String[] cellFacts = theFact.split(" "); 36 | if(cellFacts[4].equals("b")) return; 37 | 38 | g.setColor(Color.BLACK); 39 | CommonGraphics.fillWithString(g, cellFacts[4].toUpperCase(), 1.2); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/KnightthroughCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_Chessboard; 9 | 10 | 11 | public class KnightthroughCanvas extends GameCanvas_Chessboard { 12 | private static final long serialVersionUID = 1L; 13 | 14 | @Override 15 | public String getGameName() { return "Knightthrough"; } 16 | @Override 17 | protected String getGameKey() { return "knightthrough"; } 18 | 19 | @Override 20 | protected Set getFactsAboutCell(int xCell, int yCell) { 21 | return gameStateHasFactsMatching("\\( cell " + xCell + " " + yCell + " (.*) \\)"); 22 | } 23 | 24 | @Override 25 | protected Set getLegalMovesForCell(int xCell, int yCell) { 26 | return gameStateHasLegalMovesMatching("\\( move " + xCell + " " + yCell + " (.*) \\)"); 27 | } 28 | 29 | 30 | @Override 31 | protected void renderCellContent(Graphics g, String theFact) { 32 | String[] cellFacts = theFact.split(" "); 33 | String cellType = cellFacts[4]; 34 | if(cellType.equals("b")) return; 35 | 36 | CommonGraphics.drawChessPiece(g, cellType.charAt(0) + "n"); 37 | } 38 | 39 | @Override 40 | protected void renderMoveSelectionForCell(Graphics g, int xCell, int yCell, String theMove) { 41 | int width = g.getClipBounds().width; 42 | int height = g.getClipBounds().height; 43 | 44 | String[] moveParts = theMove.split(" "); 45 | int xTarget = Integer.parseInt(moveParts[4]); 46 | int yTarget = Integer.parseInt(moveParts[5]); 47 | if(xCell == xTarget && yCell == yTarget) { 48 | g.setColor(new Color(0, 0, 255, 192)); 49 | g.drawRect(3, 3, width-6, height-6); 50 | CommonGraphics.fillWithString(g, "X", 3); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/NumberTicTacToeCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_FancyGrid; 9 | 10 | 11 | public class NumberTicTacToeCanvas extends GameCanvas_FancyGrid { 12 | public static final long serialVersionUID = 0x1; 13 | 14 | @Override 15 | public String getGameName() { return "Tic-Tac-Toe (Numeric)"; } 16 | @Override 17 | protected String getGameKey() { return "numbertictactoe"; } 18 | @Override 19 | protected int getGridHeight() { return 3; } 20 | @Override 21 | protected int getGridWidth() { return 3; } 22 | 23 | @Override 24 | protected Set getFactsAboutCell(int xCell, int yCell) { 25 | return gameStateHasFactsMatching("\\( cell " + xCell + " " + yCell + " (.*) \\)"); 26 | } 27 | 28 | @Override 29 | protected Set getLegalMovesForCell(int xCell, int yCell) { 30 | return gameStateHasLegalMovesMatching("\\( mark " + xCell + " " + yCell + " (.*) \\)"); 31 | } 32 | 33 | @Override 34 | protected void renderCellContent(Graphics g, String theFact) { 35 | String[] cellFacts = theFact.split(" "); 36 | 37 | if(!cellFacts[4].equals("b")) { 38 | g.setColor(Color.BLACK); 39 | CommonGraphics.fillWithString(g, cellFacts[4], 1.2); 40 | } 41 | } 42 | 43 | @Override 44 | protected void renderMoveSelectionForCell(Graphics g, int xCell, int yCell, String theMove) { 45 | if(!isSelectedCell(xCell, yCell)) return; 46 | 47 | g.setColor(Color.GREEN); 48 | String[] moveFacts = theMove.split(" "); 49 | CommonGraphics.fillWithString(g, "" + moveFacts[4], 1.2); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/games/TicTacToeCanvas.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.games; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.apps.kiosk.templates.CommonGraphics; 8 | import org.ggp.base.apps.kiosk.templates.GameCanvas_FancyGrid; 9 | 10 | 11 | /** 12 | * An implementation of Tic-Tac-Toe based on the GameCanvas_FancyGrid template. 13 | * Comes in at just under 50 lines of code, mostly boilerplate. 14 | * 15 | * @author Sam Schreiber 16 | */ 17 | public class TicTacToeCanvas extends GameCanvas_FancyGrid { 18 | public static final long serialVersionUID = 0x1; 19 | 20 | @Override 21 | public String getGameName() { return "Tic-Tac-Toe"; } 22 | @Override 23 | protected String getGameKey() { return "ticTacToe"; } 24 | @Override 25 | protected int getGridHeight() { return 3; } 26 | @Override 27 | protected int getGridWidth() { return 3; } 28 | 29 | @Override 30 | protected Set getFactsAboutCell(int xCell, int yCell) { 31 | return gameStateHasFactsMatching("\\( cell " + xCell + " " + yCell + " (.*) \\)"); 32 | } 33 | 34 | @Override 35 | protected Set getLegalMovesForCell(int xCell, int yCell) { 36 | return gameStateHasLegalMovesMatching("\\( mark " + xCell + " " + yCell + " \\)"); 37 | } 38 | 39 | @Override 40 | protected void renderCellContent(Graphics g, String theFact) { 41 | String[] cellFacts = theFact.split(" "); 42 | 43 | if(!cellFacts[4].equals("b")) { 44 | g.setColor(Color.BLACK); 45 | CommonGraphics.fillWithString(g, cellFacts[4], 1.2); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/kiosk/templates/GameCanvas_Chessboard.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.kiosk.templates; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | 6 | /** 7 | * GameCanvas_Chessboard is a fixed grid template designed for visualizing 8 | * games that are played on a chess board. It establishes the basic graphical 9 | * conventions for this class of games: an 8x8 board with alternating colors. 10 | * It also defines the coordinates-to-letters mapping that appears in several 11 | * chess board games, such as chess and checkers. 12 | * 13 | * @author Sam Schreiber 14 | */ 15 | public abstract class GameCanvas_Chessboard extends GameCanvas_FancyGrid { 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected int getGridHeight() { return 8; } 20 | @Override 21 | protected int getGridWidth() { return 8; } 22 | 23 | @Override 24 | protected final boolean useGridVisualization() { return true; } 25 | @Override 26 | protected final boolean coordinatesStartAtOne() { return true; } 27 | 28 | @Override 29 | protected final void renderCellBackground(Graphics g, int xCell, int yCell) { 30 | int width = g.getClipBounds().width; 31 | int height = g.getClipBounds().height; 32 | 33 | // Alternating colors for the board 34 | if( (xCell + yCell) % 2 == 0) { 35 | g.setColor(Color.GRAY); 36 | g.fillRect(0, 0, width, height); 37 | } 38 | } 39 | 40 | // This function only works properly when coordinates start at one. 41 | public static final String coordinateToLetter(int x) { 42 | return "" + ((char) ('a' + x - 1)); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/logging/ExampleLogSummarizer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is an example of how to use the log summarizer server to make your own 3 | * log summaries available. First, you create a "log summary generator" that 4 | * gets requests for particular match IDs and returns log summaries for those 5 | * matches. Then, you create a "LogSummarizer" object constructed with the log 6 | * summary generator object as a parameter, and call "runSummarizer" to start 7 | * the log summarizer server using your custom-written log summary generator. 8 | */ 9 | 10 | package org.ggp.base.apps.logging; 11 | 12 | import org.ggp.base.util.logging.LogSummaryGenerator; 13 | 14 | // This is the custom-written log summary generator. You should write one 15 | // of these that produces meaningful log summaries for your player. 16 | class ExampleLogSummaryGenerator extends LogSummaryGenerator { 17 | @Override 18 | public String getSummaryFromLogsDirectory(String theLogsDirectory) { 19 | return "example log for " + theLogsDirectory; 20 | } 21 | } 22 | 23 | // This starts the log summarizer server using the custom-written log summary 24 | // generator written above. 25 | public class ExampleLogSummarizer { 26 | public static void main(String[] args) { 27 | new LogSummarizer(new ExampleLogSummaryGenerator()).runSummarizer(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/PlayerRunner.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.ggp.base.player.GamePlayer; 9 | import org.ggp.base.player.gamer.Gamer; 10 | import org.ggp.base.util.reflection.ProjectSearcher; 11 | 12 | /** 13 | * This is a simple command line app for running players. 14 | * 15 | * @author schreib 16 | */ 17 | public final class PlayerRunner 18 | { 19 | public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException 20 | { 21 | if (args.length != 2 || args[0].equals("${arg0}")) { 22 | System.out.println("PlayerRunner [port] [name]"); 23 | System.out.println("example: ant PlayerRunner -Darg0=9147 -Darg1=TurboTurtle"); 24 | return; 25 | } 26 | int port = Integer.parseInt(args[0]); 27 | String name = args[1]; 28 | System.out.println("Starting up preconfigured player on port " + port + " using player class named " + name); 29 | Class chosenGamerClass = null; 30 | List availableGamers = new ArrayList(); 31 | for (Class gamerClass : ProjectSearcher.GAMERS.getConcreteClasses()) { 32 | availableGamers.add(gamerClass.getSimpleName()); 33 | if (gamerClass.getSimpleName().equals(name)) { 34 | chosenGamerClass = gamerClass; 35 | } 36 | } 37 | if (chosenGamerClass == null) { 38 | System.out.println("Could not find player class with that name. Available choices are: " + Arrays.toString(availableGamers.toArray())); 39 | return; 40 | } 41 | Gamer gamer = (Gamer) chosenGamerClass.newInstance(); 42 | new GamePlayer(port, gamer).start(); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/ProxiedPlayerRunner.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player; 2 | 3 | import java.io.IOException; 4 | 5 | import org.ggp.base.player.gamer.Gamer; 6 | import org.ggp.base.player.gamer.statemachine.random.RandomGamer; 7 | import org.ggp.base.player.proxy.ProxyGamePlayer; 8 | 9 | public final class ProxiedPlayerRunner 10 | { 11 | public static void main(String[] args) throws IOException 12 | { 13 | Class toLaunch = RandomGamer.class; 14 | ProxyGamePlayer player = new ProxyGamePlayer(9147, toLaunch); 15 | player.start(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/config/ConfigPanel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player.config; 2 | 3 | import java.awt.LayoutManager; 4 | 5 | import javax.swing.JPanel; 6 | 7 | @SuppressWarnings("serial") 8 | public abstract class ConfigPanel extends JPanel 9 | { 10 | 11 | public ConfigPanel(LayoutManager layoutManager) 12 | { 13 | super(layoutManager); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/config/EmptyConfigPanel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player.config; 2 | 3 | import java.awt.GridBagConstraints; 4 | import java.awt.GridBagLayout; 5 | import java.awt.Insets; 6 | 7 | import javax.swing.JLabel; 8 | 9 | @SuppressWarnings("serial") 10 | public final class EmptyConfigPanel extends ConfigPanel 11 | { 12 | 13 | public EmptyConfigPanel() 14 | { 15 | super(new GridBagLayout()); 16 | 17 | this.add(new JLabel("No options available."), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/detail/DetailPanel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player.detail; 2 | 3 | import java.awt.LayoutManager; 4 | 5 | import javax.swing.JPanel; 6 | 7 | import org.ggp.base.util.observer.Observer; 8 | 9 | /** 10 | * Gamers can have optional "detail panels" which display their status while 11 | * they're playing matches. This can be as simple as a table listing the number 12 | * of moves they're considering and which one they've selected, or it can show 13 | * complex pieces of debug information like the number of match simulations done 14 | * per second or the expected payoff from taking various moves. 15 | */ 16 | @SuppressWarnings("serial") 17 | public abstract class DetailPanel extends JPanel implements Observer 18 | { 19 | public DetailPanel(LayoutManager layoutManager) 20 | { 21 | super(layoutManager); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/player/detail/EmptyDetailPanel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.player.detail; 2 | 3 | import java.awt.GridBagConstraints; 4 | import java.awt.GridBagLayout; 5 | import java.awt.Insets; 6 | 7 | import javax.swing.JLabel; 8 | 9 | import org.ggp.base.util.observer.Event; 10 | 11 | /** 12 | * This is a detail panel that contains no information at all. 13 | */ 14 | @SuppressWarnings("serial") 15 | public class EmptyDetailPanel extends DetailPanel { 16 | 17 | public EmptyDetailPanel() { 18 | super(new GridBagLayout()); 19 | this.add(new JLabel("No details available."), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 5, 5)); 20 | } 21 | 22 | @Override 23 | public void observe(Event event) { 24 | // Do nothing when notified about events 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/research/Aggregation.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.research; 2 | 3 | import java.util.Comparator; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.TreeSet; 7 | 8 | /** 9 | * Aggregation is a way of storing data about an unordered collection, mapping 10 | * each element to an associated data object, and then visualizing the data by 11 | * sorting the elements by their associated data and printing out the sorted list. 12 | * The data objects must be comparable to each other, so they can be sorted. 13 | * 14 | * @author Sam Schreiber 15 | */ 16 | public abstract class Aggregation> 17 | { 18 | private final Map entryData = new HashMap(); 19 | 20 | boolean containsEntry(String key) { 21 | return entryData.containsKey(key); 22 | } 23 | 24 | void createEntry(String key, T data) { 25 | entryData.put(key, data); 26 | } 27 | 28 | T getEntryData(String key) { 29 | return entryData.get(key); 30 | } 31 | 32 | private final class EntryComparator implements Comparator> { 33 | @Override 34 | public int compare(Map.Entry a, Map.Entry b) { 35 | return a.getValue().compareTo(b.getValue()); 36 | } 37 | 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | int nMaxLength = 0; 43 | StringBuilder theStringRep = new StringBuilder(); 44 | TreeSet> theEntries = new TreeSet>(new EntryComparator()); 45 | theEntries.addAll(entryData.entrySet()); 46 | for (Map.Entry entry : theEntries) { 47 | nMaxLength = Math.max(nMaxLength, entry.getKey().length()); 48 | } 49 | for (Map.Entry entry : theEntries) { 50 | theStringRep.append(String.format("%1$-" + (nMaxLength + 5) + "s", entry.getKey()) + entry.getValue() + "\n"); 51 | } 52 | return theStringRep.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/research/Counter.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.research; 2 | 3 | /** 4 | * Counter is a convenience class for tracking a count. 5 | * 6 | * @author Sam Schreiber 7 | */ 8 | public final class Counter implements Comparable 9 | { 10 | private double totalValue = 0; 11 | 12 | public void addValue(double value) { 13 | totalValue += value; 14 | } 15 | 16 | public double getValue() { 17 | return totalValue; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "" + ((int)(getValue() * 1000.0)/1000.0); 23 | } 24 | 25 | @Override 26 | public int compareTo(Counter arg0) { 27 | return (int)Math.signum(getValue() - arg0.getValue()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/research/FrequencyTable.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.research; 2 | 3 | /** 4 | * FrequencyTable is an aggregation that maps keys to weighted averages. 5 | * 6 | * @author Sam Schreiber 7 | */ 8 | public final class FrequencyTable extends Aggregation 9 | { 10 | public void add(String key, double value) { 11 | if (!containsEntry(key)) { 12 | createEntry(key, new WeightedAverage()); 13 | } 14 | getEntryData(key).addValue(value); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/research/Histogram.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.research; 2 | 3 | 4 | /** 5 | * Histogram is a way of visualizing an unordered collection with repeated 6 | * elements, by mapping each element to the number of times that it appears. 7 | * It is an aggregation that maps keys to counts. 8 | * 9 | * @author Sam Schreiber 10 | */ 11 | public final class Histogram extends Aggregation 12 | { 13 | public void add(String key) { 14 | if (!containsEntry(key)) { 15 | createEntry(key, new Counter()); 16 | } 17 | getEntryData(key).addValue(1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/research/WeightedAverage.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.research; 2 | 3 | /** 4 | * WeightedAverage is a convenience class for tracking a weighted average. 5 | * 6 | * @author Sam Schreiber 7 | */ 8 | public final class WeightedAverage implements Comparable 9 | { 10 | private double totalValue = 0, totalWeight = 0; 11 | 12 | public void addValue(double value) { 13 | addValue(value, 1.0); 14 | } 15 | 16 | public void addValue(double value, double weight) { 17 | totalValue += value; 18 | totalWeight += weight; 19 | } 20 | 21 | public double getValue() { 22 | return totalValue / totalWeight; 23 | } 24 | 25 | public double getWeight() { 26 | return totalWeight; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "" + ((int)(getValue() * 1000.0)/1000.0) + " [" + getWeight() + "]"; 32 | } 33 | 34 | @Override 35 | public int compareTo(WeightedAverage arg0) { 36 | return (int)Math.signum(getValue() - arg0.getValue()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/server/scheduling/PendingMatch.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.server.scheduling; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.game.Game; 6 | import org.ggp.base.util.presence.PlayerPresence; 7 | 8 | public final class PendingMatch 9 | { 10 | public final Game theGame; 11 | public final List thePlayers; 12 | public final String matchID; 13 | public final int previewClock; 14 | public final int startClock; 15 | public final int playClock; 16 | public final boolean shouldScramble; 17 | public final boolean shouldQueue; 18 | public final boolean shouldDetail; 19 | public final boolean shouldSave; 20 | public final boolean shouldPublish; 21 | 22 | public PendingMatch(String matchIdPrefix, Game theGame, List thePlayers, int previewClock, int startClock, int playClock, boolean shouldScramble, boolean shouldQueue, boolean shouldDetail, boolean shouldSave, boolean shouldPublish) { 23 | this.matchID = matchIdPrefix + "." + theGame.getKey() + "." + System.currentTimeMillis(); 24 | this.theGame = theGame; 25 | this.thePlayers = thePlayers; 26 | this.previewClock = previewClock; 27 | this.startClock = startClock; 28 | this.playClock = playClock; 29 | this.shouldScramble = shouldScramble; 30 | this.shouldQueue = shouldQueue; 31 | this.shouldDetail = shouldDetail; 32 | this.shouldSave = shouldSave; 33 | this.shouldPublish = shouldPublish; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/server/visualization/VizContainerPanel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.server.visualization; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.Graphics; 5 | import java.awt.image.BufferedImage; 6 | import java.io.ByteArrayInputStream; 7 | import java.io.ByteArrayOutputStream; 8 | 9 | import javax.imageio.ImageIO; 10 | import javax.swing.JPanel; 11 | 12 | import org.ggp.base.util.ui.GameStateRenderer; 13 | 14 | 15 | @SuppressWarnings("serial") 16 | public class VizContainerPanel extends JPanel { 17 | public VizContainerPanel(String XML, String XSL, VisualizationPanel parent) 18 | { 19 | Dimension d = GameStateRenderer.getDefaultSize(); 20 | setPreferredSize(d); 21 | 22 | BufferedImage backimage = parent.getGraphicsConfiguration().createCompatibleImage(d.width, d.height); 23 | GameStateRenderer.renderImagefromGameXML(XML, XSL, backimage); 24 | try { 25 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 26 | ImageIO.write(backimage, "png", bos); 27 | compressed = bos.toByteArray(); 28 | imageWritten = true; 29 | } catch (Exception ex) { 30 | ex.printStackTrace(); 31 | } 32 | } 33 | 34 | private byte[] compressed = null; 35 | private boolean imageWritten = false; 36 | 37 | @Override 38 | protected void paintComponent(Graphics g) { 39 | super.paintComponent(g); 40 | if (imageWritten) { 41 | try { 42 | BufferedImage img2; 43 | img2 = ImageIO.read(new ByteArrayInputStream(compressed)); 44 | g.drawImage(img2, 0, 0, null); 45 | } catch (Exception ex) { 46 | ex.printStackTrace(); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/validator/ValidatorThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.validator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.ggp.base.apps.validator.event.ValidatorFailureEvent; 7 | import org.ggp.base.apps.validator.event.ValidatorSuccessEvent; 8 | import org.ggp.base.util.game.Game; 9 | import org.ggp.base.util.observer.Event; 10 | import org.ggp.base.util.observer.Observer; 11 | import org.ggp.base.util.observer.Subject; 12 | import org.ggp.base.validator.GameValidator; 13 | import org.ggp.base.validator.ValidatorException; 14 | import org.ggp.base.validator.ValidatorWarning; 15 | 16 | public final class ValidatorThread extends Thread implements Subject 17 | { 18 | private final Game theGame; 19 | private final GameValidator theValidator; 20 | private final List observers; 21 | 22 | public ValidatorThread(Game theGame, GameValidator theValidator) 23 | { 24 | this.theGame = theGame; 25 | this.theValidator = theValidator; 26 | this.observers = new ArrayList(); 27 | } 28 | 29 | @Override 30 | public void addObserver(Observer observer) 31 | { 32 | observers.add(observer); 33 | } 34 | 35 | @Override 36 | public void notifyObservers(Event event) 37 | { 38 | for (Observer observer : observers) 39 | { 40 | observer.observe(event); 41 | } 42 | } 43 | 44 | @Override 45 | public void run() 46 | { 47 | try { 48 | List warnings = theValidator.checkValidity(theGame); 49 | notifyObservers(new ValidatorSuccessEvent(theValidator.getClass().getSimpleName(), warnings)); 50 | } catch (ValidatorException ve) { 51 | notifyObservers(new ValidatorFailureEvent(theValidator.getClass().getSimpleName(), ve)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/validator/event/ValidatorFailureEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.validator.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public class ValidatorFailureEvent extends Event 6 | { 7 | private final String name; 8 | private final Exception exception; 9 | 10 | public ValidatorFailureEvent(String name, Exception exception) 11 | { 12 | this.name = name; 13 | this.exception = exception; 14 | } 15 | 16 | public String getName() 17 | { 18 | return name; 19 | } 20 | 21 | public Exception getException() 22 | { 23 | return exception; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/apps/validator/event/ValidatorSuccessEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.apps.validator.event; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.validator.ValidatorWarning; 7 | 8 | public final class ValidatorSuccessEvent extends Event 9 | { 10 | private final String name; 11 | private final List warnings; 12 | 13 | public ValidatorSuccessEvent(String name, List warnings) 14 | { 15 | this.name = name; 16 | this.warnings = warnings; 17 | } 18 | 19 | public String getName() 20 | { 21 | return name; 22 | } 23 | 24 | public List getWarnings() { 25 | return warnings; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/event/PlayerDroppedPacketEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class PlayerDroppedPacketEvent extends Event 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/event/PlayerReceivedMessageEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class PlayerReceivedMessageEvent extends Event 6 | { 7 | 8 | private final String message; 9 | 10 | public PlayerReceivedMessageEvent(String message) 11 | { 12 | this.message = message; 13 | } 14 | 15 | public String getMessage() 16 | { 17 | return message; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/event/PlayerSentMessageEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class PlayerSentMessageEvent extends Event 6 | { 7 | 8 | private final String message; 9 | 10 | public PlayerSentMessageEvent(String message) 11 | { 12 | this.message = message; 13 | } 14 | 15 | public String getMessage() 16 | { 17 | return message; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/event/PlayerTimeEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class PlayerTimeEvent extends Event 6 | { 7 | 8 | private final long time; 9 | 10 | public PlayerTimeEvent(long time) 11 | { 12 | this.time = time; 13 | } 14 | 15 | public long getTime() 16 | { 17 | return time; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/clojure/stubs/SampleClojureGamerStub.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.clojure.stubs; 2 | import org.ggp.base.player.gamer.clojure.ClojureGamer; 3 | 4 | /** 5 | * SampleClojureGamerStub is a stub that points to a version of @RandomGamer that 6 | * has been implemented in Clojure. This stub needs to exist so that the Clojure 7 | * code can interoperate with the rest of the Java framework (and applications 8 | * like Kiosk and PlayerPanel as a result). 9 | * 10 | * @author Sam 11 | */ 12 | public final class SampleClojureGamerStub extends ClojureGamer 13 | { 14 | @Override 15 | protected String getClojureGamerFile() { return "sample_gamer"; } 16 | @Override 17 | protected String getClojureGamerName() { return "SampleClojureGamer"; } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/event/GamerAbortedMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class GamerAbortedMatchEvent extends Event 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/event/GamerCompletedMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class GamerCompletedMatchEvent extends Event 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/event/GamerNewMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.event; 2 | 3 | import org.ggp.base.util.gdl.grammar.GdlConstant; 4 | import org.ggp.base.util.match.Match; 5 | import org.ggp.base.util.observer.Event; 6 | 7 | public final class GamerNewMatchEvent extends Event 8 | { 9 | 10 | private final Match match; 11 | private final GdlConstant roleName; 12 | 13 | public GamerNewMatchEvent(Match match, GdlConstant roleName) 14 | { 15 | this.match = match; 16 | this.roleName = roleName; 17 | } 18 | 19 | public Match getMatch() 20 | { 21 | return match; 22 | } 23 | 24 | public GdlConstant getRoleName() 25 | { 26 | return roleName; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/event/GamerSelectedMoveEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.event; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.util.statemachine.Move; 7 | 8 | public final class GamerSelectedMoveEvent extends Event 9 | { 10 | private final List moves; 11 | private final Move selection; 12 | private final long time; 13 | 14 | public GamerSelectedMoveEvent(List moves, Move selection, long time) { 15 | this.moves = moves; 16 | this.selection = selection; 17 | this.time = time; 18 | } 19 | 20 | public List getMoves() { 21 | return moves; 22 | } 23 | 24 | public Move getSelection() { 25 | return selection; 26 | } 27 | 28 | public long getTime() { 29 | return time; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/event/GamerUnrecognizedMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public final class GamerUnrecognizedMatchEvent extends Event 6 | { 7 | 8 | private final String matchId; 9 | 10 | public GamerUnrecognizedMatchEvent(String matchId) 11 | { 12 | this.matchId = matchId; 13 | } 14 | 15 | public String getMatchId() 16 | { 17 | return matchId; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/exception/AbortingException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.exception; 2 | 3 | @SuppressWarnings("serial") 4 | public final class AbortingException extends Exception 5 | { 6 | public AbortingException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | @Override 11 | public String toString() 12 | { 13 | return "An unhandled exception ocurred during aborting: " + super.toString(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/exception/GamePreviewException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.exception; 2 | 3 | @SuppressWarnings("serial") 4 | public final class GamePreviewException extends Exception 5 | { 6 | public GamePreviewException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | @Override 11 | public String toString() 12 | { 13 | return "An unhandled exception occurred during game previewing!"; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/exception/MetaGamingException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.exception; 2 | 3 | @SuppressWarnings("serial") 4 | public final class MetaGamingException extends Exception 5 | { 6 | public MetaGamingException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | @Override 11 | public String toString() 12 | { 13 | return "An unhandled exception occurred during metagaming: " + super.toString(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/exception/MoveSelectionException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.exception; 2 | 3 | @SuppressWarnings("serial") 4 | public final class MoveSelectionException extends Exception 5 | { 6 | public MoveSelectionException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | @Override 11 | public String toString() 12 | { 13 | return "An unhandled exception ocurred during move selection: " + super.toString(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/exception/StoppingException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.exception; 2 | 3 | @SuppressWarnings("serial") 4 | public final class StoppingException extends Exception 5 | { 6 | public StoppingException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | @Override 11 | public String toString() 12 | { 13 | return "An unhandled exception ocurred during stopping: " + super.toString(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/python/stubs/SamplePythonGamerStub.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.python.stubs; 2 | import org.ggp.base.player.gamer.python.PythonGamer; 3 | 4 | /** 5 | * SamplePythonGamerStub is a stub pointing to a version of @RandomGamer that 6 | * has been implemented in Python. This stub needs to exist so that the Python 7 | * code can interoperate with the rest of the Java framework (and applications 8 | * like Kiosk and PlayerPanel as a result). 9 | * 10 | * @author Sam 11 | */ 12 | public final class SamplePythonGamerStub extends PythonGamer 13 | { 14 | @Override 15 | protected String getPythonGamerModule() { return "sample_gamer"; } 16 | @Override 17 | protected String getPythonGamerName() { return "SamplePythonGamer"; } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/statemachine/human/event/HumanNewMovesEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.statemachine.human.event; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | import org.ggp.base.util.observer.Event; 9 | import org.ggp.base.util.statemachine.Move; 10 | 11 | import com.google.common.collect.ImmutableList; 12 | 13 | 14 | public final class HumanNewMovesEvent extends Event 15 | { 16 | private final ImmutableList moves; 17 | private final Move selection; 18 | 19 | private HumanNewMovesEvent(ImmutableList moves, Move selection) { 20 | this.moves = moves; 21 | this.selection = selection; 22 | } 23 | 24 | public static HumanNewMovesEvent create(List moves, Move selection) { 25 | List sortedMoves = new ArrayList(moves); 26 | Collections.sort(sortedMoves, new Comparator(){ 27 | @Override 28 | public int compare(Move o1, Move o2) { 29 | return o1.toString().compareTo(o2.toString()); 30 | } 31 | }); 32 | return new HumanNewMovesEvent(ImmutableList.copyOf(sortedMoves), selection); 33 | } 34 | 35 | public List getMoves() { 36 | return moves; 37 | } 38 | 39 | public Move getSelection() { 40 | return selection; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/statemachine/human/event/HumanTimeoutEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.statemachine.human.event; 2 | 3 | import org.ggp.base.player.gamer.statemachine.human.HumanGamer; 4 | import org.ggp.base.util.observer.Event; 5 | 6 | 7 | public final class HumanTimeoutEvent extends Event 8 | { 9 | 10 | private final HumanGamer humanPlayer; 11 | 12 | public HumanTimeoutEvent(HumanGamer humanPlayer) 13 | { 14 | this.humanPlayer = humanPlayer; 15 | } 16 | 17 | public HumanGamer getHumanPlayer() 18 | { 19 | return humanPlayer; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/gamer/statemachine/sample/SampleNoopGamer.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.gamer.statemachine.sample; 2 | 3 | import org.ggp.base.apps.player.detail.DetailPanel; 4 | import org.ggp.base.apps.player.detail.EmptyDetailPanel; 5 | import org.ggp.base.util.gdl.grammar.GdlPool; 6 | import org.ggp.base.util.statemachine.Move; 7 | import org.ggp.base.util.statemachine.exceptions.GoalDefinitionException; 8 | import org.ggp.base.util.statemachine.exceptions.MoveDefinitionException; 9 | import org.ggp.base.util.statemachine.exceptions.TransitionDefinitionException; 10 | 11 | /** 12 | * SampleNoopGamer is a minimal gamer which always plays NOOP regardless 13 | * of which moves are actually legal in the current state of the game. 14 | */ 15 | public final class SampleNoopGamer extends SampleGamer 16 | { 17 | @Override 18 | public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException 19 | { 20 | return new Move(GdlPool.getConstant("NOOP")); 21 | } 22 | 23 | @Override 24 | public DetailPanel getDetailPanel() { 25 | return new EmptyDetailPanel(); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/proxy/WorkingResponseSelectedEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.proxy; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | 5 | public class WorkingResponseSelectedEvent extends Event { 6 | private String theResponse; 7 | 8 | public WorkingResponseSelectedEvent(String theResponse) { 9 | this.theResponse = theResponse; 10 | } 11 | 12 | public String getWorkingResponse() { 13 | return theResponse; 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/request/factory/exceptions/RequestFormatException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.request.factory.exceptions; 2 | 3 | @SuppressWarnings("serial") 4 | public final class RequestFormatException extends Exception 5 | { 6 | private final String source; 7 | private final Exception bad; 8 | 9 | public RequestFormatException(String source, Exception bad) 10 | { 11 | this.source = source; 12 | this.bad = bad; 13 | } 14 | 15 | public String getSource() 16 | { 17 | return source; 18 | } 19 | 20 | @Override 21 | public String toString() 22 | { 23 | return "Improperly formatted request: " + source + ", resulting in exception: " + bad; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/request/grammar/AbortRequest.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.request.grammar; 2 | 3 | import org.ggp.base.player.gamer.Gamer; 4 | import org.ggp.base.player.gamer.event.GamerAbortedMatchEvent; 5 | import org.ggp.base.player.gamer.event.GamerUnrecognizedMatchEvent; 6 | import org.ggp.base.player.gamer.exception.AbortingException; 7 | import org.ggp.base.util.logging.GamerLogger; 8 | 9 | public final class AbortRequest extends Request 10 | { 11 | private final Gamer gamer; 12 | private final String matchId; 13 | 14 | public AbortRequest(Gamer gamer, String matchId) 15 | { 16 | this.gamer = gamer; 17 | this.matchId = matchId; 18 | } 19 | 20 | @Override 21 | public String getMatchId() { 22 | return matchId; 23 | } 24 | 25 | @Override 26 | public String process(long receptionTime) 27 | { 28 | // First, check to ensure that this abort request is for the match 29 | // we're currently playing. If we're not playing a match, or we're 30 | // playing a different match, send back "busy". 31 | if (gamer.getMatch() == null || !gamer.getMatch().getMatchId().equals(matchId)) 32 | { 33 | GamerLogger.logError("GamePlayer", "Got abort message not intended for current game: ignoring."); 34 | gamer.notifyObservers(new GamerUnrecognizedMatchEvent(matchId)); 35 | return "busy"; 36 | } 37 | 38 | // Mark the match as aborted and notify observers 39 | gamer.getMatch().markAborted(); 40 | gamer.notifyObservers(new GamerAbortedMatchEvent()); 41 | try { 42 | gamer.abort(); 43 | } catch (AbortingException e) { 44 | GamerLogger.logStackTrace("GamePlayer", e); 45 | } 46 | 47 | // Once the match has ended, set 'roleName' and 'match' 48 | // to NULL to indicate that we're ready to begin a new match. 49 | gamer.setRoleName(null); 50 | gamer.setMatch(null); 51 | 52 | return "aborted"; 53 | } 54 | 55 | @Override 56 | public String toString() 57 | { 58 | return "abort"; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/request/grammar/InfoRequest.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.request.grammar; 2 | 3 | import org.ggp.base.player.gamer.Gamer; 4 | import org.ggp.base.util.presence.InfoResponse; 5 | 6 | public final class InfoRequest extends Request 7 | { 8 | private final Gamer gamer; 9 | 10 | public InfoRequest(Gamer gamer) 11 | { 12 | this.gamer = gamer; 13 | } 14 | 15 | @Override 16 | public String getMatchId() { 17 | return null; 18 | } 19 | 20 | @Override 21 | public String process(long receptionTime) 22 | { 23 | InfoResponse info = new InfoResponse(); 24 | info.setName(gamer.getName()); 25 | info.setStatus(gamer.getMatch() == null ? "available" : "busy"); 26 | info.setSpecies(gamer.getSpecies()); 27 | return info.toSymbol().toString(); 28 | } 29 | 30 | @Override 31 | public String toString() 32 | { 33 | return "info"; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/player/request/grammar/Request.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.player.request.grammar; 2 | 3 | public abstract class Request 4 | { 5 | 6 | public abstract String process(long receptionTime); 7 | 8 | public abstract String getMatchId(); 9 | 10 | @Override 11 | public abstract String toString(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerAbortedMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | 7 | @SuppressWarnings("serial") 8 | public final class ServerAbortedMatchEvent extends Event implements Serializable 9 | { 10 | public ServerAbortedMatchEvent() 11 | { 12 | ; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerCompletedMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import org.ggp.base.util.observer.Event; 7 | 8 | 9 | @SuppressWarnings("serial") 10 | public final class ServerCompletedMatchEvent extends Event implements Serializable 11 | { 12 | 13 | private final List goals; 14 | 15 | public ServerCompletedMatchEvent(List goals) 16 | { 17 | this.goals = goals; 18 | } 19 | 20 | public List getGoals() 21 | { 22 | return goals; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerConnectionErrorEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.util.statemachine.Role; 7 | 8 | 9 | @SuppressWarnings("serial") 10 | public final class ServerConnectionErrorEvent extends Event implements Serializable 11 | { 12 | 13 | private final Role role; 14 | 15 | public ServerConnectionErrorEvent(Role role) 16 | { 17 | this.role = role; 18 | } 19 | 20 | public Role getRole() 21 | { 22 | return role; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerIllegalMoveEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.util.statemachine.Move; 7 | import org.ggp.base.util.statemachine.Role; 8 | 9 | 10 | @SuppressWarnings("serial") 11 | public final class ServerIllegalMoveEvent extends Event implements Serializable 12 | { 13 | 14 | private final Move move; 15 | private final Role role; 16 | 17 | public ServerIllegalMoveEvent(Role role, Move move) 18 | { 19 | this.role = role; 20 | this.move = move; 21 | } 22 | 23 | public Move getMove() 24 | { 25 | return move; 26 | } 27 | 28 | public Role getRole() 29 | { 30 | return role; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerMatchUpdatedEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import org.ggp.base.util.match.Match; 4 | import org.ggp.base.util.observer.Event; 5 | 6 | public final class ServerMatchUpdatedEvent extends Event { 7 | private final Match match; 8 | private final String externalPublicationKey; 9 | private final String externalFilename; 10 | 11 | public ServerMatchUpdatedEvent(Match match, String externalPublicationKey, String externalFilename) { 12 | this.match = match; 13 | this.externalFilename = externalFilename; 14 | this.externalPublicationKey = externalPublicationKey; 15 | } 16 | 17 | public Match getMatch() { 18 | return match; 19 | } 20 | 21 | public String getExternalFilename() { 22 | return externalFilename; 23 | } 24 | 25 | public String getExternalPublicationKey() { 26 | return externalPublicationKey; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerNewGameStateEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import org.ggp.base.util.observer.Event; 4 | import org.ggp.base.util.statemachine.MachineState; 5 | 6 | 7 | public final class ServerNewGameStateEvent extends Event 8 | { 9 | private final MachineState state; 10 | 11 | public ServerNewGameStateEvent(MachineState state) 12 | { 13 | this.state = state; 14 | } 15 | 16 | public MachineState getState() 17 | { 18 | return state; 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerNewMatchEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.util.statemachine.MachineState; 7 | import org.ggp.base.util.statemachine.Role; 8 | 9 | 10 | public final class ServerNewMatchEvent extends Event 11 | { 12 | 13 | private final List roles; 14 | private final MachineState initialState; 15 | 16 | public ServerNewMatchEvent(List roles, MachineState initialState) 17 | { 18 | this.roles = roles; 19 | this.initialState = initialState; 20 | } 21 | 22 | public List getRoles() 23 | { 24 | return roles; 25 | } 26 | 27 | public MachineState getInitialState() 28 | { 29 | return initialState; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerNewMovesEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import org.ggp.base.util.observer.Event; 7 | import org.ggp.base.util.statemachine.Move; 8 | 9 | 10 | @SuppressWarnings("serial") 11 | public final class ServerNewMovesEvent extends Event implements Serializable 12 | { 13 | 14 | private final List moves; 15 | 16 | public ServerNewMovesEvent(List moves) 17 | { 18 | this.moves = moves; 19 | } 20 | 21 | public List getMoves() 22 | { 23 | return moves; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerTimeEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | 7 | 8 | @SuppressWarnings("serial") 9 | public final class ServerTimeEvent extends Event implements Serializable 10 | { 11 | 12 | private final long time; 13 | 14 | public ServerTimeEvent(long time) 15 | { 16 | this.time = time; 17 | } 18 | 19 | public long getTime() 20 | { 21 | return time; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/event/ServerTimeoutEvent.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.ggp.base.util.observer.Event; 6 | import org.ggp.base.util.statemachine.Role; 7 | 8 | 9 | @SuppressWarnings("serial") 10 | public final class ServerTimeoutEvent extends Event implements Serializable 11 | { 12 | 13 | private final Role role; 14 | 15 | public ServerTimeoutEvent(Role role) 16 | { 17 | this.role = role; 18 | } 19 | 20 | public Role getRole() 21 | { 22 | return role; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/threads/AbortRequestThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.threads; 2 | 3 | import org.ggp.base.server.GameServer; 4 | import org.ggp.base.server.request.RequestBuilder; 5 | import org.ggp.base.util.match.Match; 6 | import org.ggp.base.util.statemachine.Role; 7 | 8 | public final class AbortRequestThread extends RequestThread 9 | { 10 | public AbortRequestThread(GameServer gameServer, Match match, Role role, String host, int port, String playerName) 11 | { 12 | super(gameServer, role, host, port, playerName, 1000, RequestBuilder.getAbortRequest(match.getMatchId())); 13 | } 14 | 15 | @Override 16 | protected void handleResponse(String response) { 17 | ; 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/threads/PreviewRequestThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.threads; 2 | 3 | import org.ggp.base.server.GameServer; 4 | import org.ggp.base.server.request.RequestBuilder; 5 | import org.ggp.base.util.match.Match; 6 | import org.ggp.base.util.statemachine.Role; 7 | 8 | 9 | public final class PreviewRequestThread extends RequestThread 10 | { 11 | public PreviewRequestThread(GameServer gameServer, Match match, Role role, String host, int port, String playerName) 12 | { 13 | super(gameServer, role, host, port, playerName, match.getPreviewClock() * 1000, RequestBuilder.getPreviewRequest(match.getGame().getRules(), match.getPreviewClock(), match.getGdlScrambler())); 14 | } 15 | 16 | @Override 17 | protected void handleResponse(String response) { 18 | ; 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/threads/RandomPlayRequestThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.threads; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ThreadLocalRandom; 5 | 6 | import org.ggp.base.util.match.Match; 7 | import org.ggp.base.util.statemachine.Move; 8 | 9 | 10 | public final class RandomPlayRequestThread extends PlayRequestThread 11 | { 12 | private Move move; 13 | 14 | public RandomPlayRequestThread(Match match, List legalMoves) 15 | { 16 | super(null, match, null, legalMoves, null, null, 0, null, true); 17 | move = legalMoves.get(ThreadLocalRandom.current().nextInt(legalMoves.size())); 18 | } 19 | 20 | @Override 21 | public Move getMove() 22 | { 23 | return move; 24 | } 25 | 26 | @Override 27 | public void run() 28 | { 29 | ; 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/threads/StartRequestThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.threads; 2 | 3 | import org.ggp.base.server.GameServer; 4 | import org.ggp.base.server.request.RequestBuilder; 5 | import org.ggp.base.util.match.Match; 6 | import org.ggp.base.util.statemachine.Role; 7 | 8 | 9 | public final class StartRequestThread extends RequestThread 10 | { 11 | public StartRequestThread(GameServer gameServer, Match match, Role role, String host, int port, String playerName) 12 | { 13 | super(gameServer, role, host, port, playerName, match.getStartClock() * 1000, RequestBuilder.getStartRequest(match.getMatchId(), role, match.getGame().getRules(), match.getStartClock(), match.getPlayClock(), match.getGdlScrambler())); 14 | } 15 | 16 | @Override 17 | protected void handleResponse(String response) { 18 | ; 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/server/threads/StopRequestThread.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.server.threads; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.server.GameServer; 6 | import org.ggp.base.server.request.RequestBuilder; 7 | import org.ggp.base.util.match.Match; 8 | import org.ggp.base.util.statemachine.Move; 9 | import org.ggp.base.util.statemachine.Role; 10 | 11 | 12 | public final class StopRequestThread extends RequestThread 13 | { 14 | public StopRequestThread(GameServer gameServer, Match match, List previousMoves, Role role, String host, int port, String playerName) 15 | { 16 | super(gameServer, role, host, port, playerName, match.getPlayClock() * 1000, RequestBuilder.getStopRequest(match.getMatchId(), previousMoves, match.getGdlScrambler())); 17 | } 18 | 19 | @Override 20 | protected void handleResponse(String response) { 21 | ; 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/Pair.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util; 2 | 3 | import java.util.Map; 4 | 5 | public class Pair { 6 | public final L left; 7 | public final R right; 8 | 9 | private Pair(L left, R right) { 10 | this.left = left; 11 | this.right = right; 12 | } 13 | 14 | public static Pair of(L left, R right) { 15 | return new Pair(left, right); 16 | } 17 | 18 | public static Pair from(Map.Entry entry) { 19 | return of(entry.getKey(), entry.getValue()); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | final int prime = 31; 25 | int result = 1; 26 | result = prime * result + ((left == null) ? 0 : left.hashCode()); 27 | result = prime * result + ((right == null) ? 0 : right.hashCode()); 28 | return result; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (this == obj) 34 | return true; 35 | if (obj == null) 36 | return false; 37 | if (getClass() != obj.getClass()) 38 | return false; 39 | Pair other = (Pair) obj; 40 | if (left == null) { 41 | if (other.left != null) 42 | return false; 43 | } else if (!left.equals(other.left)) 44 | return false; 45 | if (right == null) { 46 | if (other.right != null) 47 | return false; 48 | } else if (!right.equals(other.right)) 49 | return false; 50 | return true; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "<" + left + ", " + right + ">"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/concurrency/ConcurrencyUtils.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.concurrency; 2 | 3 | public class ConcurrencyUtils { 4 | private ConcurrencyUtils() { 5 | } 6 | 7 | /** 8 | * If the thread has been interrupted, throws an InterruptedException. 9 | */ 10 | public static void checkForInterruption() throws InterruptedException { 11 | if (Thread.currentThread().isInterrupted()) 12 | throw new InterruptedException(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/configuration/ProjectConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * ProjectConfiguration handles the project-specific directory settings. 3 | * This class stores the paths of the game directory so it can quickly be changed and overridden. 4 | * 5 | * @author Sam Schreiber 6 | */ 7 | 8 | package org.ggp.base.util.configuration; 9 | 10 | import java.io.File; 11 | 12 | public class ProjectConfiguration { 13 | /* Game rulesheet repository information */ 14 | private static final String gamesRootDirectoryPath = "games"; 15 | 16 | public static final File gameImagesDirectory = new File(new File(gamesRootDirectoryPath, "resources"), "images"); 17 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/crypto/BaseHashing.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.crypto; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.ByteArrayInputStream; 5 | import java.security.DigestInputStream; 6 | import java.security.MessageDigest; 7 | import java.util.Formatter; 8 | 9 | public class BaseHashing { 10 | // Computes the SHA1 hash of a given input string, and represents 11 | // that hash as a hexadecimal string. 12 | public static String computeSHA1Hash(String theData) { 13 | try { 14 | MessageDigest SHA1 = MessageDigest.getInstance("SHA1"); 15 | DigestInputStream theDigestStream = new DigestInputStream( 16 | new BufferedInputStream(new ByteArrayInputStream( 17 | theData.getBytes("UTF-8"))), SHA1); 18 | while (theDigestStream.read() != -1); 19 | byte[] theHash = SHA1.digest(); 20 | 21 | Formatter hexFormat = new Formatter(); 22 | for (byte x : theHash) { 23 | hexFormat.format("%02x", x); 24 | } 25 | String theHex = hexFormat.toString(); 26 | hexFormat.close(); 27 | return theHex; 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | return null; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/files/FileUtils.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.files; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | import java.io.PrintStream; 10 | 11 | public class FileUtils { 12 | private FileUtils() { 13 | } 14 | 15 | public static String readFileAsString(File file) { 16 | try (BufferedReader reader = new BufferedReader(new FileReader(file))) { 17 | StringBuilder fileData = new StringBuilder(10000); 18 | char[] buf = new char[1024]; 19 | int numRead=0; 20 | while((numRead=reader.read(buf)) != -1){ 21 | fileData.append(buf, 0, numRead); 22 | } 23 | return fileData.toString(); 24 | } catch (FileNotFoundException e) { 25 | return null; 26 | } catch (IOException e) { 27 | e.printStackTrace(); 28 | return null; 29 | } 30 | } 31 | 32 | public static void writeStringToFile(File file, String s) throws IOException { 33 | try (PrintStream out = new PrintStream(new FileOutputStream(file, false))) { 34 | out.print(s); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/game/GameRepository.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.game; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | /** 8 | * Game repositories contain games, and provide two main services: you can 9 | * query a repository to get a list of available games (by key), and given 10 | * a key, you can look up the associated Game object. 11 | * 12 | * All queries to a game repository are cached, and the caching is handled 13 | * in this abstract base class. Concrete subclasses will implement the actual 14 | * behavior required for fetching games from the underlying repositories. 15 | * 16 | * @author Sam 17 | */ 18 | public abstract class GameRepository { 19 | public static GameRepository getDefaultRepository() { 20 | return new CloudGameRepository("games.ggp.org/base"); 21 | } 22 | 23 | public Game getGame(String theKey) { 24 | if (!theGames.containsKey(theKey)) { 25 | Game theGame = getUncachedGame(theKey); 26 | if (theGame != null) { 27 | theGames.put(theKey, theGame); 28 | } 29 | } 30 | return theGames.get(theKey); 31 | } 32 | 33 | public Set getGameKeys() { 34 | if (theGameKeys == null) { 35 | theGameKeys = getUncachedGameKeys(); 36 | } 37 | return theGameKeys; 38 | } 39 | 40 | // Abstract methods, for implementation classes. 41 | protected abstract Game getUncachedGame(String theKey); 42 | protected abstract Set getUncachedGameKeys(); 43 | 44 | // Cached values, lazily filled. 45 | private Set theGameKeys; 46 | private Map theGames = new HashMap(); 47 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/game/TestGameRepository.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.game; 2 | 3 | import java.io.File; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.util.files.FileUtils; 8 | 9 | 10 | /** 11 | * Test game repository that provides rulesheet-only access to games with no 12 | * associated metadata or other resources, to be used only for unit tests. 13 | * 14 | * @author Sam 15 | */ 16 | public final class TestGameRepository extends GameRepository { 17 | @Override 18 | protected Set getUncachedGameKeys() { 19 | Set theKeys = new HashSet(); 20 | for(File game : new File("games/test").listFiles()) { 21 | if(!game.getName().endsWith(".kif")) continue; 22 | theKeys.add(game.getName().replace(".kif", "")); 23 | } 24 | return theKeys; 25 | } 26 | 27 | @Override 28 | protected Game getUncachedGame(String theKey) { 29 | try { 30 | return Game.createEphemeralGame(Game.preprocessRulesheet(FileUtils.readFileAsString(new File("games/test/" + theKey + ".kif")))); 31 | } catch (Exception e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/factory/exceptions/GdlFormatException.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.factory.exceptions; 2 | 3 | import org.ggp.base.util.symbol.grammar.Symbol; 4 | 5 | @SuppressWarnings("serial") 6 | public final class GdlFormatException extends Exception 7 | { 8 | 9 | private final Symbol source; 10 | 11 | public GdlFormatException(Symbol source) 12 | { 13 | this.source = source; 14 | } 15 | 16 | public Symbol getSource() 17 | { 18 | return source; 19 | } 20 | 21 | @Override 22 | public String toString() 23 | { 24 | return "Improperly formatted gdl expression: " + source; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/Gdl.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.io.ObjectStreamException; 4 | import java.io.Serializable; 5 | 6 | @SuppressWarnings("serial") 7 | public abstract class Gdl implements Serializable 8 | { 9 | 10 | public abstract boolean isGround(); 11 | 12 | @Override 13 | public abstract String toString(); 14 | 15 | /** 16 | * This method is used by deserialization to ensure that Gdl objects 17 | * loaded from an ObjectInputStream or a remote method invocation 18 | * are the versions that exist in the GdlPool. 19 | */ 20 | protected Object readResolve() throws ObjectStreamException { 21 | return GdlPool.immerse(this); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlConstant.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public final class GdlConstant extends GdlTerm 5 | { 6 | 7 | private final String value; 8 | 9 | GdlConstant(String value) 10 | { 11 | this.value = value.intern(); 12 | } 13 | 14 | public String getValue() 15 | { 16 | return value; 17 | } 18 | 19 | @Override 20 | public boolean isGround() 21 | { 22 | return true; 23 | } 24 | 25 | @Override 26 | public GdlSentence toSentence() 27 | { 28 | return GdlPool.getProposition(this); 29 | } 30 | 31 | @Override 32 | public String toString() 33 | { 34 | return value; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlDistinct.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public final class GdlDistinct extends GdlLiteral 5 | { 6 | 7 | private final GdlTerm arg1; 8 | private final GdlTerm arg2; 9 | private transient Boolean ground; 10 | 11 | GdlDistinct(GdlTerm arg1, GdlTerm arg2) 12 | { 13 | this.arg1 = arg1; 14 | this.arg2 = arg2; 15 | ground = null; 16 | } 17 | 18 | public GdlTerm getArg1() 19 | { 20 | return arg1; 21 | } 22 | 23 | public GdlTerm getArg2() 24 | { 25 | return arg2; 26 | } 27 | 28 | @Override 29 | public boolean isGround() 30 | { 31 | if (ground == null) 32 | { 33 | ground = arg1.isGround() && arg2.isGround(); 34 | } 35 | 36 | return ground; 37 | } 38 | 39 | @Override 40 | public String toString() 41 | { 42 | return "( distinct " + arg1 + " " + arg2 + " )"; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlFunction.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | 7 | @SuppressWarnings("serial") 8 | public final class GdlFunction extends GdlTerm 9 | { 10 | 11 | private final ImmutableList body; 12 | private transient Boolean ground; 13 | private final GdlConstant name; 14 | 15 | GdlFunction(GdlConstant name, ImmutableList body) 16 | { 17 | this.name = name; 18 | this.body = body; 19 | ground = null; 20 | } 21 | 22 | public int arity() 23 | { 24 | return body.size(); 25 | } 26 | 27 | private boolean computeGround() 28 | { 29 | for (GdlTerm term : body) 30 | { 31 | if (!term.isGround()) 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | return true; 38 | } 39 | 40 | public GdlTerm get(int index) 41 | { 42 | return body.get(index); 43 | } 44 | 45 | public GdlConstant getName() 46 | { 47 | return name; 48 | } 49 | 50 | public List getBody() 51 | { 52 | return body; 53 | } 54 | 55 | @Override 56 | public boolean isGround() 57 | { 58 | if (ground == null) 59 | { 60 | ground = computeGround(); 61 | } 62 | 63 | return ground; 64 | } 65 | 66 | @Override 67 | public GdlSentence toSentence() 68 | { 69 | return GdlPool.getRelation(name, body); 70 | } 71 | 72 | @Override 73 | public String toString() 74 | { 75 | StringBuilder sb = new StringBuilder(); 76 | 77 | sb.append("( " + name + " "); 78 | for (GdlTerm term : body) 79 | { 80 | sb.append(term + " "); 81 | } 82 | sb.append(")"); 83 | 84 | return sb.toString(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlLiteral.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public abstract class GdlLiteral extends Gdl 5 | { 6 | 7 | @Override 8 | public abstract boolean isGround(); 9 | 10 | @Override 11 | public abstract String toString(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlNot.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public final class GdlNot extends GdlLiteral 5 | { 6 | 7 | private final GdlLiteral body; 8 | private transient Boolean ground; 9 | 10 | GdlNot(GdlLiteral body) 11 | { 12 | this.body = body; 13 | ground = null; 14 | } 15 | 16 | public GdlLiteral getBody() 17 | { 18 | return body; 19 | } 20 | 21 | @Override 22 | public boolean isGround() 23 | { 24 | if (ground == null) 25 | { 26 | ground = body.isGround(); 27 | } 28 | 29 | return ground; 30 | } 31 | 32 | @Override 33 | public String toString() 34 | { 35 | return "( not " + body + " )"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlOr.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | 7 | @SuppressWarnings("serial") 8 | public final class GdlOr extends GdlLiteral 9 | { 10 | 11 | private final ImmutableList disjuncts; 12 | private transient Boolean ground; 13 | 14 | GdlOr(ImmutableList disjuncts) 15 | { 16 | this.disjuncts = disjuncts; 17 | ground = null; 18 | } 19 | 20 | public int arity() 21 | { 22 | return disjuncts.size(); 23 | } 24 | 25 | private boolean computeGround() 26 | { 27 | for (GdlLiteral literal : disjuncts) 28 | { 29 | if (!literal.isGround()) 30 | { 31 | return false; 32 | } 33 | } 34 | 35 | return true; 36 | } 37 | 38 | public GdlLiteral get(int index) 39 | { 40 | return disjuncts.get(index); 41 | } 42 | 43 | public List getDisjuncts() { 44 | return disjuncts; 45 | } 46 | 47 | @Override 48 | public boolean isGround() 49 | { 50 | if (ground == null) 51 | { 52 | ground = computeGround(); 53 | } 54 | 55 | return ground; 56 | } 57 | 58 | @Override 59 | public String toString() 60 | { 61 | StringBuilder sb = new StringBuilder(); 62 | 63 | sb.append("( or "); 64 | for (GdlLiteral literal : disjuncts) 65 | { 66 | sb.append(literal + " "); 67 | } 68 | sb.append(")"); 69 | 70 | return sb.toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlProposition.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | @SuppressWarnings("serial") 7 | public final class GdlProposition extends GdlSentence 8 | { 9 | 10 | private final GdlConstant name; 11 | 12 | GdlProposition(GdlConstant name) 13 | { 14 | this.name = name; 15 | } 16 | 17 | @Override 18 | public int arity() 19 | { 20 | return 0; 21 | } 22 | 23 | @Override 24 | public GdlTerm get(int index) 25 | { 26 | throw new RuntimeException("GdlPropositions have no body!"); 27 | } 28 | 29 | @Override 30 | public GdlConstant getName() 31 | { 32 | return name; 33 | } 34 | 35 | @Override 36 | public boolean isGround() 37 | { 38 | return name.isGround(); 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return name.toString(); 45 | } 46 | 47 | @Override 48 | public GdlTerm toTerm() 49 | { 50 | return name; 51 | } 52 | 53 | @Override 54 | public List getBody() { 55 | return Collections.emptyList(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlRelation.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | 7 | @SuppressWarnings("serial") 8 | public final class GdlRelation extends GdlSentence 9 | { 10 | 11 | private final ImmutableList body; 12 | private transient Boolean ground; 13 | private final GdlConstant name; 14 | 15 | GdlRelation(GdlConstant name, ImmutableList body) 16 | { 17 | this.name = name; 18 | this.body = body; 19 | ground = null; 20 | } 21 | 22 | @Override 23 | public int arity() 24 | { 25 | return body.size(); 26 | } 27 | 28 | private boolean computeGround() 29 | { 30 | for (GdlTerm term : body) 31 | { 32 | if (!term.isGround()) 33 | { 34 | return false; 35 | } 36 | } 37 | 38 | return true; 39 | } 40 | 41 | @Override 42 | public GdlTerm get(int index) 43 | { 44 | return body.get(index); 45 | } 46 | 47 | @Override 48 | public GdlConstant getName() 49 | { 50 | return name; 51 | } 52 | 53 | @Override 54 | public boolean isGround() 55 | { 56 | if (ground == null) 57 | { 58 | ground = computeGround(); 59 | } 60 | 61 | return ground; 62 | } 63 | 64 | @Override 65 | public String toString() 66 | { 67 | StringBuilder sb = new StringBuilder(); 68 | 69 | sb.append("( " + name + " "); 70 | for (GdlTerm term : body) 71 | { 72 | sb.append(term + " "); 73 | } 74 | sb.append(")"); 75 | 76 | return sb.toString(); 77 | } 78 | 79 | @Override 80 | public GdlTerm toTerm() 81 | { 82 | return GdlPool.getFunction(name, body); 83 | } 84 | 85 | @Override 86 | public List getBody() 87 | { 88 | return body; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlRule.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | 7 | @SuppressWarnings("serial") 8 | public final class GdlRule extends Gdl 9 | { 10 | 11 | private final ImmutableList body; 12 | private transient Boolean ground; 13 | private final GdlSentence head; 14 | 15 | GdlRule(GdlSentence head, ImmutableList body) 16 | { 17 | this.head = head; 18 | this.body = body; 19 | ground = null; 20 | } 21 | 22 | public int arity() 23 | { 24 | return body.size(); 25 | } 26 | 27 | private Boolean computeGround() 28 | { 29 | for (GdlLiteral literal : body) 30 | { 31 | if (!literal.isGround()) 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | return true; 38 | } 39 | 40 | public GdlLiteral get(int index) 41 | { 42 | return body.get(index); 43 | } 44 | 45 | public GdlSentence getHead() 46 | { 47 | return head; 48 | } 49 | 50 | public List getBody() 51 | { 52 | return body; 53 | } 54 | 55 | @Override 56 | public boolean isGround() 57 | { 58 | if (ground == null) 59 | { 60 | ground = computeGround(); 61 | } 62 | 63 | return ground; 64 | } 65 | 66 | @Override 67 | public String toString() 68 | { 69 | StringBuilder sb = new StringBuilder(); 70 | 71 | sb.append("( <= " + head + " "); 72 | for (GdlLiteral literal : body) 73 | { 74 | sb.append(literal + " "); 75 | } 76 | sb.append(")"); 77 | 78 | return sb.toString(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlSentence.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings("serial") 6 | public abstract class GdlSentence extends GdlLiteral 7 | { 8 | 9 | public abstract int arity(); 10 | 11 | public abstract GdlTerm get(int index); 12 | 13 | public abstract GdlConstant getName(); 14 | 15 | @Override 16 | public abstract boolean isGround(); 17 | 18 | @Override 19 | public abstract String toString(); 20 | 21 | public abstract GdlTerm toTerm(); 22 | 23 | public abstract List getBody(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlTerm.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public abstract class GdlTerm extends Gdl 5 | { 6 | 7 | @Override 8 | public abstract boolean isGround(); 9 | 10 | public abstract GdlSentence toSentence(); 11 | 12 | @Override 13 | public abstract String toString(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/grammar/GdlVariable.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.grammar; 2 | 3 | @SuppressWarnings("serial") 4 | public final class GdlVariable extends GdlTerm 5 | { 6 | 7 | private final String name; 8 | 9 | GdlVariable(String name) 10 | { 11 | this.name = name.intern(); 12 | } 13 | 14 | public String getName() 15 | { 16 | return name; 17 | } 18 | 19 | @Override 20 | public boolean isGround() 21 | { 22 | return false; 23 | } 24 | 25 | @Override 26 | public GdlSentence toSentence() 27 | { 28 | throw new RuntimeException("Unable to convert a GdlVariable to a GdlSentence!"); 29 | } 30 | 31 | @Override 32 | public String toString() 33 | { 34 | return name; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/AbstractSentenceDomainModel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | import org.ggp.base.util.gdl.grammar.Gdl; 7 | import org.ggp.base.util.gdl.grammar.GdlRule; 8 | import org.ggp.base.util.gdl.grammar.GdlSentence; 9 | 10 | import com.google.common.collect.Multimap; 11 | 12 | /** 13 | * Allows SentenceDomainModels to delegate their SentenceFormModel aspects 14 | * to an existing SentenceFormModel. 15 | */ 16 | public abstract class AbstractSentenceDomainModel implements SentenceDomainModel { 17 | private final SentenceFormModel formModel; 18 | 19 | protected AbstractSentenceDomainModel(SentenceFormModel formModel) { 20 | this.formModel = formModel; 21 | } 22 | 23 | /*package-private*/ SentenceFormModel getFormModel() { 24 | return formModel; 25 | } 26 | 27 | @Override 28 | public Set getIndependentSentenceForms() { 29 | return formModel.getIndependentSentenceForms(); 30 | } 31 | 32 | @Override 33 | public Set getConstantSentenceForms() { 34 | return formModel.getConstantSentenceForms(); 35 | } 36 | 37 | @Override 38 | public Multimap getDependencyGraph() { 39 | return formModel.getDependencyGraph(); 40 | } 41 | 42 | @Override 43 | public Set getSentencesListedAsTrue(SentenceForm form) { 44 | return formModel.getSentencesListedAsTrue(form); 45 | } 46 | 47 | @Override 48 | public Set getRules(SentenceForm form) { 49 | return formModel.getRules(form); 50 | } 51 | 52 | @Override 53 | public Set getSentenceForms() { 54 | return formModel.getSentenceForms(); 55 | } 56 | 57 | @Override 58 | public List getDescription() { 59 | return formModel.getDescription(); 60 | } 61 | 62 | @Override 63 | public SentenceForm getSentenceForm(GdlSentence sentence) { 64 | return formModel.getSentenceForm(sentence); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/GameFlowTester.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import org.ggp.base.util.game.Game; 4 | import org.ggp.base.util.game.GameRepository; 5 | 6 | public class GameFlowTester { 7 | //This doesn't really "test" the game flow so much as let us 8 | //examine it to evaluate it. 9 | public static void main(String[] args) throws InterruptedException { 10 | String gameName = "tictactoe"; 11 | Game theGame = GameRepository.getDefaultRepository().getGame(gameName); 12 | GameFlow flow = new GameFlow(theGame.getRules()); 13 | 14 | System.out.println("Size of flow: " + flow.getNumTurns()); 15 | System.out.println("Sentence forms in flow: " + flow.getSentenceForms()); 16 | for(int i = 0; i < flow.getNumTurns(); i++) { 17 | System.out.println("On turn " + i + ": " + flow.getSentencesTrueOnTurn(i)); 18 | } 19 | System.out.println("Turn after last: " + flow.getTurnAfterLast()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceDomainModel.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | 4 | /** 5 | * An extension of the SentenceFormModel that additionally 6 | * includes information about the domains of sentence forms. 7 | * In other words, this model specifies which constants can 8 | * be in which positions of each sentence form. 9 | * 10 | * The recommended way to create a SentenceDomainModel is 11 | * via {@link SentenceDomainModelFactory#createWithCartesianDomains(java.util.List)}. 12 | */ 13 | public interface SentenceDomainModel extends SentenceFormModel { 14 | /** 15 | * Gets the domain of a particular sentence form, which has 16 | * information about which particular sentences of the given 17 | * sentence form are possible. 18 | */ 19 | SentenceFormDomain getDomain(SentenceForm form); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceDomainModelFactory.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.ggp.base.util.gdl.grammar.Gdl; 7 | 8 | public class SentenceDomainModelFactory { 9 | private SentenceDomainModelFactory() { 10 | } 11 | 12 | public static ImmutableSentenceDomainModel createWithCartesianDomains(List description) throws InterruptedException { 13 | ImmutableSentenceFormModel formModel = SentenceFormModelFactory.create(description); 14 | 15 | SentenceFormsFinder sentenceFormsFinder = new SentenceFormsFinder(formModel.getDescription()); 16 | Map domains = sentenceFormsFinder.findCartesianDomains(); 17 | 18 | return ImmutableSentenceDomainModel.create(formModel, domains); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceForm.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.grammar.GdlConstant; 7 | import org.ggp.base.util.gdl.grammar.GdlSentence; 8 | import org.ggp.base.util.gdl.grammar.GdlTerm; 9 | 10 | /** 11 | * A sentence form captures the structure of a group of possible 12 | * GdlSentences. Two sentences have the same form if they have the 13 | * same name and include the same functions in the same place 14 | * 15 | * Implementations of SentenceForm should be immutable. They 16 | * should extend {@link AbstractSentenceForm} for implementations 17 | * of hashCode and equals that will be compatible with other 18 | * SentenceForms, as well as a recommended implementation of 19 | * toString. 20 | */ 21 | public interface SentenceForm { 22 | /** 23 | * Returns the name of all sentences with this form. 24 | */ 25 | GdlConstant getName(); 26 | 27 | /** 28 | * Returns a sentence form exactly like this one, except 29 | * with a new name. 30 | */ 31 | SentenceForm withName(GdlConstant name); 32 | 33 | /** 34 | * Returns true iff the given sentence is of this sentence form. 35 | */ 36 | boolean matches(GdlSentence relation); 37 | 38 | /** 39 | * Returns the number of constants and/or variables that a sentence 40 | * of this form contains. 41 | */ 42 | int getTupleSize(); 43 | 44 | /** 45 | * Given a list of GdlConstants and/or GdlVariables in the 46 | * order they would appear in a sentence of this sentence form, 47 | * returns that sentence. 48 | * 49 | * For the opposite operation (getting a tuple from a sentence), 50 | * see {@link GdlUtils#getTupleFromSentence(GdlSentence)} and 51 | * {@link GdlUtils#getTupleFromGroundSentence(GdlSentence)}. 52 | */ 53 | GdlSentence getSentenceFromTuple(List tuple); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceFormDomain.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import java.util.Set; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlConstant; 6 | import org.ggp.base.util.gdl.grammar.GdlSentence; 7 | 8 | /** 9 | * A SentenceFormDomain contains information about the possible 10 | * sentences of a particular sentence form within a game. In other 11 | * words, it captures information about which constants can be 12 | * in which positions in the SentenceForm. 13 | */ 14 | public interface SentenceFormDomain extends Iterable { 15 | /** 16 | * Returns the SentenceForm associated with this domain. 17 | */ 18 | SentenceForm getForm(); 19 | 20 | /** 21 | * Returns a set containing every constant that can appear in 22 | * the given slot index in the sentence form. 23 | */ 24 | Set getDomainForSlot(int slotIndex); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceForms.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import java.util.Collection; 4 | import java.util.Set; 5 | 6 | import org.ggp.base.util.gdl.grammar.GdlPool; 7 | 8 | import com.google.common.base.Predicate; 9 | import com.google.common.collect.Sets; 10 | 11 | public class SentenceForms { 12 | private SentenceForms() {} 13 | 14 | public static final Predicate TRUE_PRED = new Predicate() { 15 | @Override 16 | public boolean apply(SentenceForm input) { 17 | return input.getName() == GdlPool.TRUE; 18 | } 19 | }; 20 | public static final Predicate DOES_PRED = new Predicate() { 21 | @Override 22 | public boolean apply(SentenceForm input) { 23 | return input.getName() == GdlPool.DOES; 24 | } 25 | }; 26 | 27 | public static Set getNames(Collection forms) { 28 | Set names = Sets.newHashSet(); 29 | for (SentenceForm form : forms) { 30 | names.add(form.getName().getValue()); 31 | } 32 | return names; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/SentenceModelUtils.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model; 2 | 3 | import java.util.Set; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlSentence; 6 | 7 | 8 | public class SentenceModelUtils { 9 | private SentenceModelUtils() { 10 | } 11 | 12 | public static boolean inSentenceFormGroup(GdlSentence sentence, 13 | Set forms) { 14 | for(SentenceForm form : forms) 15 | if(form.matches(sentence)) 16 | return true; 17 | return false; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/assignments/AddibleFunctionInfo.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model.assignments; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlConstant; 6 | import org.ggp.base.util.gdl.grammar.GdlSentence; 7 | 8 | public interface AddibleFunctionInfo extends FunctionInfo { 9 | /** 10 | * Convenience method, equivalent to addTuple. 11 | */ 12 | void addSentence(GdlSentence value); 13 | 14 | /** 15 | * Adds a tuple to the known values for the sentence form. 16 | * Adjusts the function info accordingly. 17 | */ 18 | void addTuple(List sentenceTuple); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/assignments/AssignmentIterator.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model.assignments; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | 7 | import org.ggp.base.util.gdl.grammar.GdlConstant; 8 | import org.ggp.base.util.gdl.grammar.GdlVariable; 9 | 10 | 11 | public interface AssignmentIterator extends Iterator> { 12 | 13 | /** 14 | * Request that the next assignment change at least one 15 | * of the listed variables from its current assignment. 16 | */ 17 | void changeOneInNext(Collection varsToChange, 18 | Map assignment); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/assignments/Assignments.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model.assignments; 2 | 3 | import java.util.Map; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlConstant; 6 | import org.ggp.base.util.gdl.grammar.GdlVariable; 7 | 8 | 9 | //TODO: Get rid of this class in some way... 10 | //Or, just remake into AssignmentIterationPlan 11 | public interface Assignments extends Iterable> { 12 | 13 | AssignmentIterator getIterator(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/model/assignments/FunctionInfos.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.model.assignments; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import org.ggp.base.util.gdl.GdlUtils; 8 | import org.ggp.base.util.gdl.grammar.GdlSentence; 9 | import org.ggp.base.util.gdl.grammar.GdlTerm; 10 | import org.ggp.base.util.gdl.grammar.GdlVariable; 11 | 12 | public class FunctionInfos { 13 | public static Set getProducibleVars(FunctionInfo functionInfo, GdlSentence sentence) { 14 | if (!functionInfo.getSentenceForm().matches(sentence)) { 15 | throw new RuntimeException("Sentence "+sentence+" does not match constant form"); 16 | } 17 | 18 | List tuple = GdlUtils.getTupleFromSentence(sentence); 19 | List dependentSlots = functionInfo.getDependentSlots(); 20 | 21 | Set candidateVars = new HashSet(); 22 | //Variables that appear multiple times go into multipleVars 23 | Set multipleVars = new HashSet(); 24 | //...which, of course, means we have to spot non-candidate vars 25 | Set nonCandidateVars = new HashSet(); 26 | 27 | for(int i = 0; i < tuple.size(); i++) { 28 | GdlTerm term = tuple.get(i); 29 | if(term instanceof GdlVariable 30 | && !multipleVars.contains(term)) { 31 | GdlVariable var = (GdlVariable) term; 32 | if(candidateVars.contains(var) 33 | || nonCandidateVars.contains(var)) { 34 | multipleVars.add(var); 35 | candidateVars.remove(var); 36 | } else if(dependentSlots.get(i)) { 37 | candidateVars.add(var); 38 | } else { 39 | nonCandidateVars.add(var); 40 | } 41 | } 42 | } 43 | 44 | return candidateVars; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/scrambler/GdlScrambler.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.scrambler; 2 | 3 | import org.ggp.base.util.gdl.factory.exceptions.GdlFormatException; 4 | import org.ggp.base.util.gdl.grammar.Gdl; 5 | import org.ggp.base.util.symbol.factory.exceptions.SymbolFormatException; 6 | 7 | public interface GdlScrambler { 8 | public String scramble(Gdl x); 9 | public Gdl unscramble(String x) throws SymbolFormatException, GdlFormatException; 10 | public boolean scrambles(); 11 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/scrambler/NoOpGdlScrambler.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.scrambler; 2 | 3 | import org.ggp.base.util.gdl.factory.GdlFactory; 4 | import org.ggp.base.util.gdl.factory.exceptions.GdlFormatException; 5 | import org.ggp.base.util.gdl.grammar.Gdl; 6 | import org.ggp.base.util.symbol.factory.exceptions.SymbolFormatException; 7 | 8 | public class NoOpGdlScrambler implements GdlScrambler { 9 | @Override 10 | public String scramble(Gdl x) { 11 | return x.toString(); 12 | } 13 | @Override 14 | public Gdl unscramble(String x) throws SymbolFormatException, GdlFormatException { 15 | return GdlFactory.create(x); 16 | } 17 | @Override 18 | public boolean scrambles() { 19 | return false; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/gdl/transforms/ConstantChecker.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.gdl.transforms; 2 | 3 | import java.util.Set; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlSentence; 6 | import org.ggp.base.util.gdl.model.SentenceForm; 7 | import org.ggp.base.util.gdl.model.SentenceFormModel; 8 | 9 | /** 10 | * A ConstantChecker provides information about which sentences are true 11 | * for the constant sentence forms in a game. These can be computed once 12 | * at the beginning of a match, to avoid redundant computations. 13 | * 14 | * The preferred way to create a ConstantChecker is with 15 | * {@link ConstantCheckerFactory#createWithForwardChaining(org.ggp.base.util.gdl.model.SentenceDomainModel)}. 16 | */ 17 | public interface ConstantChecker { 18 | /** 19 | * Returns true iff the sentence is of a constant form included in 20 | * this ConstantChecker. 21 | */ 22 | boolean hasConstantForm(GdlSentence sentence); 23 | 24 | /** 25 | * Returns true iff the given sentence form is constant and is included 26 | * in this ConstantChecker. 27 | */ 28 | boolean isConstantForm(SentenceForm form); 29 | 30 | /** 31 | * Returns the set of all true sentences of the given constant 32 | * sentence form. 33 | */ 34 | Set getTrueSentences(SentenceForm form); 35 | 36 | /** 37 | * Returns the set of all constant sentence forms included 38 | * in this ConstantChecker. 39 | */ 40 | Set getConstantSentenceForms(); 41 | 42 | /** 43 | * Returns true iff the given sentence is of a constant 44 | * sentence form and is always true. 45 | */ 46 | boolean isTrueConstant(GdlSentence sentence); 47 | 48 | /** 49 | * Returns the sentence form model that the constant checker is based on. 50 | */ 51 | SentenceFormModel getSentenceFormModel(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/http/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.http; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.net.InetSocketAddress; 6 | import java.net.Socket; 7 | import java.util.Map; 8 | 9 | /** 10 | * HttpRequest is a helper class that encapsulates all of the code necessary 11 | * for a match host to issue a long-lived HTTP request to a player, wait for 12 | * the response, and return it. This is a key part of the GGP gaming protocol. 13 | * 14 | * @author schreib 15 | */ 16 | public final class HttpRequest 17 | { 18 | public static String issueRequest(String targetHost, int targetPort, String forPlayerName, String requestContent, int timeoutClock, Map extraHeaders) throws IOException { 19 | Socket socket = new Socket(); 20 | InetAddress theHost = InetAddress.getByName(targetHost); 21 | socket.connect(new InetSocketAddress(theHost.getHostAddress(), targetPort), 5000); 22 | HttpWriter.writeAsClient(socket, theHost.getHostName(), requestContent, forPlayerName, extraHeaders); 23 | String response = (timeoutClock < 0) ? HttpReader.readAsClient(socket) : HttpReader.readAsClient(socket, timeoutClock); 24 | socket.close(); 25 | return response; 26 | } 27 | 28 | public static String issueRequest(String targetHost, int targetPort, String forPlayerName, String requestContent, int timeoutClock) throws IOException { 29 | return issueRequest(targetHost, targetPort, forPlayerName, requestContent, timeoutClock, null); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/logging/LogSummaryGenerator.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.logging; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | 6 | public abstract class LogSummaryGenerator { 7 | public String getLogSummary(String matchId) { 8 | final String thePrefix = matchId; 9 | File logsDirectory = new File("logs"); 10 | FilenameFilter logsFilter = new FilenameFilter() { 11 | @Override 12 | public boolean accept(File dir, String name) { 13 | return name.startsWith(thePrefix); 14 | } 15 | }; 16 | String[] theMatchingMatches = logsDirectory.list(logsFilter); 17 | if (theMatchingMatches == null) { 18 | System.err.println("Log summary retrieval for " + matchId + " yielded an error."); 19 | } else if (theMatchingMatches.length > 1) { 20 | System.err.println("Log summary retrieval for " + matchId + " matched multiple matches."); 21 | } else if (theMatchingMatches.length == 0) { 22 | System.err.println("Log summary retrieval for " + matchId + " matched zero matches."); 23 | } else { 24 | return getSummaryFromLogsDirectory(logsDirectory + "/" + theMatchingMatches[0]); 25 | } 26 | return null; 27 | } 28 | 29 | public abstract String getSummaryFromLogsDirectory(String theLogsDirectory); 30 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/observer/Event.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.observer; 2 | 3 | public abstract class Event 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/observer/Observer.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.observer; 2 | 3 | public interface Observer 4 | { 5 | 6 | public void observe(Event event); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/observer/Subject.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.observer; 2 | 3 | public interface Subject 4 | { 5 | 6 | public void addObserver(Observer observer); 7 | 8 | public void notifyObservers(Event event); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/presence/PlayerPresence.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.presence; 2 | 3 | import java.io.IOException; 4 | 5 | import org.ggp.base.server.request.RequestBuilder; 6 | import org.ggp.base.util.http.HttpRequest; 7 | 8 | public class PlayerPresence { 9 | private final String host; 10 | private final int port; 11 | private String name; 12 | private String status; 13 | private long statusTime; 14 | 15 | PlayerPresence(String host, int port) { 16 | this.host = host; 17 | this.port = port; 18 | this.name = null; 19 | this.status = null; 20 | this.statusTime = 0; 21 | } 22 | 23 | public void updateInfo() { 24 | InfoResponse info; 25 | try { 26 | String infoFull = HttpRequest.issueRequest(host, port, "", RequestBuilder.getInfoRequest(), 1000); 27 | info = InfoResponse.create(infoFull); 28 | } catch (IOException e) { 29 | info = new InfoResponse(); 30 | info.setName(null); 31 | info.setStatus("error"); 32 | } 33 | synchronized(this) { 34 | name = info.getName(); 35 | status = info.getStatus(); 36 | statusTime = System.currentTimeMillis(); 37 | } 38 | } 39 | 40 | public synchronized String getName() { 41 | return name; 42 | } 43 | 44 | public synchronized String getStatus() { 45 | return status; 46 | } 47 | 48 | public synchronized long getStatusAge() { 49 | return System.currentTimeMillis() - statusTime; 50 | } 51 | 52 | public String getHost() { 53 | return host; 54 | } 55 | 56 | public int getPort() { 57 | return port; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/architecture/components/And.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.architecture.components; 2 | 3 | import org.ggp.base.util.propnet.architecture.Component; 4 | 5 | /** 6 | * The And class is designed to represent logical AND gates. 7 | */ 8 | @SuppressWarnings("serial") 9 | public final class And extends Component 10 | { 11 | /** 12 | * Returns true if and only if every input to the and is true. 13 | * 14 | * @see org.ggp.base.util.propnet.architecture.Component#getValue() 15 | */ 16 | @Override 17 | public boolean getValue() 18 | { 19 | for ( Component component : getInputs() ) 20 | { 21 | if ( !component.getValue() ) 22 | { 23 | return false; 24 | } 25 | } 26 | return true; 27 | } 28 | 29 | /** 30 | * @see org.ggp.base.util.propnet.architecture.Component#toString() 31 | */ 32 | @Override 33 | public String toString() 34 | { 35 | return toDot("invhouse", "grey", "AND"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/architecture/components/Constant.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.architecture.components; 2 | 3 | import org.ggp.base.util.propnet.architecture.Component; 4 | 5 | /** 6 | * The Constant class is designed to represent nodes with fixed logical values. 7 | */ 8 | @SuppressWarnings("serial") 9 | public final class Constant extends Component 10 | { 11 | /** The value of the constant. */ 12 | private final boolean value; 13 | 14 | /** 15 | * Creates a new Constant with value value. 16 | * 17 | * @param value 18 | * The value of the Constant. 19 | */ 20 | public Constant(boolean value) 21 | { 22 | this.value = value; 23 | } 24 | 25 | /** 26 | * Returns the value that the constant was initialized to. 27 | * 28 | * @see org.ggp.base.util.propnet.architecture.Component#getValue() 29 | */ 30 | @Override 31 | public boolean getValue() 32 | { 33 | return value; 34 | } 35 | 36 | /** 37 | * @see org.ggp.base.util.propnet.architecture.Component#toString() 38 | */ 39 | @Override 40 | public String toString() 41 | { 42 | return toDot("doublecircle", "grey", Boolean.toString(value).toUpperCase()); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/architecture/components/Not.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.architecture.components; 2 | 3 | import org.ggp.base.util.propnet.architecture.Component; 4 | 5 | /** 6 | * The Not class is designed to represent logical NOT gates. 7 | */ 8 | @SuppressWarnings("serial") 9 | public final class Not extends Component 10 | { 11 | /** 12 | * Returns the inverse of the input to the not. 13 | * 14 | * @see org.ggp.base.util.propnet.architecture.Component#getValue() 15 | */ 16 | @Override 17 | public boolean getValue() 18 | { 19 | return !getSingleInput().getValue(); 20 | } 21 | 22 | /** 23 | * @see org.ggp.base.util.propnet.architecture.Component#toString() 24 | */ 25 | @Override 26 | public String toString() 27 | { 28 | return toDot("invtriangle", "grey", "NOT"); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/architecture/components/Or.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.architecture.components; 2 | 3 | import org.ggp.base.util.propnet.architecture.Component; 4 | 5 | /** 6 | * The Or class is designed to represent logical OR gates. 7 | */ 8 | @SuppressWarnings("serial") 9 | public final class Or extends Component 10 | { 11 | /** 12 | * Returns true if and only if at least one of the inputs to the or is true. 13 | * 14 | * @see org.ggp.base.util.propnet.architecture.Component#getValue() 15 | */ 16 | @Override 17 | public boolean getValue() 18 | { 19 | for ( Component component : getInputs() ) 20 | { 21 | if ( component.getValue() ) 22 | { 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | 29 | /** 30 | * @see org.ggp.base.util.propnet.architecture.Component#toString() 31 | */ 32 | @Override 33 | public String toString() 34 | { 35 | return toDot("ellipse", "grey", "OR"); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/architecture/components/Transition.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.architecture.components; 2 | 3 | import org.ggp.base.util.propnet.architecture.Component; 4 | 5 | /** 6 | * The Transition class is designed to represent pass-through gates. 7 | */ 8 | @SuppressWarnings("serial") 9 | public final class Transition extends Component 10 | { 11 | /** 12 | * Returns the value of the input to the transition. 13 | * 14 | * @see org.ggp.base.util.propnet.architecture.Component#getValue() 15 | */ 16 | @Override 17 | public boolean getValue() 18 | { 19 | return getSingleInput().getValue(); 20 | } 21 | 22 | /** 23 | * @see org.ggp.base.util.propnet.architecture.Component#toString() 24 | */ 25 | @Override 26 | public String toString() 27 | { 28 | return toDot("box", "grey", "TRANSITION"); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/propnet/factory/LegacyPropNetFactory.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.propnet.factory; 2 | 3 | import java.util.List; 4 | 5 | import org.ggp.base.util.gdl.grammar.Gdl; 6 | import org.ggp.base.util.gdl.grammar.GdlRule; 7 | import org.ggp.base.util.logging.GamerLogger; 8 | import org.ggp.base.util.propnet.architecture.PropNet; 9 | import org.ggp.base.util.propnet.factory.converter.PropNetConverter; 10 | import org.ggp.base.util.propnet.factory.flattener.PropNetFlattener; 11 | import org.ggp.base.util.statemachine.Role; 12 | 13 | 14 | /** 15 | * The LegacyPropNetFactory class defines the creation of PropNets from game 16 | * descriptions. It has been superseded by the @OptimizingPropNetFactory 17 | * which has a more sophisticated approach to creating PropNets. 18 | */ 19 | public final class LegacyPropNetFactory 20 | { 21 | private LegacyPropNetFactory() { 22 | } 23 | 24 | /** 25 | * Creates a PropNet from a game description using the following process: 26 | *
    27 | *
  1. Flattens the game description to remove variables.
  2. 28 | *
  3. Converts the flattened description into an equivalent PropNet.
  4. 29 | *
30 | * 31 | * @param description 32 | * A game description. 33 | * @return An equivalent PropNet. 34 | */ 35 | public static PropNet create(List description) 36 | { 37 | try { 38 | List flatDescription = new PropNetFlattener(description).flatten(); 39 | GamerLogger.log("StateMachine", "Converting..."); 40 | return new PropNetConverter().convert(Role.computeRoles(description), flatDescription); 41 | } catch(Exception e) { 42 | GamerLogger.logStackTrace("StateMachine", e); 43 | return null; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/prover/Prover.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.prover; 2 | 3 | import java.util.Set; 4 | 5 | import org.ggp.base.util.gdl.grammar.GdlSentence; 6 | 7 | public interface Prover 8 | { 9 | public abstract Set askAll(GdlSentence query, Set context); 10 | public abstract GdlSentence askOne(GdlSentence query, Set context); 11 | public abstract boolean prove(GdlSentence query, Set context); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/prover/aima/knowledge/KnowledgeBase.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.prover.aima.knowledge; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | import org.ggp.base.util.gdl.grammar.Gdl; 10 | import org.ggp.base.util.gdl.grammar.GdlConstant; 11 | import org.ggp.base.util.gdl.grammar.GdlPool; 12 | import org.ggp.base.util.gdl.grammar.GdlRule; 13 | import org.ggp.base.util.gdl.grammar.GdlSentence; 14 | 15 | 16 | public final class KnowledgeBase 17 | { 18 | private final Map> contents; 19 | 20 | public KnowledgeBase(Set description) 21 | { 22 | contents = new HashMap>(); 23 | for (Gdl gdl : description) 24 | { 25 | GdlRule rule = (gdl instanceof GdlRule) ? (GdlRule) gdl : GdlPool.getRule((GdlSentence) gdl); 26 | GdlConstant key = rule.getHead().getName(); 27 | 28 | if (!contents.containsKey(key)) 29 | { 30 | contents.put(key, new ArrayList()); 31 | } 32 | contents.get(key).add(rule); 33 | } 34 | } 35 | 36 | public synchronized List fetch(GdlSentence sentence) 37 | { 38 | GdlConstant key = sentence.getName(); 39 | 40 | if (contents.containsKey(key)) 41 | { 42 | return contents.get(key); 43 | } 44 | else 45 | { 46 | return new ArrayList(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/reasoner/DifferentialForwardChainingReasoner.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.reasoner; 2 | 3 | import org.ggp.base.util.gdl.model.SentenceDomainModel; 4 | import org.ggp.base.util.gdl.transforms.VariableConstrainer; 5 | 6 | /** 7 | * An extension of the ForwardChainingReasoner that allows for finding 8 | * just the consequences of a rule that result from a particular input. 9 | * This can be a much more efficient way of handling recursive rules. 10 | */ 11 | public interface DifferentialForwardChainingReasoner 12 | extends ForwardChainingReasoner { 13 | /** 14 | * Given a rule, all sentences known to be true, and a set of new sentences, 15 | * returns all new results of the rule that involve at least one of the new 16 | * sentences as a positive literal in the body of the rule. Sentences already 17 | * known to be true will not be included in the result. 18 | * 19 | * This can be a more efficient way of dealing with recursive rules than 20 | * {@link #getRuleResults(Object, SentenceDomainModel, Object)}. 21 | * 22 | * For the outputs of this method to be valid, the GDL that the rule 23 | * is derived from should have had the {@link VariableConstrainer} 24 | * transformation applied to it. 25 | */ 26 | Sentences getRuleResultsForNewSentences(Rule rule, SentenceDomainModel domainModel, 27 | Sentences allSentences, Sentences newSentences) throws InterruptedException; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/reasoner/ForwardChainingReasoner.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.reasoner; 2 | 3 | import org.ggp.base.util.gdl.model.SentenceDomainModel; 4 | import org.ggp.base.util.gdl.transforms.VariableConstrainer; 5 | import org.ggp.base.util.reasoner.gdl.GdlChainingReasoner; 6 | 7 | /** 8 | * An interface for a forward-chaining reasoner. The interface is 9 | * parameterized in such a way that if a state machine (or other 10 | * code) is based on it, the underlying reasoner (and associated 11 | * representations of rules and sentences) can easily be swapped 12 | * out for another. 13 | * 14 | * See {@link GdlChainingReasoner} for one such implementation. 15 | */ 16 | public interface ForwardChainingReasoner { 17 | /** 18 | * Returns a set of sentences that are always true, which can be 19 | * used as a basis and added to via getUnion. This includes all 20 | * constant values defined explicitly in the game description. It 21 | * may include other sentences that are always true based on game 22 | * rules, depending on the implementation and how it is 23 | * instantiated. 24 | */ 25 | Sentences getConstantSentences(); 26 | 27 | /** 28 | * Given a rule and all sentences known to be true so far, returns 29 | * all new results of applying the rule. 30 | * 31 | * For the outputs of this method to be valid, the GDL that the rule 32 | * is derived from should have had the {@link VariableConstrainer} 33 | * transformation applied to it. 34 | */ 35 | Sentences getRuleResults(Rule rule, SentenceDomainModel domainModel, 36 | Sentences sentencesSoFar) throws InterruptedException; 37 | 38 | /** 39 | * Returns the union of the two sets of sentences. Calling this 40 | * method invalidates oldSentences. 41 | */ 42 | Sentences getUnion(Sentences oldSentences, Sentences newSentences); 43 | 44 | /** 45 | * Returns true iff newSentences is a subset of oldSentences. 46 | */ 47 | boolean isSubsetOf(Sentences oldSentences, Sentences newSentences); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/ggp/base/util/statemachine/MachineState.java: -------------------------------------------------------------------------------- 1 | package org.ggp.base.util.statemachine; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.ggp.base.util.gdl.grammar.GdlSentence; 7 | 8 | public class MachineState { 9 | public MachineState() { 10 | this.contents = null; 11 | } 12 | 13 | /** 14 | * Starts with a simple implementation of a MachineState. StateMachines that 15 | * want to do more advanced things can subclass this implementation, but for 16 | * many cases this will do exactly what we want. 17 | */ 18 | private final Set contents; 19 | public MachineState(Set contents) 20 | { 21 | this.contents = contents; 22 | } 23 | 24 | /** 25 | * getContents returns the GDL sentences which determine the current state 26 | * of the game being played. Two given states with identical GDL sentences 27 | * should be identical states of the game. 28 | */ 29 | public Set getContents() 30 | { 31 | return contents; 32 | } 33 | 34 | @Override 35 | public MachineState clone() { 36 | return new MachineState(new HashSet(contents)); 37 | } 38 | 39 | /* Utility methods */ 40 | @Override 41 | public int hashCode() 42 | { 43 | return getContents().hashCode(); 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | Set 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 | --------------------------------------------------------------------------------