Page 1 of 1

How to make your Winboard engine run in Windows Mobile

PostPosted: 27 Jan 2009, 03:01
by Kerwin
Its really very easy. You don't even need to write new code. You simply need to paste the following...

At the start of your main header file, paste this block of code:

Code: Select all
#if UNDER_CE
    int __cdecl PrintF(const char *fmt, ...);
    typedef struct
    {
        int version;
        void *pIOInst;
        int (__stdcall *p_input_available) (void *pInst);
        char * (__stdcall *p_get_string) (void *pInst, char *s, int nmaxlen);
        void (__stdcall *p_put_string) (void *pInst, const char *s);
        int (__cdecl *p_print) (void *pInst, const char *fmt, ...);
        int (__cdecl *p_vprint) (void *pInst, const char *fmt, va_list args);
        unsigned int (__stdcall *p_available_memory) (void *pInst);
        void * (__stdcall *p_allocate_memory) (void *pInst, int nsize);
        void (__stdcall *p_free_memory) (void *pInst, void *pmem);
        int argc;
        char **argv;
    }
    TEngineIO;
    extern TEngineIO *EngineIO;
    #define malloc(n_) (EngineIO->p_allocate_memory(EngineIO->pIOInst,n_))
    #define free(p_) (EngineIO->p_free_memory(EngineIO->pIOInst,p_))
    #define printf PrintF
    #define puts(s_) PrintF("%s\n",s_)
    // replace this with the name of your "input-available" function
    #define InputAvailable() (EngineIO->p_input_available(EngineIO->pIOInst))
#endif


At the end of your main source file, paste this block of code:

