[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GO engine interface



Weimin Xiao wrote:
> 
> Hi, there,
> 
> I were using Borland C++ Builder to write GO GUI for easy coding, and using
> MS VC++ to write GO Engine for easy debugging. The GUI accesses the Engine
> only through an interface class AbsGO:
> 
> // -------------------------------------------------------------------------
> --
> #ifndef AbsGoH
> #define AbsGoH
> // -------------------------------------------------------------------------
> --
> class AbsGO
> {
> public:
>     AbsGO() {};
>     virtual ~AbsGO() {};
> 
>     // game playing interface
>     virtual bool GameStart(int iHandicap, int  iBoardSize)=0;
>     virtual bool GameBoard(int& iPlayer,  int  iX, int  iY)=0;
>     virtual bool LastMove (int& iPlayer,  int& iX, int& iY)=0;
>     virtual bool IsLegalMove(int iX, int iY)=0;
>     virtual bool HasStoneKilled()=0;
>     virtual bool IsGameEnd()=0;
> 
>     virtual bool MoveTo(int iPlayer, int iX, int iY)=0;
>     virtual bool Suggestion(int iPlayer, int& iX, int& iY)=0;
>     virtual bool BackOneMove()=0;
> 
>     virtual bool ScoreGame(int& iBlackScore, int& iWhiteScore)=0;
>     virtual bool SaveGame(char* sFile, int iStyle = 0)=0;
>     virtual bool LoadGame(char* sFile)=0;
> 
>     // informational
>     virtual bool InternalStatus(int iBoardType,
>                                 double& dPositionValue,
>                                 int iX,
>                                 int iY)=0;
>     virtual bool EngineLoaded()=0;
> 
>     // machine learning interface
>     virtual bool BatchLearn(char* sFile, int iMethod)=0;
>     virtual bool SaveLearnt(char* sFile, int iMethod)=0;
>     virtual bool LoadLearnt(char* sFile, int iMethod)=0;
> };
> #endif
> 
> For my implementation, the above interface class seems good enough. If a GO
> environment or a UI object has similar interface, change an Engine or a UI
> should not be a pain.
> 
> Some suggestions?

 Great the computer GO mailing list is finally talking about code . . .
excellent  :-)  !!!!!!!

 Some comments for you . . .

o  Is it really the job of the board manager to score the game ? In
pubgo the scoring
involves doing string tactics to work out what strings are dead. I think
the low level board
should have as little responsibility as possible.

o  The batch learn stuff looks very interesting but again is part of the
lowest level board
management. Likewise the EngineAttached but I am interested to know what
the Engine is :-)

o How is your GUI updated ? In pubgo Bruces go board uses an Subject
Observer pattern, The GUI 
simply attaches to the GoBoard and is informed about changes in board
state (GoMove messages).
The hash function in pubgo is implemented as a BoardView. Views can be
attached and dettached so
during a search you can monitor whats happening by leaving the board
attached or if you are in real
play mode you can detach the view. Knowing what views need to be
attached / detached has not been
addressed yet in pubgo because I have only implemented a few of them it
it easy to attach and dettach
the relevent views. If lots of views are attached (by other unkown
observers of the board) then the
board manager and views would need to get a bit cleverer.

 I have attached a few headers from pubgo which define our board and
board view interface.

 cheers Paul.

/*
 * Generic go board base class.
 * Designed to automate storage of the positions, making moves, and
 * taking them back. Ideally it will allow easier coding of Go AI.
 *
 * Author:		Bruce Cropley
 * History:		25 April 1995: Commenced
 *			16 September 1995: Resumed for TEAMGO
 *                      6  March 1998: PJL add prisoner counting.   
 *
 * Notes:
 */

#ifndef _GoBoard_H
#define _GoBoard_H

#include		"GoString.h"		/* A group of stones */
#include		"brdcontr.h"		/* The BoardController */
#include                "boarbase.h"

