public interface GameInterface
For your convenience in generating JSON strings, version 1.1.1 of the following library is provided in the class path of the GameManager.
If you'd like or require additional libraries they can be added to the class path easily by modifying the following export in /BotBattleApp/custom_modules/BotBattlePaths.js
This has been simplified to emphasize the order in which the game interface methods are called. The actual Main Game Loop can be found in ArenaGameInstance.java. Familiarizing yourself with the game loop's structure and the order and timing in which the interface methods are called should make the life of a game developer much easier.
runArenaGame() { game.initializeGame(gameType) game.getInitialGameStateJSON() while (!game.isGameOver()) { int player = game.getPlayerForCurrentTurn() if (player == 1) { board = game.getPlayerOneBoard() timeout = game.getBotTimeoutInMilliseconds() } else { board = game.getPlayerTwoBoard() if (gameType == BOT_VS_HUMAN) timeout = game.getHumanTimeoutInMilliseconds() else timeout = game.getBotTimeoutInMilliseconds() } move = Get move from player(board, timeout) reasonMoveWasInvalid = game.validateMove(move, player); if (reasonMoveWasInvalid == null) game.updateBoard(move, stderr, player); game.getMidGameStateJSON(jsonSafeMove, jsonSafeStderrArray, player) } else { Send invalid move message to TestArena } } game.getFinalGameStateJSON() }
Modifier and Type | Method and Description |
---|---|
int |
getBotTimeoutInMilliseconds()
Number of milliseconds to wait for a bot's move (via their stdout stream) before
giving up and reporting a "null" move.
|
java.lang.String |
getCompleteBoard()
Currently unused
The idea was to combine both player 1 and player 2's view of the board into an
overall string representation of the board.
|
java.lang.String |
getFinalGameStateJSON()
A string containing a valid FinalGameState as defined in the documentation.
|
int |
getHumanTimeoutInMilliseconds()
Number of milliseconds to wait for a human's move (via their stdout stream) before
giving up and reporting a "null" move.
|
java.lang.String |
getInitialGameStateJSON()
A string containing a valid InitialGameState as defined in the documentation.
|
java.lang.String |
getMidGameStateJSON(java.lang.String jsonSafeMove,
java.lang.String jsonSafeStderrArray,
int player)
A string containing a valid MidGameState as defined in the documentation.
|
java.lang.String |
getName()
Currently unused.
|
int |
getPlayerForCurrentTurn()
Return the player number of the current turn (iteration of the game loop).
|
java.lang.String |
getPlayerOneBoard()
Called when getPlayerForCurrentTurn() has indicated that it's
player 1's turn.
|
java.lang.String |
getPlayerTwoBoard()
Called when getPlayerForCurrentTurn() has indicated that it's player 2's turn.
|
void |
initializeGame(GameType gameType)
Called before any other interface methods.
|
boolean |
isGameOver()
Used as the control for the main game loop.
|
void |
updateBoard(java.lang.String move,
int player)
Update internal state of the board based on a valid move.
|
java.lang.String |
validateMove(java.lang.String move,
int player)
Determine if the player's move was valid, and provide the reason if not.
|
java.lang.String getName()
void initializeGame(GameType gameType)
gameType
- A GameType enum specifying BotVsBot or BotVsHuman.java.lang.String getInitialGameStateJSON()
java.lang.String getMidGameStateJSON(java.lang.String jsonSafeMove, java.lang.String jsonSafeStderrArray, int player)
jsonSafeMove
- The player's move, cleaned with JSONSimple's
JSONValue.toJSONString(...) method.jsonSafeStderrArray
- A String representing a JSON array of
new line separated strings received from the player since the
last turn, cleaned with JSONSimple's JSONValue.toJSONString(...) method.player
- Either 1 or 2.java.lang.String getFinalGameStateJSON()
java.lang.String validateMove(java.lang.String move, int player)
move
- The last line received from the players standard output streamplayer
- Either 1 or 2.void updateBoard(java.lang.String move, int player)
move
- The last line received from the players standard output streamplayer
- Either 1 or 2.boolean isGameOver()
int getBotTimeoutInMilliseconds()
int getHumanTimeoutInMilliseconds()
int getPlayerForCurrentTurn()
java.lang.String getPlayerOneBoard()
java.lang.String getPlayerTwoBoard()
java.lang.String getCompleteBoard()