Class ReactController

java.lang.Object
org.bamboomy.c44.rest.ReactController

@CrossOrigin(origins="http://localhost/", maxAge=3600L) @RestController @RequestMapping("/react/") public class ReactController extends Object
Class which handles the communication with the engine.
  • 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.
      Parameters:
      hash - is written in the jsp so old games can be retrieved
      Returns:
      a redirect view (see) getBoard
    • board

      @RequestMapping(path="/getBoard/{gameHash}/{userHash}", produces="application/json") public org.bamboomy.c44.react.board.gui.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 - A gameHash, hardcoded in the ColorControler (and also visible in the jsp).
      userHash - A userHash, the different userHashes can be found in the jsp.
      Returns:
      a json which represents the current state of the board (for parsing see internal methods of the Robots
    • gameHash

      @GetMapping("/getGameHash/{hash}") public String gameHash(@PathVariable("hash") String hash)
      Returns the gameHash from the given userHash.
      Parameters:
      hash - the userHash (robot or player)
      Returns:
      the corresponding game hash.
    • amI

      @GetMapping("/getIsCurrentPlayer/{hash}") public org.springframework.web.servlet.view.RedirectView amI(@PathVariable("hash") String hash)
      Redirects to the currentPlayer method.
      Parameters:
      hash - a player hash
      Returns:
      a redirect to isCurrentPlayer (see the currentPlayer method)
    • color

      @GetMapping("/getMyColor/{hash}") public int color(@PathVariable("hash") String hash)
      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). If a debug value is set in the interface (see postTurn) this color is used.
      Parameters:
      hash - the player hash
      Returns:
      the color
    • allayColor

      @GetMapping("/getAllayColor/{hash}") public int allayColor(@PathVariable("hash") String hash)
      Returns the AllyColor of the given player.
      Parameters:
      hash - A player hash.
      Returns:
      The color of the Ally.
    • 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 (String) boolean ("true" or "false")).
      Parameters:
      gameHash - the gameHash
      userHash - the userHash
      Returns:
      whether the userHash is the current player for the given game
    • play

      @RequestMapping(path="/play/{gameHash}/{userHash}/{pieceHash}/{square}", produces="application/json") public ArrayList<ArrayList<org.bamboomy.c44.react.board.gui.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). If you are in "debug-mode" (you posted a board situation, you choose a debug color, the interface is turned to this color). (see also postTurn and postDebugColor) That move is sent to the bot as the only move possible (so you can investigate why it did (or didn't) do a certain move...).
      Parameters:
      gameHash - The game
      userHash - The user
      pieceHash - 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 (also found in this json).
      Returns:
      a json which can be ignored
    • 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 allyance is mated a well. If you (or your ally) is mated; and you (or your ally) can still mate the last foe, your allyance gains 1.47 points. Mating the second enemy gains 1.3 points in total if you or your ally is not mated.
      Parameters:
      gameHash - the gameHash
      userHash - the userHash
    • postTurn

      @RequestMapping(path="/postTurn/{gameHash}/{turn}/{debug}") public void postTurn(@PathVariable("gameHash") String gameHash, @PathVariable("turn") String turn, @PathVariable("debug") String debug)
      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 - the gameHash
      turn - the desired turn
      debug - whether the user wants to debug
    • postDebugColor

      @RequestMapping(path="/postDebugColor/{gameHash}/{turn}") public void postDebugColor(@PathVariable("gameHash") String gameHash, @PathVariable("turn") String turn)
      The postDebugColor method: Not implemented at the time of writing. This is a helper-method for debugging purposes only. It will not be present in the online version of the server.
      Parameters:
      gameHash - the gameHash
      turn - the color to be debugged
    • showDebugColor

      @RequestMapping(path="/showDebugColor/{gameHash}") public String showDebugColor(@PathVariable("gameHash") String gameHash)
      The showDebugColor method: whether the debug dialog should be shown. The user interface needs this to show the debug dialog once a board has been posted. This is a helper-method for debugging purposes only. It will not be present in the online version of the server.
      Parameters:
      gameHash - the
      Returns:
      a boolean indicating this
    • 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 - the gamehash
      Returns:
      the described String
    • 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:
      the color
    • lastMove

      @RequestMapping(path="/lastMove/{hash}", produces="application/json") public ArrayList<org.bamboomy.c44.react.board.gui.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 - the userhash
      Returns:
      the last moves of that game
    • 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 - the userHash
      Returns:
      a boolean indicating this
    • robotOutput

      @GetMapping("/robotOutput/{hash}") public String robotOutput(@PathVariable("hash") String hash)
      Returns what the current robot is "thinking". After an initial message the input send to the updateOutput method is used.
      Parameters:
      hash - the userHash
      Returns:
      what the bot is thinking (debug info, can be anything)
    • dirty

      @GetMapping("/dirty/{hash}") public boolean dirty(@PathVariable("hash") String hash)
      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 - the player hash
      Returns:
      the boolean indicating this
    • robotBoard

      @RequestMapping(path="/getRobotBoard/{colorHash}", produces="application/json") public org.bamboomy.c44.react.board.gui.GuiPlace[][] robotBoard(@PathVariable("colorHash") String colorHash)
      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:
      colorHash - the colorHash
      Returns:
      either the board or null, if the return value is not null the bot is expected to play
    • playBot

      @RequestMapping(path="/playBot/{colorHash}/{pieceHash}/{placeHash}", produces="application/json") public void playBot(@PathVariable("colorHash") String colorHash, @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:
      colorHash - the colorHash of the bot
      pieceHash - The piece the bot wants to move (to be found in the JSON returned by the board method).
      placeHash - The destination square the piece wants to move to (also found in this json).
    • getColorFromHash

      @RequestMapping(path="/getColor/{colorHash}") public String getColorFromHash(@PathVariable("colorHash") String colorHash)
      A method used to indicate with which color the bot needs to play (if it plays different colors in the same game). Returns the color of the bot that is going to play (if a remote bot plays multiple colors).
      Parameters:
      colorHash - the colorHash
      Returns:
      the color
    • getAlliaceColor

      @RequestMapping(path="/getAllianceColor/{colorHash}") public String getAlliaceColor(@PathVariable("colorHash") String colorHash)
      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:
      colorHash - the colorHash
      Returns:
      the ally color as a String
    • updateOutput

      @PostMapping(value="/updateOutput/{colorHash}", consumes="text/html; charset=utf-8", produces="text/html; charset=utf-8") public String updateOutput(@PathVariable("colorHash") String colorHash, @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:
      colorHash - the colorHash
      output - the output
      Returns:
      always "ok"
    • 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. This is a helper-method for debugging purposes only. It will not be present in the online version of the server.
      Parameters:
      robotHash - the robotHash
      boardJson - the json replacing the current board
      Returns:
      always "ok"
    • isMate

      @RequestMapping(path="/mate/{hash}", produces="application/json") public boolean isMate(@PathVariable("hash") String userHash)
      Whether the current player is mate.
      Parameters:
      userHash - the userHash
      Returns:
      a boolean whether (s)he is mate
    • done

      @GetMapping("/done/{hash}") public boolean done(@PathVariable("hash") String hash)
      Whether the game is done.
      Parameters:
      hash - the userHash
      Returns:
      a boolean
    • finished

      @GetMapping("/finished/{hash}") public boolean finished(@PathVariable("hash") String hash)
      Whether the game is finished. (This is called when the game is retrieved from the jsp.)
      Parameters:
      hash - the player hash
      Returns:
      whether the game is finished
    • robotHash

      @GetMapping("/robotHash/{hash}") public String robotHash(@PathVariable("hash") String hash)
      The robotHash, used in the editor. Is used by the editor to send the game to the engine.
      Parameters:
      hash - unused
      Returns:
      the robotHash of the currently active game
    • calculateMovez

      @RequestMapping(path="/calculateMovez/{robotHash}") public String calculateMovez(@PathVariable("robotHash") String robotHash)
      The calculateMovez call, used for legacy reasons and will not be present in the online version. Is used by the editor to request calculating the moves.
      Parameters:
      robotHash - the robotHash of the currently active game (see robotHash)
      Returns:
      always returns "ok"
    • isMoveMade

      @GetMapping("/isMoveMade/{hash}") public String isMoveMade(@PathVariable("hash") String hash)
      Blocks until a move is made in robot play to update the user interface.
      Parameters:
      hash - the user hash
      Returns:
      always "ok" (but only after a (robot) move is played)
    • getName

      @PostMapping(value="/getName/{colorHash}", consumes="text/html; charset=utf-8", produces="text/html; charset=utf-8") public String getName(@PathVariable("colorHash") String colorHash, @RequestBody String name)
      POSTs the name of the bot, for interface reasons.
      Parameters:
      colorHash - the colorHash
      name - the name
      Returns:
      always "ok"
    • numberOfMove

      @RequestMapping(path="/numberOfMove/{colorHash}") public String numberOfMove(@PathVariable("colorHash") String colorHash)
      The current count of the moves (used in the jsp).
      Parameters:
      colorHash - the colorHash
      Returns:
      the count of the number of moves.
    • adjucate

      @RequestMapping(path="/adjucate/{colorHash}") public String adjucate(@PathVariable("colorHash") String colorHash)
      What the judge adjucates. (This is always "STOP" as bots are not required (yet) to be able to continue game once one mate is reached.)
      Parameters:
      colorHash - the colorHash
      Returns:
      the adjucation
    • exception

      @PostMapping(value="/exception/{robotHash}", consumes="text/html; charset=utf-8", produces="text/html; charset=utf-8") public String exception(@PathVariable("robotHash") String robotHash, @RequestBody String stack)
      A post-endpoint for communicating an exception to the engine. If an exception has occured in the bot you can post it to this endpoint, it stops the game and displays the exception (and stack) to the front-end.

      You are not obliged to post exceptions to the engine but you are required to make a move in the given time, even if exceptions occur.

      This is a helper-method for debugging purposes only.

      It will not be present in the online version of the server.
      Parameters:
      robotHash - the robotHash
      stack - the stack
      Returns:
      always "ok"
    • getException

      @RequestMapping(path="/getException/{colorHash}") public String getException(@PathVariable("colorHash") String colorHash)
      A getter for the exception (see exception). Blocks game, so use with prudence. Handy if you want to have an exception-free bot. The only requirement at the time of writing is that exceptions can occur, but the bot is required to make it's move (within 3 minutes).
      Parameters:
      colorHash - the colorHash
      Returns:
      the exception given to the exception method
    • getResult

      @RequestMapping(path="/result/{colorHash}") public String getResult(@PathVariable("colorHash") String colorHash)
      The final result of the game.
      Parameters:
      colorHash - the colorHash
      Returns:
      the final result
    • getTemporaryResult

      @RequestMapping(path="/temporaryResult/{colorHash}") public String getTemporaryResult(@PathVariable("colorHash") String colorHash)
      A mid-game result.
      Parameters:
      colorHash - the colorHash
      Returns:
      the temporary result
    • getTemporarySituation

      @RequestMapping(path="/finalSituation/{colorHash}") public String getTemporarySituation(@PathVariable("colorHash") String colorHash)
      The final situation once the game ended (is used to pass the winners and points to the interface).
      Parameters:
      colorHash - the colorHash
      Returns:
      the final situation as a String
    • setDone

      @RequestMapping(path="/setDone/{colorHash}") public String setDone(@PathVariable("colorHash") String colorHash)
      Sets the game to done. This is a helper-method for debugging purposes only. It will not be present in the online version of the server.
      Parameters:
      colorHash - the color hash
      Returns:
      always "ok"