
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
//
//	Gerbil
//
//	Copyright (c) 2001, Bruce Moreland.  All rights reserved.
//
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
//
//	This file is part of the Gerbil chess program project.
//
//	Gerbil is free software; you can redistribute it and/or modify it under
//	the terms of the GNU General Public License as published by the Free
//	Software Foundation; either version 2 of the License, or (at your option)
//	any later version.
//
//	Gerbil is distributed in the hope that it will be useful, but WITHOUT ANY
//	WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
//	FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
//	details.
//
//	You should have received a copy of the GNU General Public License along
//	with Gerbil; if not, write to the Free Software Foundation, Inc.,
//	59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
#include "gproto.h"
#include "winboard.h"

static char const s_aszModule[] = __FILE__;

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

void VPrCallback(void * pv)
{
	VProcessEngineCommand(pv, TRUE);
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

//	Here's a move the engine wants to make.  The format for sending moves is
//	different depending upon whether I am using the old protocol or the new
//	one.

//	The "..." is a silly obsolete Winboard behavior.

void VPrSendMove(char * szMove)
{
	VSendToWinboard("%s %s", (s_ivars.iProtover > 1) ?
		"move" : "1. ...", szMove);
	s_ivars.coOnMove ^= 1;					// Protover 1.
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

//	This is actually the move being pondered on, not a response to the
//	"hint" command that Winboard might send.

void VPrSendHint(char * szMove)
{
	VSendToWinboard("Hint: %s", szMove);
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

void VPrSendAnalysis(int ply, int val, unsigned long tm,
	unsigned __int64 nodes, int prsa, char * szLine)
{
	VSendToWinboard("%d %d %lu %I64u %s", ply, val, tm / 10, nodes, szLine);
	switch (prsa) {
	case prsaFAIL_HIGH:
		VSendToWinboard("++");
		break;
	case prsaFAIL_LOW:
		VSendToWinboard("--");
		break;
	}
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

void VPrSendResult(char * szResult, char * szWhy)
{
	if (szWhy != NULL)
		VSendToWinboard("%s {%s}", szResult, szWhy);
	else
		VSendToWinboard("%s", szResult);
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

//	This sends a line to the interface, preceded by "# ".  This is just a
//	personal choice.  The interface may not demand this.
//
//	I'm going to send anything I think the interface won't really care about
//	with this function.

void VPrSendComment(const char * szFmt, ...)
{
	char	aszBuf[256];
	va_list	pvaArg;

	va_start(pvaArg, szFmt);
	vsprintf(aszBuf, szFmt, pvaArg);
	VSendToWinboard("# %s", aszBuf);
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

void VPrSendBookLine(char const * szLine, ...)
{
	if (szLine[0]) {
		char	aszBuf[256];
		va_list	pvaArg;

		va_start(pvaArg, szLine);
		vsprintf(aszBuf, szLine, pvaArg);
		VSendToWinboard(" %s", aszBuf);
	} else
		VSendToWinboard("");
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

void VPrOfferDraw(void)
{
	VSendToWinboard("offer draw");
}

//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
