Class AlphaBetaPlayer

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected AlphaBetaSearchTree alphaBeta
      Implementation of the Negamax tree with AlphaBetaSearchTree pruning.
      long bufferTime
      a buffer time in millisecond that is used to ensure there is enough time to interrupt any ongoing calculations and encode the response turn after the time for actual calculations has run out.
      int depth
      the depth of the game tree that should be searched.
      Evaluator evaluator
      the evaluator that is used to evaluate positions of the game.
      protected java.util.concurrent.ExecutorService executor
      Thread for turn calculation.
      boolean iterativeDeepening
      enables iterative deepening which uses all of the turn time to try and calculate evaluations for progressively deeper depths.
      protected OpeningBook openingBook
      opening book that is used for all games played by this instance.
      java.io.File openingBookFile
      path to the opening book that should be used; null if disabled.
      int parallelism
      target parallelism for the negamax algorithm.
      boolean presort
      enables presort which presorts all Turns and cuts a on depth depending part of the bad valued Turns.
    • Constructor Summary

      Constructors 
      Constructor Description
      AlphaBetaPlayer()
      create an AlphaBetaPlayer with default values.
      AlphaBetaPlayer​(Evaluator evaluator, int depth, boolean iterativeDeepening, long bufferTime, int parallelism, java.io.File openingBookFile, boolean presort)
      Player instance that can can be fully customized.
    • Field Detail

      • evaluator

        public final Evaluator evaluator
        the evaluator that is used to evaluate positions of the game.
      • depth

        public final int depth
        the depth of the game tree that should be searched. this is considered a minimum depth if iterative deepening is enabled.
      • iterativeDeepening

        public final boolean iterativeDeepening
        enables iterative deepening which uses all of the turn time to try and calculate evaluations for progressively deeper depths.
      • bufferTime

        public final long bufferTime
        a buffer time in millisecond that is used to ensure there is enough time to interrupt any ongoing calculations and encode the response turn after the time for actual calculations has run out.
      • parallelism

        public final int parallelism
        target parallelism for the negamax algorithm.

        should not be set to be higher than the available logical processors. high parallelism can evaluate more positions but decreases the effectiveness of alpha-beta-pruning. value 0 uses the amount of logical processors available as the target parallelism. value 1 disables parallel execution and uses a sequential version of negamax.

      • openingBookFile

        public final java.io.File openingBookFile
        path to the opening book that should be used; null if disabled.
      • presort

        public final boolean presort
        enables presort which presorts all Turns and cuts a on depth depending part of the bad valued Turns.
      • openingBook

        protected final OpeningBook openingBook
        opening book that is used for all games played by this instance.
      • executor

        protected final java.util.concurrent.ExecutorService executor
        Thread for turn calculation.
      • alphaBeta

        protected AlphaBetaSearchTree alphaBeta
        Implementation of the Negamax tree with AlphaBetaSearchTree pruning.
    • Constructor Detail

      • AlphaBetaPlayer

        public AlphaBetaPlayer()
        create an AlphaBetaPlayer with default values.
      • AlphaBetaPlayer

        public AlphaBetaPlayer​(Evaluator evaluator,
                               int depth,
                               boolean iterativeDeepening,
                               long bufferTime,
                               int parallelism,
                               java.io.File openingBookFile,
                               boolean presort)
        Player instance that can can be fully customized.
        Parameters:
        evaluator - see evaluator
        depth - see depth
        iterativeDeepening - see iterativeDeepening
        bufferTime - see bufferTime
        parallelism - see parallelism
        openingBookFile - see openingBookFile
        presort - see presort
    • Method Detail

      • calculateTurn

        @NotNull
        public @NotNull Turn calculateTurn​(int gameId,
                                           Board board,
                                           int playerId,
                                           @Nullable
                                           @Nullable Turn enemyTurn)
        Wrapper method to calculate the turn the player will take if turn time is unlimited.
        Specified by:
        calculateTurn in class AIPlayer
        Parameters:
        gameId - the running game
        board - the current board state
        playerId - the id (0 or 1) of the player who we play
        enemyTurn - what the enemy did in his last turn
        Returns:
        the turn we will play
      • calculateTurn

        public Turn calculateTurn​(int gameId,
                                  Board board,
                                  int playerId,
                                  Turn enemyTurn,
                                  long maxTurnTime)
        Calculate the best possible turn for a board state in limited time.
        Specified by:
        calculateTurn in class AIPlayer
        Parameters:
        gameId - the running game
        board - the current board state
        playerId - the id (0 or 1) of the player who we play
        enemyTurn - what the enemy did in his last turn
        maxTurnTime - the time we have to find our turn
        Returns:
        the turn we will play