Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

HexHtpEngine.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file HexHtpEngine.hpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef HEXHTPENGINE_H
00007 #define HEXHTPENGINE_H
00008 
00009 #include "GtpEngine.h"
00010 #include "SgNode.h"
00011 
00012 #include "Game.hpp"
00013 
00014 #include <boost/scoped_ptr.hpp>
00015 
00016 _BEGIN_BENZENE_NAMESPACE_
00017 
00018 //----------------------------------------------------------------------------
00019 
00020 typedef GtpCommand HtpCommand;
00021 typedef GtpFailure HtpFailure;
00022 
00023 //----------------------------------------------------------------------------
00024 
00025 /** Basic htp commands any Hex engine is required to support.  */
00026 class HexHtpEngine: public GtpEngine
00027 {
00028 public:
00029     HexHtpEngine(int boardsize);
00030     
00031     ~HexHtpEngine();
00032 
00033     /** @page hexhtpenginecommands HexHtpEngine Commands
00034         - @link CmdAllLegalMoves() @c all_legal_moves @endlink
00035         - @link CmdBoardID() @c board_id @endlink
00036         - @link CmdClearBoard() @c clear_board @endlink
00037         - @link CmdExec() @c exec @endlink
00038         - @link CmdFinalScore() @c final_score @endlink
00039         - @link CmdGenMove() @c genmove @endlink
00040         - @link CmdRegGenMove() @c reg_genmove @endlink
00041         - @link CmdInterrupt() @c gogui-interrupt @endlink
00042         - @link CmdLoadSgf() @c loadsgf @endlink
00043         - @link CmdName() @c name @endlink
00044         - @link CmdNewGame() @c boardsize @endlink
00045         - @link CmdParamGame() @c param_game @endlink
00046         - @link CmdPlay() @c play @endlink
00047         - @link CmdShowboard() @c showboard @endlink
00048         - @link CmdTimeLeft() @c time_left @endlink
00049         - @link CmdUndo() @c undo @endlink
00050         - @link CmdVersion() @c version @endlink
00051     */
00052 
00053     /** @name Command Callbacks */
00054     // @{
00055     // The callback functions are documented in the cpp file
00056 
00057     virtual void CmdAllLegalMoves(HtpCommand& cmd);
00058     virtual void CmdBoardID(HtpCommand&);
00059     virtual void CmdClearBoard(HtpCommand& cmd);
00060     virtual void CmdExec(HtpCommand& cmd);
00061     virtual void CmdFinalScore(HtpCommand& cmd);
00062     virtual void CmdGenMove(HtpCommand& cmd);
00063     virtual void CmdRegGenMove(HtpCommand& cmd);
00064 #if GTPENGINE_INTERRUPT
00065     virtual void CmdInterrupt(HtpCommand& cmd);
00066 #endif
00067     virtual void CmdLoadSgf(HtpCommand& cmd);
00068     virtual void CmdName(HtpCommand&);
00069     virtual void CmdNewGame(HtpCommand& cmd);
00070     virtual void CmdParamGame(HtpCommand& cmd);
00071     virtual void CmdPlay(HtpCommand&);
00072     virtual void CmdShowboard(HtpCommand&);
00073     virtual void CmdTimeLeft(HtpCommand&);
00074     virtual void CmdUndo(HtpCommand& cmd);
00075     virtual void CmdVersion(HtpCommand&);
00076 
00077     // @} // @name
00078 
00079 #if GTPENGINE_INTERRUPT
00080     /** Calls SgSetUserAbort(). */
00081     void Interrupt();
00082 #endif
00083 
00084 protected:
00085 
00086     StoneBoard m_board;
00087 
00088     Game m_game;
00089 
00090     /** Clears SgAbortFlag() */
00091     void BeforeHandleCommand();
00092 
00093     /** Does nothing. */
00094     void BeforeWritingResponse();
00095 
00096     /** Plays a move. */
00097     virtual void Play(HexColor color, HexPoint move);
00098 
00099     /** Creates a new game on a board with given dimensions. */
00100     virtual void NewGame(int width, int height);
00101 
00102     /** Generates a move for color. */
00103     virtual HexPoint GenMove(HexColor color, bool useGameClock) = 0;
00104 
00105     void SetPosition(const SgNode* node);
00106 
00107 private:
00108     void RegisterCmd(const std::string& name,
00109                      GtpCallback<HexHtpEngine>::Method method);
00110 };
00111 
00112 //----------------------------------------------------------------------------
00113 
00114 /** Misc HTP utilities. */
00115 namespace HtpUtil
00116 {
00117     HexColor ColorArg(const HtpCommand& cmd, std::size_t number);
00118 
00119     HexPoint MoveArg(const HtpCommand& cmd, std::size_t number);
00120 }
00121 
00122 //----------------------------------------------------------------------------
00123 
00124 _END_BENZENE_NAMESPACE_
00125 
00126 #endif // HEXHTPENGINE_H


6 Jan 2011 Doxygen 1.6.3