Package org.swtpra1

Class AIPlayer

  • Direct Known Subclasses:
    AlphaBetaPlayer, RandomPlayer, RelativeTerritoryPlayer

    public abstract class AIPlayer
    extends java.lang.Object
    Abstract class for all player implementations. Subclasses need to implement the calculateTurn functionality. To help with that the class offers functionality to calculate the possible turns given a position
    • Field Detail

      • DEFAULT_MAX_TURN_TIME

        public static final long DEFAULT_MAX_TURN_TIME
    • Constructor Detail

      • AIPlayer

        public AIPlayer()
    • Method Detail

      • calculateTurn

        public abstract Turn calculateTurn​(int gameId,
                                           Board board,
                                           int playerId,
                                           Turn enemyTurn)
        Calculates best turn in the players' view.
        Parameters:
        gameId - the id of the game that is being played
        board - the current board state
        playerId - our player id
        enemyTurn - the turn played by the enemy
        Returns:
        best possible turn
      • calculateTurn

        public abstract Turn calculateTurn​(int gameId,
                                           Board board,
                                           int playerId,
                                           Turn enemyTurn,
                                           long maxTurnTime)
        Calculates best turn in the players' view within a given timelimit.
        Parameters:
        gameId - the id of the game that is being played
        board - the current board state
        playerId - our player id
        enemyTurn - the turn played by the enemy
        maxTurnTime - the time we are given to calculate the turn in ms
        Returns:
        best possible turn
      • newGame

        public void newGame()
      • getAllPossibleTurns

        public static java.util.List<Turn> getAllPossibleTurns​(Board board,
                                                               int playerId)
        Get all possible turns of a player on the board.
        Parameters:
        board - The current board.
        playerId - The relative player id of the player whose possible turns we want to get.
        Returns:
        List of all possible turns a player can make.
      • generateQueensMoves

        protected static java.util.List<Square> generateQueensMoves​(Square startingSquare,
                                                                    Board board)
        Gets the Squares a queen can move to from a given square It is used to generate the queen and shot squares.
        Parameters:
        startingSquare - The start square.
        board - The current board.
        Returns:
        The list of squares where a queen can go.