Package org.bamboomy.c44.rest
Class ReactController
java.lang.Object
org.bamboomy.c44.rest.ReactController
@CrossOrigin(origins="http://localhost/",
maxAge=3600L)
@RestController
@RequestMapping("/react/")
public class ReactController
extends Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.web.servlet.view.RedirectViewRedirects to the currentPlayer method.GuiPlace[][]Takes a gameHash and userHash and returns the board rotated for that player as a JSON.intReturns the color as int for the userHash given, Green is 0, Blue 1, Red 2 and Yellow 3.currentColor(String hash) Returns the current color (as a String) of the game the user is playing in.currentPlayer(String hash) The describing String of how a player is doing.currentPlayer(String gameHash, String userHash) Returns whether the given userHash for the given gameHash is currently having its turn (as a boolean).booleanWhether the board is "dirty".
When a board situation is posted by the postBoard method this value is used to set the color by the user interface.booleanWhether the game is done.Returns the gameHash from the userHash, always returns 8ac4d9c3d324225fdbeedf99dc6a44a6 in this version.getAlliaceColor(String robotHash, String playerHash) Returns the color with which the playing color is in alliance with.A method used when play is begun: returns the color of the bot that is going to play (if a remote bot plays multiple colors).org.springframework.web.servlet.view.RedirectViewTakes a user-hash and redirects to the board-method.Whether the current player is check (if the given hash is the current player).booleanWhether the current playver is mate.voidIndicates that the mater wants to continue play (and the matee should contemplate kamikaze).Returns the last played moves of all the players.Performs a move (if the userHash is the current player for the given gameHash).voidPlays a move for the bot (if it's the current player).Rewrites the board content.voidThe postTurn method: changes the turn of the current user.Registers the color(s) the remote bot wants to play in this game.GuiPlace[][]robotBoard(String robotHash, String playerHash) Returns the robot board when the bot should currently pounder upon it's move.String[]Gets the initing robot hashes available (for the time being only one game is initing at the same time).robotOutput(String hash) Returns what the current robot is "thinking".voidRolls back the last move (will also be removed in the online version).updateOutput(String robotHash, String output) Sends the (debug) output of the bot to the server.
-
Constructor Details
-
ReactController
public ReactController()
-
-
Method Details
-
hello
@GetMapping("/getGame/{hash}") public org.springframework.web.servlet.view.RedirectView hello(@PathVariable("hash") String hash) Takes a user-hash and redirects to the board-method. The user-hash for this server is hard-coded, but will be replaced with hashes generated upon creation of the game and are taken from the database online.- Parameters:
hash- only bbad6bd689f97ce9e85f7815cdd47fa8 works in this version.- Returns:
-
board
@RequestMapping(path="/getBoard/{gameHash}/{userHash}", produces="application/json") public GuiPlace[][] board(@PathVariable("gameHash") String gameHash, @PathVariable("userHash") String userHash) Takes a gameHash and userHash and returns the board rotated for that player as a JSON. The JSON is not documented but should be human-readeable.- Parameters:
gameHash- The gameHash, hardcoded to 8ac4d9c3d324225fdbeedf99dc6a44a6 in this version.userHash- The userHash, the different userHashes can be found in the source-code.- Returns:
-
gameHash
Returns the gameHash from the userHash, always returns 8ac4d9c3d324225fdbeedf99dc6a44a6 in this version.- Parameters:
hash-- Returns:
-
amI
@GetMapping("/getIsCurrentPlayer/{hash}") public org.springframework.web.servlet.view.RedirectView amI(@PathVariable("hash") String hash) Redirects to the currentPlayer method.- Parameters:
hash-- Returns:
-
color
Returns the color as int for the userHash given, Green is 0, Blue 1, Red 2 and Yellow 3. (See also the Color enum in the source code for the other values).- Parameters:
hash-- Returns:
-
currentPlayer
@RequestMapping(path="/isCurrentPlayer/{gameHash}/{userHash}") public String currentPlayer(@PathVariable("gameHash") String gameHash, @PathVariable("userHash") String userHash) Returns whether the given userHash for the given gameHash is currently having its turn (as a boolean).- Parameters:
gameHash-userHash-- Returns:
-
play
@RequestMapping(path="/play/{gameHash}/{userHash}/{pieceHash}/{square}", produces="application/json") public ArrayList<ArrayList<GuiPlace>> play(@PathVariable("gameHash") String gameHash, @PathVariable("userHash") String userHash, @PathVariable("pieceHash") String pieceHash, @PathVariable("square") String square) Performs a move (if the userHash is the current player for the given gameHash).- Parameters:
gameHash- The gameuserHash- The userpieceHash- The piece the user wants to move (to be found in the JSON returned by the board method).square- The destination square the piece wants to move to (for Casteling you need to move the king two places). (Also given in the same JSON.)- Returns:
-
kamikaze
@RequestMapping(path="/kamikaze/{gameHash}/{userHash}") public void kamikaze(@PathVariable("gameHash") String gameHash, @PathVariable("userHash") String userHash) Indicates that the mater wants to continue play (and the matee should contemplate kamikaze). (A mated player is allowed to play one last "kamikaze"-move (it balances the game) once mate.) The point gained by mating this player is at peril until the other player in the allicance is mated a well. If you (or your ally) is mated; and you (or your ally) can still mate the last foe, your allicance gains 1.47 points. Mating the second enemy gains 1.3 points in total if you or your ally is not mated.- Parameters:
gameHash-userHash-
-
postTurn
@RequestMapping(path="/postTurn/{gameHash}/{turn}") public void postTurn(@PathVariable("gameHash") String gameHash, @PathVariable("turn") String turn) The postTurn method: changes the turn of the current user. This is a helper-method for debugging purposes only. It will not be present in the online version of the server.- Parameters:
gameHash-turn-
-
currentPlayer
@GetMapping("/getCurrentPlayerString/{hash}") public String currentPlayer(@PathVariable("hash") String hash) The describing String of how a player is doing. Gets a human readable description of the state a user is in (check for instance). Used by the user interface.- Parameters:
hash-- Returns:
-
currentColor
@GetMapping("/getCurrentColor/{hash}") public String currentColor(@PathVariable("hash") String hash) Returns the current color (as a String) of the game the user is playing in.- Parameters:
hash- The userHash of the game.- Returns:
-
lastMove
@RequestMapping(path="/lastMove/{hash}", produces="application/json") public ArrayList<GuiMove> lastMove(@PathVariable("hash") String userHash) Returns the last played moves of all the players. Used by the user interface. Retuned as JSON (again, not documented, should be understandable on its own).- Parameters:
userHash-- Returns:
-
isCheck
@RequestMapping(path="/isCheck/{hash}", produces="application/json") public String isCheck(@PathVariable("hash") String userHash) Whether the current player is check (if the given hash is the current player).- Parameters:
userHash-- Returns:
-
rollBack
@RequestMapping(path="/rollBack/{gameHash}") public void rollBack(@PathVariable("gameHash") String gameHash) Rolls back the last move (will also be removed in the online version).- Parameters:
gameHash-
-
robotOutput
Returns what the current robot is "thinking". After an initial message the input send to the updateOutput method is used.- Parameters:
hash-- Returns:
-
dirty
Whether the board is "dirty".
When a board situation is posted by the postBoard method this value is used to set the color by the user interface. Will also be removed online.- Parameters:
hash-- Returns:
-
robotHashes
@RequestMapping(path="/getInitingRobotHashes", produces="application/json") public String[] robotHashes()Gets the initing robot hashes available (for the time being only one game is initing at the same time).- Returns:
-
register
@RequestMapping(path="/register/{robotHash}/{colors}", produces="application/json") public String register(@PathVariable("robotHash") String robotHash, @PathVariable("colors") String colors) Registers the color(s) the remote bot wants to play in this game.- Parameters:
robotHash- One of the initing robot hashes of robotHashescolors- The colors, comma separated for examples: see the application.properties in the bots.- Returns:
- The hashes of the colors, in the same order as the colors are given.
-
robotBoard
@RequestMapping(path="/getRobotBoard/{robotHash}/{playerHash}", produces="application/json") public GuiPlace[][] robotBoard(@PathVariable("robotHash") String robotHash, @PathVariable("playerHash") String playerHash) Returns the robot board when the bot should currently pounder upon it's move. Sends null otherwise. (You can depend on this method to start letting your bot calculate).- Parameters:
robotHash-playerHash-- Returns:
-
playBot
@RequestMapping(path="/playBot/{robotHash}/{pieceHash}/{placeHash}", produces="application/json") public void playBot(@PathVariable("robotHash") String robotHash, @PathVariable("pieceHash") String pieceHash, @PathVariable("placeHash") String placeHash) Plays a move for the bot (if it's the current player). (See also the play method.)- Parameters:
robotHash-pieceHash-placeHash-
-
getColor
@RequestMapping(path="/getColor/{robotHash}/{playerHash}") public String getColor(@PathVariable("robotHash") String robotHash, @PathVariable("playerHash") String playerHash) A method used when play is begun: returns the color of the bot that is going to play (if a remote bot plays multiple colors).- Parameters:
robotHash-playerHash-- Returns:
-
getAlliaceColor
@RequestMapping(path="/getAllianceColor/{robotHash}/{playerHash}") public String getAlliaceColor(@PathVariable("robotHash") String robotHash, @PathVariable("playerHash") String playerHash) Returns the color with which the playing color is in alliance with. Allied colors try to defeat the other alliance. Allied colors cannot take each other pieces.- Parameters:
robotHash-playerHash-- Returns:
-
updateOutput
@PostMapping(value="/updateOutput/{robotHash}", consumes="text/html; charset=utf-8", produces="text/html; charset=utf-8") public String updateOutput(@PathVariable("robotHash") String robotHash, @RequestBody String output) Sends the (debug) output of the bot to the server. The output is shown in the interface (by the robotoutput method).- Parameters:
robotHash-output-- Returns:
-
postBoard
@PostMapping(value="/postBoard/{robotHash}", consumes="application/json", produces="text/html; charset=utf-8") public String postBoard(@PathVariable("robotHash") String robotHash, @RequestBody String boardJson) Rewrites the board content. After this method the postTurn must be called to continue the game.- Parameters:
robotHash-boardJson-- Returns:
-
isMate
@RequestMapping(path="/mate/{hash}", produces="application/json") public boolean isMate(@PathVariable("hash") String userHash) Whether the current playver is mate.- Parameters:
userHash-- Returns:
-
done
Whether the game is done.- Parameters:
hash-- Returns:
-