Developer Zone
Contents:
1. Introduction
2. Build a Winboard-compatible
engine
3. Build a simple engine using our SDK
If you have some questions, you can send us an email at
developer@netblitzchess.com.
1. Introduction
This document is addressed to programmers interested into knowing more about
the internals of Net Blitz II, and specifically how then can extend Net Blitz II by
developing their own custom chess engine that will be compatible with it.
If you wish to use an engine from within Net Blitz II, you have two choices:
- Create an engine compatible with the Winboard protocol. This will be covered
in section 2.
- Create a Net Blitz engine using our Chess Engine SDK. This will be covered
in section 3.
2. Build a Winboard-compatible engine
Winboard (the Windows equivalent of XBoard on the Unix platforms) is chess
program user interface similar to Net Blitz II. To enable multiple individuals
to develop their own engines and make them compete against each other, the Winboard
protocol was born. This protocol was invented by Tim Mann, and the complete
specifications can be located on the
Tim Mann's Web site.
The protocol description itself is found at this
page.
This is about as far as this tutorial will go regarding creating your own Winboard-compatible
engine. Visit the links provided for more information. The nice thing about
going this route is that your engine will also be compatible with Winboard user
interface and virtually all other Winboard-compatible user interfaces you may
find on the Internet.
NOTE: Although Net Blitz II has been successfully tested with a variety of publicly
available Winboard-compatible engines (ArasanX,
Gnu Chess,
among others) we cannot guarantee it is universally compliant with the protocol.
We did our best to adhere to the specifications, but we may have overlooked
some cases in the process, so you might have to adapt your engine so that Net
Blitz II uses it properly.
To setup your engine to be used in Net Blitz II, follow the following steps:
- Start Net Blitz II application
- Chose Local Chess Game from the main menu
- Click on Settings
- In the Settings dialog, select the
Winboard-Compatible Engine
from the drop-down list and then click Configure...
- In the Configure Engines
dialog, click Add...
- Finally, fill in the necessary information so that Net Blitz II can locate your
Winboard-compatible engine (display name, path to the executable file and
the working
directory if needed)
If you followed these steps properly, you should be able to select your new
engine from the list (see dialog box in step #5).
3. Build a simple engine using our SDK
The other option you have to develop your own engine to work within Net Blitz II
is using our public SDK. Here is a checklist of things you should be aware
before going on with this option:
- Engines must be written in C++ (since the SDK is only available in C++)
- Microsoft Visual Studio .NET 2003's C++ compiler should be used. Other compilers
may work but were not tested. The reason behind this is because our SDK relies
on virtual interfaces that must be implemented by the engine. Since Net Blitz II
was compiled with MSVC .NET 2003, your engine must be binary-compatible with
the way MSVC .NET 2003 handles its v-tables.
Our SDK is available in the public distribution of Net Blitz II. If you chose the
default path when installing, this should be in C:\Program Files\Net Blitz II\ChessEngineSDK.
The SDK itself is composed of two header files named ChessEnums.h
and ChessEngineSDK.h.
The remainder of this section is a devoted tutorial to show how to create a
basic chess engine with the Net Blitz II SDK.
- Create an empty C++ project in MSVC .NET 2003 (File | New | Project... |
Visual C++ Project | Win32 | Win32 Project). For this example we will name our project
MyChessEngine.
- In the Application Settings dialog for your
project, select DLL.
- If everything went well, a file named MyChessEngine.cpp should have been
created in C:\MyChessEngine. We will now copy the Net Blitz II SDK into this
folder as well. Copy the SDK folder into your project's folder so that the
files are accessible from this path: C:\MyChessEngine\ChessEngineSDK\ChessEngineSDK.h
and
C:\MyChessEngine\ChessEngineSDK\ChessEnums.h.
- In MyChessEngine.cpp, write the following code :
// MyChessEngine.cpp : Defines the entry point for the DLL application. //
#include "stdafx.h"
#include "ChessEngineSDK\ChessEngineSDK.h" using namespace NetBlitzEngineSDK; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }
class MyChessEngine : public ChessEngine { protected: Color m_color; bool m_bFirstMove; GameCommunicationInterface* m_pGameCommunicationInterface;
public: MyChessEngine() : m_pGameCommunicationInterface(NULL), m_color(White), m_bFirstMove(true) { } const char* GetEngineName() { static const char* name = "MyChessEngine"; return name; } bool InitializeEngine(void) { return true; }
bool UninitializeEngine(void) { return true; }
void SetCommunicationInterface(GameCommunicationInterface* pInterface) { m_pGameCommunicationInterface = pInterface; }
void SetColor(Color col) { m_color = col; }
bool HasSettingsDlg() { return false; } void DoSettingsDlg() { // do nothing in this sample } void ResetBoard() { // TODO m_bFirstMove = true; }
void ForceMove(int colSrc, int rowSrc, int colDst, int rowDst, Piece promotion) { // TODO m_bFirstMove = false; }
bool StartGame(int nbSeconds, int nbSecondsIncrement) { // TODO
// for our very simple implementation we only play the 1st move // always move e2e4 if we are white if(m_bFirstMove && m_color == White) m_pGameCommunicationInterface->PlayMove(4, 1, 4, 3, Queen);
return true; }
bool PlayMove(int colSrc, int rowSrc, int colDst, int rowDst, Piece promotion, int time, int opponentTime) { // TODO // for our very simple implementation, whatever what white plays, // our second move is e7e5
if(m_bFirstMove && m_color == Black) m_pGameCommunicationInterface->PlayMove(4, 6, 4, 4, Queen); m_bFirstMove = false;
// since we never play a move past 1st move, // our simple engine will lose by the clock...
return true; }
bool EndGame(void) { return true; }
void DeleteThis() { delete this; } };
// this is the function that netblitz will call from your DLL // thus it needs the extern "C" __declspec(dllexport) specifiers // and its name and signature must exactly match this
extern "C" __declspec(dllexport) ChessEngine* CreateChessEngine() { return new MyChessEngine; }
- Compile MyChessEngine.dll and copy the file into a sub-folder of
Engines,
for example: C:\Program Files\Net Blitz II\Engines\MyChessEngine\MyChessEngine.dll.
- Run Net Blitz II, select Local Chess Game, in the
Settings dialog your engine
should be available in the drop-down list ! Enjoy !
|