Winboard/Java help.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Winboard/Java help.

Post by Dan Honeycutt »

Hi all,

I've been trying to learn some Java programming. I thought a good exercise would be to write a simple engine. I started with a really simple one just to see if I could 'talk' to winboard. All the program does is get two winboard commands and send a message back. I built my .jar file and copied it to my winboard directory. I then opened a cmd prompt, navigated to the winboard folder and ran my program with:

Code: Select all

java -jar moron.jar
Everything worked fine. Next I entered:

Code: Select all

winboard.exe -cp -fcp "java -jar moron.jar" -scp "java -jar moron.jar" -debug
I got Startup failure on 'java -jar moron.jar': The System cannot find the file specified. I'm not sure who can't find what. I verified that there is a java.exe in my path. I'm probably missing something obvious but damned if I can see what it is.

The winboard debug file and a listing of my program are below. Any help would be greatly appreciated.

Thanks
Dan H.

Code: Select all

WinBoard 4.4.0 + java
Reset(1, 0) from gameMode 0
recognized 'normal' (-1) as variant normal
GameEnds(0, (null), 2)
shuffleOpenings = 0
TC string = '+5+30'
mps=0 tc=300000 inc=30000
TC string = '+5+30'
mps=0 tc=300000 inc=30000
StartChildProcess (dir="") java -jar moron.jar
Fatal Error: Startup failure on 'java -jar moron.jar':
The system cannot find the file specified.


GameEnds(40, xboard exit, 2)

Code: Select all

/*
 * Java translation of the famous Moron engine by Fernando Villegas
 */
package moron;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;

public class Moron {

  static String fromWinboard() {      //get winboard command
    Scanner scan = new Scanner(System.in);  
    String cmd = scan.nextLine();
    writeLog&#40;"<- " + cmd&#41;;      //record what we got
    return cmd;
  &#125;

  static void toWinboard&#40;String msg&#41; &#123;  //send message to winboard
    System.out.println&#40;msg&#41;;
    System.out.flush&#40;);    
    writeLog&#40;"-> " + msg&#41;;
  &#125;

  static void writeLog&#40;String msg&#41; &#123;
    String eol = System.getProperty&#40;"line.separator");
    try &#40;BufferedWriter out = new BufferedWriter&#40;new FileWriter&#40;"log.txt", true&#41;)) &#123;
      out.write&#40;msg + eol&#41;;
      out.close&#40;);            //Close the output stream
    &#125; catch &#40;Exception e&#41; &#123;   //Catch exception if any
      System.err.println&#40;"Error&#58; " + e.getMessage&#40;));
    &#125;    
  &#125;

  public static void main&#40;String&#91;&#93; args&#41; &#123;
    fromWinboard&#40;);     //xboard
    fromWinboard&#40;);     //protover 2
    toWinboard&#40;"feature done=0 myname=Moron done=1");    
  &#125;
&#125;
User avatar
Jim Ablett
Posts: 1383
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: Winboard/Java help.

Post by Jim Ablett »

Hi Dan,

Won't work. You need to use something like this >

http://www.marochess.de/chess/tools/jlaunch/

ChessGui can load java engines > http://www.chessgui.com/

Or compile the java to executable >

http://www.byobingo.com/gcc_mingw.htm

Code: Select all

Compiling a Java Program with GCJ

Using GCC to run a Java program is familiar to anyone who has used it for C or C++ programs. 
To compile the Java program MyJavaProg.java, type&#58;

gcj -c -g -O MyJavaProg.java

To link it, use the command&#58;

gcj --main=MyJavaProg -o MyJavaProg MyJavaProg.o

This is just like compiling a C++ program mycxxprog.cc&#58;

g++ -c -g -O mycxxprog.cc

and then linking to create an executable mycxxprog&#58;

g++ -o mycxxprog mycxxprog.o
Or use executable wrapper >

http://launch4j.sourceforge.net/


Jim.
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Winboard/Java help.

Post by Dan Honeycutt »

Jim Ablett wrote:Hi Dan,

Won't work.
Ah ha. At least I don't feel like quite such a dunce. I made an exe with Launch4j and winboard started it okay but they didn't talk. A dos window opened and stayed open. I typed in two entrys, moron replied and exited. Winboard saw that it was gone and announced that first chess program quit unexpectedly.

Launch4j has a ton of settings, I'll have to study those. I think you've got me headed in the right direction. Thanks much.

Best
Dan H.
User avatar
Jim Ablett
Posts: 1383
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: Winboard/Java help.

Post by Jim Ablett »

Dan Honeycutt wrote:
Jim Ablett wrote:Hi Dan,

Won't work.
Ah ha. At least I don't feel like quite such a dunce. I made an exe with Launch4j and winboard started it okay but they didn't talk. A dos window opened and stayed open. I typed in two entrys, moron replied and exited. Winboard saw that it was gone and announced that first chess program quit unexpectedly.

Launch4j has a ton of settings, I'll have to study those. I think you've got me headed in the right direction. Thanks much.

Best
Dan H.

In Launch4j it's important to use >

Code: Select all

Header type = Gui
Tick the 'stay alive after launching a GUI application' box
If you double-click the executable produced you will see nothing, but it will work in the gui.

Jim.
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Winboard/Java help.

Post by Dan Honeycutt »

Getting closer. I received xboard and new. Don't know what happened to protover 2. Winboard doesn't seem to have received my features. I think I need to add more functionality to figure out what's happening.

Best
Dan H.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Winboard/Java help.

Post by Sven »

Dan Honeycutt wrote:Getting closer. I received xboard and new. Don't know what happened to protover 2. Winboard doesn't seem to have received my features. I think I need to add more functionality to figure out what's happening.

Best
Dan H.
It is possible that you also need to take care about using non-buffered input, since otherwise some WinBoard command lines might be sitting in some buffer for a while. I don't know how to do it in Java. In C you would use something like setbuf(stdin, 0) or setvbuf(stdin, ...).

Sven
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Winboard/Java help.

Post by Dan Honeycutt »

Sven Schüle wrote:It is possible that you also need to take care about using non-buffered input, since otherwise some WinBoard command lines might be sitting in some buffer for a while. I don't know how to do it in Java. In C you would use something like setbuf(stdin, 0) or setvbuf(stdin, ...).

Sven
I think you hit on the problem, Sven. With some more tinkering I determined that I was sending to Winboard fine but I was only receiving about half of the commands Winboard sent me. I changed from the scanner to a buffered reader, in Java:

Code: Select all

BufferedReader brd = new BufferedReader&#40;new InputStreamReader&#40;System.in&#41;);
. . . and now IT WORKS!!

Thank you both very much.

Now, if HG wanders by maybe he can put on his todo list adding jar file support to Winboard :-)

Best
Dan H.
User avatar
JuLieN
Posts: 2949
Joined: Mon May 05, 2008 12:16 pm
Location: Bordeaux (France)
Full name: Julien Marcel

Re: Winboard/Java help.

Post by JuLieN »

Dan Honeycutt wrote: Now, if HG wanders by maybe he can put on his todo list adding jar file support to Winboard :-)

