Class Bot


public final class Bot
extends AbstractBot
This class represents a Bot running on the server. It has methods to login the Bot to the Server, enter a game, fetch list of rooms, join a room, etc. Bots are instantiated in the setUpGame() method of the Game class
  • Field Details

    • lastErrorCode

      public volatile int lastErrorCode
    • debugEnabled

      public final boolean debugEnabled
      indicates whether debug messages will be logged for this bot or not
  • Constructor Details

    • Bot

      public Bot()
      Creates a Bot
    • Bot

      public Bot​(boolean enableDebug)
      Creates a Bot
      Parameters:
      enableDebug - - specifies whether debug messages should be logged for this bot or not
    • Bot

      public Bot​(BotTurnDelayType turnDelayType)
      Creates a Bot
      Parameters:
      turnDelayType - - specifies the turn delay type for this bot (fast, normal, slow or no delay)
    • Bot

      public Bot​(BotTurnDelayType turnDelayType, boolean enableDebug)
      creates a Bot
      Parameters:
      turnDelayType - - specifies the turn delay type for this bot (fast, normal, slow or no delay)
      enableDebug - - specifies whether debug messages should be logged for this bot or not
  • Method Details

    • logIn

      public void logIn​(String name, int avtarId, String gameName)
      Attempts to Login a Bot onto server with emailId and starts a new session
      Parameters:
      name - - the Bot name
      avtarId - - the bot avatar Id
      gameName - - the game which should be linked with this Bot session on successful login - cannot be null
    • sendJsonMessage

      public void sendJsonMessage​(String command, JsonObject data)
      Attempts to Send a json message to the server
      Parameters:
      command - - the message command
      data - - the message data as json
    • sendTxtMessage

      public void sendTxtMessage​(String command, String data)
      Attempts to Send a text message to the server
      Parameters:
      command - - the message command
      data - - the message data as string
    • sendBinaryMessage

      public void sendBinaryMessage​(String command, byte[] data)
      Attempts to sends a binary message to the server
      Parameters:
      command - - the message command
      data - - the message data as a byte array
    • getPollData

      protected final String getPollData()
      Internal method. Do not touch
      Specified by:
      getPollData in class AbstractBot
    • changeAvtar

      public void changeAvtar​(int avtarId)
      Attempts to Change the avtarId of this Bot
      Parameters:
      avtarId - - the new avtar ID
    • logOut

      public void logOut()
      Attempts to Logout this bot from the server
    • getLocations

      public void getLocations()
      Fetches the list of game locations from the server
    • getRooms

      public void getRooms​(String location, RoomType roomType)
      Fetches the list of rooms from the server
      Parameters:
      location - - the location whose rooms should be fetched
      roomType - - the room type - normal or fast
    • joinRoom

      public void joinRoom​(long roomId)
      Attempts to Make the Bot session join the specified room.
      Parameters:
      roomId - - the roomId of the room to join
    • refreshRoomFromServer

      public void refreshRoomFromServer()
      Attempts to refresh the room state(data) from the server
    • takeSeat

      public void takeSeat​(long roomId, int seatNo, JsonObject data)
      Attempts to take a seat in the room. Until the Bot is seated he/she remains a spectator and cannot take part in the game play. The seat numbers are numbered 1 to n.
      Parameters:
      roomId - - the roomId of the room to join
      seatNo - - the seat number to sit on - starting from 1
      data - - additional data sent along with the take seat command to the server. For eg. in Poker this could be the chips to put on table
    • leaveSeat

      public void leaveSeat()
      Attempts to leave the seat in the room.
    • leaveRoom

      public void leaveRoom()
      Attempts to leave the room.
    • processCommand

      protected final void processCommand​(String command, String data)
      internal method. Do not touch
      Specified by:
      processCommand in class AbstractBot
      Parameters:
      command - -
      data - -
    • processCommand

      protected final void processCommand​(String command, byte[] data)
      internal method. Do not touch
      Specified by:
      processCommand in class AbstractBot
      Parameters:
      command - -
      data - -
    • setBotEventListener

      public final void setBotEventListener​(BotEventListener botEventListener)
      Sets the BotEventListener to which the bot's events/callbacks will be forwarded
      Parameters:
      botEventListener - - the BotEventListener that will handle the Bot's events/callbacks
    • getUserId

      public String getUserId()
      Returns the user ID of the Bot.
      Returns:
      - the user ID of the bot
    • getSessionId

      public String getSessionId()
      Returns the Bot sessionId
      Returns:
      - Bot sessionId
    • getName

      public String getName()
      Returns the name of the Bot
      Returns:
      - the name of the Bot
    • getAvtarId

      public int getAvtarId()
      Returns the avtarId of the bot
      Returns:
      - the avtarId of the bot
    • getGameName

      public String getGameName()
      returns the Name of the game that this Bot is linked to
      Returns:
      - the Name of the game that this Bot is linked to
    • getGameUserData

      public JsonObject getGameUserData()
      Returns the Game Specific User Data of the Bot
      Returns:
      - the Game Specific User Data of the Bot
    • isLoggedIn

      public boolean isLoggedIn()
      Returns whether this Bot is loggedIn to the server or not
      Returns:
      - true if this Bot is loggedIn to the server
    • getJoinedRoom

      public Room getJoinedRoom()
      Returns the room joined by this bot or null if no room has been joined
      Returns:
      - the room joined by this bot
    • hasJoinedRoom

      public boolean hasJoinedRoom()
      Checks if Bot has joined a room. Returns true if this Bot has joined a room
      Returns:
      - true if this Bot has joined a room
    • isSpectator

      public boolean isSpectator()
      Checks if Bot is a spectator. Returns true if this Bot has joined a room and is a spectator
      Returns:
      - true if this Bot has joined a room and is a spectator
    • isSeated

      public boolean isSeated()
      Checks if this Bot is seated. Returns true if this Client is seated in a room.
      Returns:
      - true if this Bot is seated in a room.
    • isGamePlayInProgress

      public boolean isGamePlayInProgress()
      Checks if Game play is in progress. Returns true if this Bot has joined a room and Game play is in progress in the room.
      Returns:
      - true if this Bot has joined a room and Game play is in progress in the room.
    • isActivePlayer

      public boolean isActivePlayer()
      Checks if this Bot is an active player. Returns true if this Bot is seated in a room and is taking part in the current game play in the room..
      Returns:
      - true if this Bot is seated in a room and is taking part in the current game play in the room..
    • getPlayer

      public Player getPlayer()
      Returns the player object associated with this Bot or null if the Bot is not seated
      Returns:
      - the player object associated with this Bot or null if the Bot is not seated
    • isCurTurn

      public boolean isCurTurn()
      Returns true if the current turn belongs to this Bot.
      Returns:
      - true if the current turn belongs to this Boy.
    • playAction

      public final void playAction​(String action, JsonObject actionData) throws GamePlayNotInProgressException
      Attempts to Play an action. Sends a playAction message to the Server.
      Parameters:
      action - - the action played
      actionData - - the data associated with the action
      Throws:
      GamePlayNotInProgressException - - if GamePlay is not in progress
    • debug

      public final void debug​(String txt)
      Outputs a debug message if debug is enabled for this Bot
      Parameters:
      txt - - the debug message