Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     Texel - A UCI chess engine.
  3.     Copyright (C) 2012-2014  Peter Ă–sterlund, peterosterlund2@gmail.com
  4.  
  5.     This program is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. /*
  20.  * computerPlayer.hpp
  21.  *
  22.  *  Created on: Feb 25, 2012
  23.  *      Author: petero
  24.  */
  25.  
  26. #ifndef COMPUTERPLAYER_HPP_
  27. #define COMPUTERPLAYER_HPP_
  28.  
  29. #include "player.hpp"
  30. #include "transpositionTable.hpp"
  31. #include "book.hpp"
  32. #include "search.hpp"
  33.  
  34. #include <string>
  35. #include <memory>
  36.  
  37. class ComputerPlayerTest;
  38.  
  39. /**
  40.  * A computer algorithm player.
  41.  */
  42. class ComputerPlayer : public Player {
  43.     friend class ComputerPlayerTest;
  44. public:
  45.     static std::string engineName;
  46.     bool verbose;
  47.  
  48.     ComputerPlayer();
  49.     ComputerPlayer(const ComputerPlayer& other) = delete;
  50.     ComputerPlayer& operator=(const ComputerPlayer& other) = delete;
  51.  
  52.     void setTTLogSize(int logSize);
  53.  
  54.     void setListener(const std::shared_ptr<Search::Listener>& listener);
  55.  
  56.     std::string getCommand(const Position& posIn, bool drawOffer, const std::vector<Position>& history) override;
  57.  
  58.     bool isHumanPlayer() override;
  59.  
  60.     void useBook(bool bookOn) override;
  61.  
  62.     void timeLimit(int minTimeLimit, int maxTimeLimit) override;
  63.  
  64.     void clearTT() override;
  65.  
  66.     /** Search a position and return the best move and score. Used for test suite processing. */
  67.     std::pair<Move, std::string> searchPosition(Position& pos, int maxTimeMillis);
  68.  
  69.     /** Initialize static data. */
  70.     static void staticInitialize();
  71.  
  72.     /** Performs initialization that must happen after static initialization. */
  73.     static void initEngine();
  74.  
  75. private:
  76.     /** Check if a draw claim is allowed, possibly after playing "move".
  77.      * @param move The move that may have to be made before claiming draw.
  78.      * @return The draw string that claims the draw, or empty string if draw claim not valid.
  79.      */
  80.     std::string canClaimDraw(Position& pos, std::vector<U64>& posHashList,
  81.                              int posHashListSize, const Move& move);
  82.  
  83.  
  84.     int minTimeMillis;
  85.     int maxTimeMillis;
  86.     int maxDepth;
  87.  
  88.     int maxNodes;
  89.     TranspositionTable tt;
  90.     ParallelData pd;
  91.     std::shared_ptr<Evaluate::EvalHashTables> et;
  92.     Book book;
  93.     bool bookEnabled;
  94.     Search* currentSearch;
  95.     std::shared_ptr<Search::Listener> listener;
  96. };
  97.  
  98.  
  99. inline void
  100. ComputerPlayer::setTTLogSize(int logSize) {
  101.     tt.reSize(logSize);
  102. }
  103.  
  104. inline void
  105. ComputerPlayer::setListener(const std::shared_ptr<Search::Listener>& listener) {
  106.     this->listener = listener;
  107. }
  108.  
  109. inline bool
  110. ComputerPlayer::isHumanPlayer() {
  111.     return false;
  112. }
  113.  
  114. inline void
  115. ComputerPlayer::useBook(bool bookOn) {
  116.     bookEnabled = bookOn;
  117. }
  118.  
  119. inline void
  120. ComputerPlayer::clearTT() {
  121.     tt.clear();
  122. }
  123.  
  124. #endif /* COMPUTERPLAYER_HPP_ */
  125.