Code: Select all
#if UNDER_CE
    TEngineIO *EngineIO;
    int __cdecl PrintF(const char *fmt, ...)
    {
        int n;
        va_list args;
        va_start (args, fmt);
        n = EngineIO->p_vprint (EngineIO->pIOInst, fmt, args);
        va_end (args);
        return n;
    }
    BOOL WINAPI DllMain (HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
    {
        return TRUE;
    }
    __declspec(dllexport) void __stdcall Run (TEngineIO *pEngineIO)
    {
        EngineIO = pEngineIO;
        main (EngineIO->argc, EngineIO->argv);
    }
#endif


That's it! Yes, its that easy. Your winboard engine is now ready to run in ThinkerBoard.

I am hoping other authors of xboard-compatible engines would consider porting their engines. As can be seen, it takes very little effort - especially in the ThinkerBoard environment - it does not force you to reorganize your existing code.

If anyone needs help doing so, please let me know.

Thanks!

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 02:37
by Pedro Castro
Hi Kerwin, I'm interested in making a port DanaSah. Last version of DanaSah is compatible with Windows and Linux. DanaSah is open code (GPL)

I have tried to build a dynamic dll.

I've added your first code to the header stdafx.h and y've added this hearder to all files cpp, then I added the other code to a new file cpp.

I have tried to compile the dll and I have 4 problems:

1. With the openning book, I use the code book Rebel/PRODEO. Thinkerboard has openning book for the engine?

2. With bitbases of Scorpio.

These two errors could not be if I not load book and bitbases.

3. I have a problem with the function get_ms (), the GUI controls the time or the engine?

Fatal error C1083: Can not open include file: 'sys/timeb.h': No such file or directory

4. I have a problem with the main function, I have to change the function int main () that I had before?

. \ danasah414wm.cpp (25): error C3861: 'main': identifier not found (This file contains the code you've post)

I could send you a more consistent version than it is on the website, you can send me a pm with your address?

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 03:14
by Kerwin
Cool!

I have just downloaded your engine and its source. I'll work on it a bit, and then I'll let you know what happens.

..later

Pedro Castro wrote:Hi Kerwin, I'm interested in making a port DanaSah. Last version of DanaSah is compatible with Windows and Linux. DanaSah is open code (GPL)

I have tried to build a dynamic dll.

I've added your first code to the header stdafx.h and y've added this hearder to all files cpp, then I added the other code to a new file cpp.

I have tried to compile the dll and I have 4 problems:

1. With the openning book, I use the code book Rebel/PRODEO. Thinkerboard has openning book for the engine?

2. With bitbases of Scorpio.

These two errors could not be if I not load book and bitbases.

3. I have a problem with the function get_ms (), the GUI controls the time or the engine?

Fatal error C1083: Can not open include file: 'sys/timeb.h': No such file or directory

4. I have a problem with the main function, I have to change the function int main () that I had before?

. \ danasah414wm.cpp (25): error C3861: 'main': identifier not found (This file contains the code you've post)

I could send you a more consistent version than it is on the website, you can send me a pm with your address?

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 03:54
by Pedro Castro
Hi Kerwin,

Perhaps it is best to download the code from the link below. I have standardized the program files, with names in English and with multiple sources as do other programmers.

The code contains an already created a project for msvc 2008 and smart devices.

The opening book and bitbases is loaded in Xboard file after the command Protover

http://danasah.googlepages.com/DanaSahv.4.zip

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 08:17
by Kerwin
Pedro Castro wrote:Hi Kerwin,

Perhaps it is best to download the code from the link below. I have standardized the program files, with names in English and with multiple sources as do other programmers.

The code contains an already created a project for msvc 2008 and smart devices.

The opening book and bitbases is loaded in Xboard file after the command Protover

http://danasah.googlepages.com/DanaSahv.4.zip


OK. I will use that then.

I have actually made the "other" source to work (well, almost). I just had to change the timer function (the API it was using does not exist in Win CE) and I had to change the use of "stdin" (this also does not exist in Win CE; there are no console apps in this environment). The ThinkerBoard UI can now see the output of your engine. However, the engine crashes. I have not debugged it yet. Maybe its just due to unalligned memory access, which is not allowed on ARM processors.

I will try again, but this time use the new source that you specified. I have to retire now for the day. Next update will be tomorrow.

Take care...

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 11:48
by Pedro Castro
Hi Kerwin,

Thanks.

It is good that you have already compiled my no standard program.

Not sure if you've managed to disable the opening book and bitbases.

Since then I imagine that you will sould change the memory resources for pocketpc, in the PC I'm using the following:

1 In the file danasah.ini you can see that I use 64 MB of hash, I imagine that this will decrease to about 4 MB for the pocketpc.

2. danasah has evalhash, often used on the PC 8 MB, I imagine that this value could drop to about 0.5 Mb

3. The opening book (I use the code modified by Fonzy) is planning to load the book into memory for faster access, it will use another MB, the original code of Ed not loaded into memory. The code that you have use one dll for open the book, the new code includes the code for the book and is not necessary the dll, it will be necessary with the executable the files mainbook.bin, tourbook.bin, random1.bin and random2.bin. If this book format is very complicated, I could go back to an earlier version of a text format and code like TSCP.

4.If loaded bitbases the default option would be to use 3 and 4 men in memory which would be about 10 MB, this would not be possible in the pocketpc, I think there is a option for not load bitbases into memory which would slow access, I think Fruit 2.3.1 uses bitbases in pocketpc (CEboard), I do not know as he does, I do not know if they have included the contents of the dll in Fruit.

Best,

Pedro

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 29 Jan 2009, 23:40
by Kerwin
Hi Pedro,

I got your latest source to build and run for ThinkerBoard on the Pocket PC.

The modified source files and the DLL is here.
http://cid-2991af457de54bf0.skydrive.li ... hv.4.1.zip

You will notice that the changes are very few and most have to do with making the source build for the Pocket PC environment. This includes:
1. Time function.
2. Unicode strings.
3. Stdio (stdin)

Such changes are required anyway if you need to make your source a good "Windows" citizen.

The rest is to simply "paste" the ThinkerBoard-specific IO redirectors.

And btw, I did not use your project files. They are too heavy because it specifies the use of MFC. I think you should create a new project that just specifies a "plain" Win32 DLL.

When you create the project:
1. Select Win32 Smart Device Project (under Smart Device)
2. For Platforms, select Pocket PC 2003 SDK "only" (the app will still run on newer Windows Mobile versions)
3. For Application Settings, select DLL and "Empty Project". Then just add your source files, and the DLL.DEF that I added.

Lastly, you don't need a real Windows Mobile device to run them. You can run the device simulator in VS 2008 (Tools - Connect to device - Pocket PC 2003 SE Emulator). Install the ThinkerBoard UI, and then add your engine DLL.

Here is a screen shot of DanaSah in action. The NPS looks low, because its running on the emulator. The NPS on iPAQ is much higher.
http://cid-2991af457de54bf0.skydrive.li ... SahWCE.PNG

Enjoy...

Pedro Castro wrote:Hi Kerwin,

Thanks.

It is good that you have already compiled my no standard program.

Not sure if you've managed to disable the opening book and bitbases.

Since then I imagine that you will sould change the memory resources for pocketpc, in the PC I'm using the following:

1 In the file danasah.ini you can see that I use 64 MB of hash, I imagine that this will decrease to about 4 MB for the pocketpc.

2. danasah has evalhash, often used on the PC 8 MB, I imagine that this value could drop to about 0.5 Mb

3. The opening book (I use the code modified by Fonzy) is planning to load the book into memory for faster access, it will use another MB, the original code of Ed not loaded into memory. The code that you have use one dll for open the book, the new code includes the code for the book and is not necessary the dll, it will be necessary with the executable the files mainbook.bin, tourbook.bin, random1.bin and random2.bin. If this book format is very complicated, I could go back to an earlier version of a text format and code like TSCP.

4.If loaded bitbases the default option would be to use 3 and 4 men in memory which would be about 10 MB, this would not be possible in the pocketpc, I think there is a option for not load bitbases into memory which would slow access, I think Fruit 2.3.1 uses bitbases in pocketpc (CEboard), I do not know as he does, I do not know if they have included the contents of the dll in Fruit.

Best,

Pedro

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 30 Jan 2009, 13:30
by Pedro Castro
Hi Kerwin,

Thank you very much. I am impressed with the speed that you has made the port. You're right not many changes but I would have taken months.

Has been me very excited to see play to DanaSah in the pocketpc, I think that as much as when I play with the first version on the PC.

Some comments;

1. I managed to compile and link the dll following the steps you say, the only problem is that I have had to disable the buffer check (/GS).

2. I have also seen that you've changed the code for opening book, unfortunately the book does not load.

You can read the information in a configuration file?, I think it is also prepared to open the file and read danasah.ini, but just in case I tried to upload the book directly (without ini file) and it does not work either.

One suggestion is that perhaps MobilThinker (GUI) could use the opening book of Thinker (dat) for the another engines.

3. I have also seen that you changed the code for bitbases of Scorpio, I have not tried to load.

I could try to load the dll directly (version windows pc)? or I would have to modify the code of bitbases to create a new dll special for pocketpc?

I will talk more when I try more the program.

Thanks again.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 30 Jan 2009, 20:04
by Kerwin
Yup. I forgot to mention that you need to disable the GS flag.

The changes that I made to your book and bitbase code only has to do with converting the strings to unicode, because Windows CE is unicode only.

As for the book and bitbase DLLs, you need to build a Pocket PC version of the DLLs. So, you need the source code of the book program and the source code of the bitbase program, and then you have to port them over to the Windows Mobile environment, just like you did with your engine source code. The Pocket PC uses the ARM processor which is very different from the x86 processor.

Your suggestion of using the Thinker book is a good one. I'm now thinking of porting the BookThinker code to Windows Mobile. That should happen this weekend.

Take care now...

Pedro Castro wrote:Hi Kerwin,

Thank you very much. I am impressed with the speed that you has made the port. You're right not many changes but I would have taken months.

Has been me very excited to see play to DanaSah in the pocketpc, I think that as much as when I play with the first version on the PC.

Some comments;

1. I managed to compile and link the dll following the steps you say, the only problem is that I have had to disable the buffer check (/GS).

2. I have also seen that you've changed the code for opening book, unfortunately the book does not load.

You can read the information in a configuration file?, I think it is also prepared to open the file and read danasah.ini, but just in case I tried to upload the book directly (without ini file) and it does not work either.

One suggestion is that perhaps MobilThinker (GUI) could use the opening book of Thinker (dat) for the another engines.

3. I have also seen that you changed the code for bitbases of Scorpio, I have not tried to load.

I could try to load the dll directly (version windows pc)? or I would have to modify the code of bitbases to create a new dll special for pocketpc?

I will talk more when I try more the program.

Thanks again.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 02 Feb 2009, 11:14
by Pedro Castro
Hi Kerwin,

I got the opening book of Rebel/Prodeo working with the engine. The source code is included.

It seems that there is a difference between PC and Pocket PC when using the fopen function, we must give the full path or else the fopen function searches the root directory.

I also changed when check the end of search time, I now check each 256 nodes. The number of nodes that makes my old ipaq 266 MHz is about 20,000 (about 40 times lower than the PC) which is the same as the emulator.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 02 Feb 2009, 23:43
by Kerwin
Cool! That's good to know.

If you intend to always put the book in the same folder as the UI, then I suggest that you use the module path as the book path. This is how the Thinker engine loads its book.

Its something like this...

Code: Select all
            WCHAR BookPath[_MAX_PATH];
            GetModuleFileName (NULL, BookPath, _MAX_PATH);

            WCHAR *p = wcsrchr (BookPath, '\\');
            if (p != NULL) p++;
            else p = BookPath;

            wcscpy (p, L"MyBook.dat");


Thinker gets 65,000 on a 625mhz iPaq, which I think is just about the same performance as yours (but on a faster hardware).

Btw, you can host your engine on FICS. You just need to get a computer account. I like to think that this is the most eco-friendly solution, because iPaqs consume only about 1 watt. With desktop PCs, memory alone consumes 3 watts.

One of these days, we should have a tournament of mobile engines. We probably could do this on HGMs new ICS server.

Pedro Castro wrote:Hi Kerwin,

I got the opening book of Rebel/Prodeo working with the engine. The source code is included.

It seems that there is a difference between PC and Pocket PC when using the fopen function, we must give the full path or else the fopen function searches the root directory.

I also changed when check the end of search time, I now check each 256 nodes. The number of nodes that makes my old ipaq 266 MHz is about 20,000 (about 40 times lower than the PC) which is the same as the emulator.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 09 Feb 2009, 00:57
by Pedro Castro
Hi Kerwin,

Thanks for the code, I will try to opening books in the same folder as the program. I have to change opening book, in PC, this is loaded into memory for fast speed but in the pocketpc does not make sense.

Thinker, amy, crafty do not use the configuration file on the pocketpc, these engines have hash fixed? Per example 5 Mb? I made a version without the configuration file because some people had problems with it, possibly by UNICODE.

I tried to play on FICS with the engine, everything goes well except for a small problem, I send a "q" for promote the queen, I believe I have send "Q" for FICS understand.

I think the conversion is good and the engine is quite competitive.

When I do that if you want the engine can be distributed in an upcoming version of Mobile Thinker.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 10 Feb 2009, 22:49
by Kerwin
Pedro Castro wrote:Hi Kerwin,

Thanks for the code, I will try to opening books in the same folder as the program. I have to change opening book, in PC, this is loaded into memory for fast speed but in the pocketpc does not make sense.

Thinker, amy, crafty do not use the configuration file on the pocketpc, these engines have hash fixed? Per example 5 Mb? I made a version without the configuration file because some people had problems with it, possibly by UNICODE.

I tried to play on FICS with the engine, everything goes well except for a small problem, I send a "q" for promote the queen, I believe I have send "Q" for FICS understand.

I think the conversion is good and the engine is quite competitive.

When I do that if you want the engine can be distributed in an upcoming version of Mobile Thinker.


Pedro Castro wrote:Hi Kerwin,

Thanks for the code, I will try to opening books in the same folder as the program. I have to change opening book, in PC, this is loaded into memory for fast speed but in the pocketpc does not make sense.

Thinker, amy, crafty do not use the configuration file on the pocketpc, these engines have hash fixed? Per example 5 Mb? I made a version without the configuration file because some people had problems with it, possibly by UNICODE.

I tried to play on FICS with the engine, everything goes well except for a small problem, I send a "q" for promote the queen, I believe I have send "Q" for FICS understand.

I think the conversion is good and the engine is quite competitive.

When I do that if you want the engine can be distributed in an upcoming version of Mobile Thinker.


Hi Pedro,

I definitely want to distribute your engine together with the Pocket PC ThinkerBoard. I'm sure many users would like to use your engine on their Windows Mobile devices. Just send me the DLL and I will bundle it with the next release.

As for the engine configuration, the Thinker engine accepts options from the command line. So, the configuration file can simply have something like this:
Engine=Thinker.DLL hashsize=3

The UI recognizes the command-line parameters and passes them to the DLL. As long as your "main()" can accept arguments, the DLL stub can pass them. Just make sure that the exported 'Run' function is like this:
Code: Select all
    __declspec(dllexport) void __stdcall Run (TEngineIO *pEngineIO)
    {
        EngineIO = pEngineIO;
        main (EngineIO->argc, EngineIO->argv);
    }


Take care...
Kerwin

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 20 Feb 2009, 12:19
by Pedro Castro
Hi Kerwin,

I continue to work on DanaSah, at the moment I have:

1. I deleted the configuration file "danasah.ini", now you can change the size of the hash or upload the book with parameters like Thinker. (DanaSahWCEDLL hash 5 ownbook on)

2. Now opening books are in the same folder as the dll file (easier installation).

3. I fixed a problem with the promotion when danasah is hosted on FICS. In this case moves have format a7a8=q (xboard protocol a7a8q)

4. I load opening book in memory, it uses 1 MB of memory (storage) and 1 Mb of memory (program) when danasah is run, I tried not load opening book. I thought that on the PDA was not needed because the memory storage is equal fast as the memory program, but without loading the opening book the result are bad, it is very slow.

5. I have thought to print the pv is very slow, I'm just trying to print over a depth of 6.

I have 2 problems with the function InputAvailable():

1. I need to include this function even during the search, otherwise there are occasions in which the move of opponent is lost. The same goes for TSCP. Even with ...

Code: Select all
   if ((nodes % 0x400) == 0) {
      if (status == SEARCHING && abort) {
         if (get_ms() >= time || InputAvailable() ) {
            stop_search = TRUE;
            return (0);
         }
      }
      else if (status == PONDERING) {
         if (InputAvailable() ) {
            stop_search = TRUE;
            return (0);
         }
      }
             }


2. I use a very simple way to ponder, just in time to ponder refull hash tables without attempting to trace the move of an opponent, this kind of ponder gives me good results in tournaments as WBEC or OpenWar.

The problem here is that DanaSah takes several seconds to leave the state ponder (the search goes fast), I do not know because this happens. I was thinking about how to change the ponder.

I hope that maybe in a week to have a stable version, but I'm not sure. As soon as I have something stable, I will tell you and I provide the program.

The good news is that I've ported TSCP 1.81, about 2-3 hours, for mobilthinker. ELO TSCP 1.81 on pda 1600-1700? (TSCP has not ponder). I think that TSCP can be very fun to play.

I will ask permission for distribute it to Tom Kerrigan.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 13 Mar 2009, 11:04
by Pedro Castro
Hi,

Here is DanaSah v.4.20 for MobilThinker (includes source code)
http://danasah.googlepages.com/DanaSahWCEDLLv.4.zip

This release may play a little better than the 4.17 version that played this tournament:
http://raitpref.hotbox.ru/ct-championship-1.htm

A few council if someone wants to make compatible the engine with MobilThinker:

1. Beware of the memory used by the engine. Thinker can use up to 5 Mb, DanaSah until 4 Mb (DanaSah also uses eval hash 1 Mb and 1 Mb to load the opening book in memory). With 5 MB starts the game but maybe it can quit in the middle of the game.

Is it possible to increase the memory used by the engines? In some PDA have memory not used.

2. In DanaSah try not to print the information of pv below deep 6 and not to print in mode "ponder", otherwise the engine takes a long time to get out of the search.

I still expect a response from Tom if is possible distribute TSCP 1.81

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 16 Mar 2009, 11:24
by Kerwin
Pedro Castro wrote:Hi,

Here is DanaSah v.4.20 for MobilThinker (includes source code)
http://danasah.googlepages.com/DanaSahWCEDLLv.4.zip

This release may play a little better than the 4.17 version that played this tournament:
http://raitpref.hotbox.ru/ct-championship-1.htm

A few council if someone wants to make compatible the engine with MobilThinker:

1. Beware of the memory used by the engine. Thinker can use up to 5 Mb, DanaSah until 4 Mb (DanaSah also uses eval hash 1 Mb and 1 Mb to load the opening book in memory). With 5 MB starts the game but maybe it can quit in the middle of the game.

Is it possible to increase the memory used by the engines? In some PDA have memory not used.

2. In DanaSah try not to print the information of pv below deep 6 and not to print in mode "ponder", otherwise the engine takes a long time to get out of the search.

I still expect a response from Tom if is possible distribute TSCP 1.81


Hi Pedro,

You can call the this function to determine the available memory: "unsigned int (__stdcall *p_available_memory) (void *pInst)". Then you can decide how much to allocate for your hash tables (after you make some adjustments for stack usage and other dynamic memory requirements).

I'm still finalizing a few minor fixes to the ThinkerBoard and the Thinker engine. Once that is done, I will release a new version that also includes your engine.

I hope you get a response from Tom. I don't see him in my address book anymore.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 24 Mar 2009, 19:13
by Pedro Castro
Thanks Kervin,

I have found a bug which I was creating hash tables 2 times.

Now I have a version with which I could play with up to 16 MB and also use new bitbases of scorpio.

http://danasah.googlepages.com/DanaSahWCEDLLv.4.zip

I talked to Tom about TSCP for MobileThinkerBoard, perhaps it will be possible to download it from the page of TSCP.

Re: How to make your Winboard engine run in Windows Mobile

PostPosted: 25 Mar 2009, 00:41
by Kerwin
Pedro Castro wrote:Thanks Kervin,

I have found a bug which I was creating hash tables 2 times.

Now I have a version with which I could play with up to 16 MB and also use new bitbases of scorpio.

http://danasah.googlepages.com/DanaSahWCEDLLv.4.zip

I talked to Tom about TSCP for MobileThinkerBoard, perhaps it will be possible to download it from the page of TSCP.


That's cool!

I will soon be releasing a new version of Pocket PC ThinkerBoard, and will include your engine with it. I'm just fixing a very nasty bug that has to do with resuming of games on FICS (the UI ends-up sending the wrong board information to the engine).

Take care...

TSCP 1.81 for MobileThinkerBoard

PostPosted: 01 Apr 2009, 08:45
by Pedro Castro
Hi,

TSCP 1.81 for MobilThinkerBoard is available from the home page TSCP. I estimate that the engine will have a force of about 1600 ELO. This engine is good to intermediate players.

http://www.tckerrigan.com/Chess/TSCP/Co ... inkerBoard

Note: Do not distribute engine without permission from Tom.