1 //----------------------------------------------------------------------------- 2 /** @file libpentobi_gtp/GtpEngine.h 3 @author Markus Enzenberger 4 @copyright GNU General Public License version 3 or later */ 5 //----------------------------------------------------------------------------- 6 7 #ifndef LIBPENTOBI_GTP_GTP_ENGINE_H 8 #define LIBPENTOBI_GTP_GTP_ENGINE_H 9 10 #include "libboardgame_gtp/GtpEngine.h" 11 #include "libpentobi_base/Game.h" 12 #include "libpentobi_base/PlayerBase.h" 13 14 namespace libpentobi_gtp { 15 16 using libpentobi_base::Board; 17 using libpentobi_base::Color; 18 using libpentobi_base::Game; 19 using libpentobi_base::PlayerBase; 20 using libpentobi_base::Variant; 21 using libboardgame_gtp::Arguments; 22 using libboardgame_gtp::Response; 23 24 //----------------------------------------------------------------------------- 25 26 /** GTP Blokus engine. */ 27 class GtpEngine 28 : public libboardgame_gtp::GtpEngine 29 { 30 public: 31 explicit GtpEngine(Variant variant); 32 33 void cmd_all_legal(Arguments args, Response& response); 34 void cmd_clear_board(); 35 void cmd_cputime(Response& response); 36 void cmd_final_score(Response& response); 37 void cmd_g(Response& response); 38 void cmd_genmove(Arguments args, Response& response); 39 void cmd_loadsgf(Arguments args); 40 void cmd_move_info(Arguments args, Response& response); 41 void cmd_p(Arguments args); 42 void cmd_param_base(Arguments args, Response& response); 43 void cmd_play(Arguments args); 44 void cmd_point_integers(Response& response); 45 void cmd_showboard(Response& response); 46 void cmd_reg_genmove(Arguments args, Response& response); 47 void cmd_savesgf(Arguments args); 48 void cmd_set_game(Arguments args); 49 void cmd_set_random_seed(Arguments args); 50 void cmd_undo(); 51 52 /** Set the player. 53 @param player The player. The lifetime of this parameter must 54 exceed the lifetime of the class instance. */ 55 void set_player(PlayerBase& player); 56 set_accept_illegal(bool enable)57 void set_accept_illegal(bool enable) { m_accept_illegal = enable; } 58 59 /** Enable or disable resigning. */ set_resign(bool enable)60 void set_resign(bool enable) { m_resign = enable; } 61 62 void set_show_board(bool enable); 63 get_board()64 const Board& get_board() const { return m_game.get_board(); } 65 66 protected: 67 Color get_color_arg(Arguments args, unsigned i) const; 68 69 Color get_color_arg(Arguments args) const; 70 71 void on_handle_cmd_begin() override; 72 73 private: 74 bool m_accept_illegal = false; 75 76 bool m_show_board = false; 77 78 bool m_resign = true; 79 80 Game m_game; 81 82 PlayerBase* m_player = nullptr; 83 84 void board_changed(); 85 86 void genmove(Color c, Response& response); 87 88 PlayerBase& get_player() const; 89 90 void play(Color c, Arguments args, unsigned arg_move_begin); 91 }; 92 93 //----------------------------------------------------------------------------- 94 95 } // namespace libpentobi_gtp 96 97 #endif // LIBPENTOBI_GTP_GTP_ENGINE_H 98