class BitPad;

class GoBoard : public BoardBase
{
public:
                     GoBoard(Coord width);
  virtual	     ~GoBoard();

  // Main selector methods
    
  const GoString*    stringAt(const Point &p) const;
  // Check for occupied point, off board, suicide (if applicable), Ko.

  bool		     legalMove(const Point &p) const;

  // Is the point an illegal Ko move?
  bool		     isIllegalKo(const Point &pt) const;

  /*!  width of the board */
  static int	     width(); 

  /*!  number of points on board width*width */
  static int         size();

  Side		     stoneColorAt(const Point &pt) const; // -pjl likewise

  /*! the board controller manages the attaching and detaching of views */
  BoardController *  boardController() const { return _boardController;}
    
  /*! For Testing me */
  bool		     isValid() const;
  void		     rebuild();
    
  // Pass moves  "Point::passPoint()"
  void		     move(const Point &pt);

  // Unmove == unpass. takeBack the last move.
  void		     takeBack();
    
      
  // PJL: hack to check valid points when search methods going wild
  // Just takeBack() but assert it is really that pt.
  bool		     takeBack(const Point &pt);

  //! How many captured stones ?
  int                prisoners(Side side) const;

    
    
    
public:
  static GoBoard *   the(){assert(_theBoard != 0); return _theBoard;}
private:

 ...  stuff in here

};

#endif				/* _GoBoard_H */


/*
 * BoardController class.
 * Sends out changes to the LowBoard to all currently registered
 * BoardView subclasses. Also maintains the move list.
 *
 * Author:		Bruce Cropley
 * History:		2 October 1995: Commenced for TEAMGO
 * Notes:		The "Controller" in the Model View Controller paradigm.
 *
 */

#ifndef _BoardController_H
#define _BoardController_H

#include "assert.h"

class BoardView;
class String;
class GameMove;

class BoardController
{
public:
  BoardController();
  ~BoardController();

  // Add and remove Views.
  void				addView(BoardView *v);
  void				removeView(BoardView *v);

  // IS this ever used ? (delete it ?)
  BoardView *			getView( const char *viewId );

  void				move(const GameMove &mv);
  void				takeBack();

  // Return the move i turns before last move
  // NULL if non existant 
  const GameMove *              history(int i) const;

  GameMove *			topMove() const;
  GameMove *			nextMove() const;

  static BoardController *	the();

private:
  BoardView **                  _views;
  static BoardController *      _the;
  unsigned char                 _numViews;

  GameMove *_moveList;
  unsigned short _moveNumber;
};



#endif


/*
 * BoardView base class.
 * Base class for classes which are interested in changes to the GoBoard.
 *
 * Author:		Bruce Cropley
 * History:		1 October 1995: Commenced for TEAMGO
 * Notes:		The "View" in the Model View Controller paradigm.
*/

#ifndef _BoardView_H
#define _BoardView_H

#include <string.h>

class GameMove;

class BoardView
{
public:
	BoardView( const char *id );
	virtual ~BoardView() {};

	virtual void	move(const GameMove &mv) =0;
	virtual void	takeBack(const GameMove &mv) =0;

	const char *getId();

private:
	const char *_identification;
};



#ifndef _GameMove_H
#define _GameMove_H

#include "GoString.h"

class GameMove 
{
  friend class GoBoard;
public:
  GameMove();
  ~GameMove();

  const Point	&           pointPlayed() const;
  const GoString  *         string() const;
  bool		            koCapture() const;
  bool	                    suicide() const;      // pjl
  bool		            pass() const;         // pjl
  const StringCollection  & prisoners() const;
  const StringCollection  & joinedStrings() const;

private:
  Point			    _pointPlayed;
  bool			    _koCapture;
  GoString  *               _string;
  StringCollection	    _prisoners;
  StringCollection	    _joinedStrings;
  static StringCollection * _emptyStringCollection;
};