what on earth

Discussion of chess software programming and technical issues.

Moderator: Ras

flok

what on earth

Post by flok »

In case someone wants to see what on earth I'm doing, I uploaded a tar-file with the current sources: http://vanheusden.com/DeepBrutePos/Deep ... rc.tar.bz2

You need:
- java (both sun (oracle) jdk as openjdk work fine)
- ant

To build enter:
ant

run:
java -jar dbp.jar --help
to see a list of options. of course dbp.jar should be adjusted (ant places the created jar-file under dist/)
zongli
Posts: 13
Joined: Sat May 12, 2012 9:45 pm

Re: what on earth

Post by zongli »

I'm not sure if your search is working correctly (seems correct), but I'll point out some glaring performance issues. First, we can't generate move lists so carelessly. ^^ Testing whether a square or the king is attacked can be accomplished by trying the other pieces' moves from the king square and seeing whether it intersects with the respective enemy piece. The purpose of doing so eludes me, but you validate each move by once again generating a full list. I think you end up generating moves tens or hundreds of times at each node.

Your move scheme is clearly copy-make, so I would recommend minimizing the amount of initialization needed by your board/scene/move objects. For your current implementation I'd expect a significant speed gain by moving to make-unmake, if you can deal with a little additional complexity. Also, try using System.arraycopy instead of loops.

By the way, I couldn't find any signs of a perft function?
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: what on earth

Post by lucasart »

flok wrote:In case someone wants to see what on earth I'm doing, I uploaded a tar-file with the current sources: http://vanheusden.com/DeepBrutePos/Deep ... rc.tar.bz2

You need:
- java (both sun (oracle) jdk as openjdk work fine)
- ant

To build enter:
ant

run:
java -jar dbp.jar --help
to see a list of options. of course dbp.jar should be adjusted (ant places the created jar-file under dist/)
I don't know Java (I use C), so I can't fix your code, but I suggest you follow a much more rigourous strategy:
1/ validate by perft your move generator. you might spot performance issues there as well. use a profiler to pinpoint the problem, guessing doesn't always work.
2/ do not write an alpha beta search, especially in this way. start by writing an SEE, and test it thouroughlly.
3/ now write a quiescent search (with alpbha beta bounds as parameters), and again test it manually by feeding positions into it. you'll be using the SEE a lot in a good QS, as well as in the move ordering (I let you test MVV/LVA sorting vs SEE sorting of captures).
4/ now write a search. although many programs do that, I do not recomment doing a specific function for the root node, for pv and non pv nodes. It's best to have one function to avoid duplicating code and creating mistakes by mismanaged copy/paste.
5/ then all the crap around it for the UCI or Xboard protocol and so on.

There is no easy way. This is the strategy I followed when coding DoubleCheck, and that was after starting from scratch my engine several times...
User avatar
hgm
Posts: 28454
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: what on earth

Post by hgm »

What helped me along quite quickly when I started coding HaChu was early implementation of the 'highlight' feature of the WB-Alien protocol. For that I order a one-ply search (or however many ply your search would need to weed out illegal moves; a King-capture engine in Chess would need two ply), and then let it make the move list of the root node available (after any sorting it might have done on it). That move list I use for legality checking of the input moves, but also for emitting the highlight command. Then I could simply move the pieces around in WinBoard Alien Edition, Edit-Game mode, with legality testing of the GUI switched off, and the moves of the pieces I pick up will be highlighted on the display according to the engines move list. So that I could discovered quite quickly which moves my move generator was missing. (Chu Shogi has some complex rules for the difference between pseudo-legal and legal moves, and I had a complex (staged) move generator anyway, which uses different methods for generating captures and non-captures, so I had to remove quite a few bugs that way!)

Code: Select all

void
Highlight(char *coords)
{
  int i, j, n, sqr, cnt=0;
  char b[BSIZE], buf[2000], *q;
  for(i=0; i<bsize; i++) b[i] = 0;
  ReadSquare(coords, &sqr);

  postThinking--;
  Search(-INF-1, INF+1, 0, 1, sup1, sup2);
  postThinking++;

  for(i=retFirst; i<retMSP; i++) { // start and end of move list returned by Search
    if(sqr == FROM(moveStack[i])) {
      int t = TO(moveStack[i]);
      b[t] = (board[t] == EMPTY ? 'Y' : 'R'); cnt++;
    }
  }
  if(!cnt) return; // refrain from sending empty color-FEN

  q = buf;
  for(i=BH-1; i>=0; i--) {
    for(j=0; j<BH; j++) {
      n = BW*i + j;
      if(b[n]) *q++ = b[n]; else {
        if(q > buf && q[-1] <= '9' && q[-1] >= '0') {
          q[-1]++;
          if(q[-1] > '9') {
            if(q > buf+1 && q[-2] <= '9' && q[-2] >= '0') q[-2]++; else q[-1] = '1', *q++ = '0';
          }
        } else *q++ = '1';
      }
    }
    *q++ = '/';
  }
  q[-1] = 0;
  printf("highlight %s\n", buf);
}

// and in the protocol driver:

        if(!strcmp(command, "lift"))    { Highlight(inBuf+5); continue; }