Best
Dan H.
Can't Winboard accept .bat files as engines? If yes, just run it with java "your_jar.jar" :)
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Winboard/Java help.

Post by Dan Honeycutt »

JuLieN wrote:Can't Winboard accept .bat files as engines? If yes, just run it with java "your_jar.jar" :)
No luck. First I tried a batch file to start winboard and feed it java my_jar and got the same error as per my original post. Next I put java my_jar in a batch file and fed that to Winboard. This time I got the error: first chess program exited unexpectedly.

Your batch file suggestion does have merit, though. I can run it as a console application by double clicking the batch file from Explorer (without having to open a cmd window). If I double click the jar file I get nothing since the file association is javaw and not java.

Best
Dan H.
User avatar
JuLieN
Posts: 2949
Joined: Mon May 05, 2008 12:16 pm
Location: Bordeaux (France)
Full name: Julien Marcel

Re: Winboard/Java help.

Post by JuLieN »

Dan Honeycutt wrote:
JuLieN wrote:Can't Winboard accept .bat files as engines? If yes, just run it with java "your_jar.jar" :)
No luck. First I tried a batch file to start winboard and feed it java my_jar and got the same error as per my original post. Next I put java my_jar in a batch file and fed that to Winboard. This time I got the error: first chess program exited unexpectedly.

Your batch file suggestion does have merit, though. I can run it as a console application by double clicking the batch file from Explorer (without having to open a cmd window). If I double click the jar file I get nothing since the file association is javaw and not java.

Best
Dan H.
Then maybe the solution would be to use a "jar to exe" kind of adapter?
Like this one : http://www.regexlab.com/en/jar2exe/

It's not a compiler, but it incapsulates the jvm and the jar into an exe file...
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]