Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Where do you include winboard stuff in your program?

Author: Alessandro Scotti

Date: 10:00:35 12/15/04

Go up one level in this thread


Hi Uri,
in Kiwi I have input and output "adapters" and the engine itself doesn't deal
directly with protocols. These adapters were supposed to deal with standard
protocols and extensions (e.g. a "perft" command) but as I could never find
enough time to design UCI in, the whole think has remained somewhat half baked
and only supports Winboard (and extensions). Anyway, here's what an adapter
looks like:

class WinBoardAdapter : public Adapter
{
public:
    WinBoardAdapter();

    virtual ~WinBoardAdapter();

    virtual bool getNextCommand( Command & command );
    virtual void sendError( const char * what, const char * why );
    virtual void sendHint( const Position & pos, Move move );
    virtual void sendResult( int result, const char * why );
    virtual void resignGame( const Position & pos, const char * why );
    virtual void showThinking( const Position & pos, const MoveInfo & move );
    virtual void showCurrentSearchMove( const Position & pos, const RootMoveStat
& move );
    virtual void rejectMove( const char * move, const char * why );
    virtual void playMove( const Position & pos, Move move );
    virtual void answerToPing( const Command & ping );

private:
    int parseCommand( const char * line, Command & command );
};

So, an adapter reads protocol specific commands and outputs a sequence of
"universal" commands specified by the Command class. The engine itself is a
state machine that processes Command events and changes state accordingly, so
the main looks like:

    while( ! done ) {
        // Think if necessary
        switch( state ) {
            case state_Thinking:
                think();
                break;
            case state_Pondering:
                ponder();
                break;
            case state_PonderMissed:
                // Nothing to do, go directly to the thinking state
                state = state_Thinking;
                break;
            case state_Analyzing:
                analyze();
                break;
            case state_Quitting:
                done = true;
                break;
            default:
                System::yield();
                break;
        }

        // Handle input
        while( System::isInputAvailable() ) {
            int r = handleInput();

            if( r != 0 ) {
                done = true;
                break;
            }
        }
    }

The handleInput() function is the only function that is able to deal with
commands. None of the other functions read input, but a few of those use the
active adapter to produce output by calling one of the available methods.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.