Page 1 of 9

Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 3:06 pm
by sje
Announcement: The Bozochess Project

Are you familiar with the Pascal programming language, or its relations Modula-2, Oberon, or Delphi? Are you interested in trying out a new chess program source? Do you have a machine built in the past ten years that can run one of the several inexpensive (or free) Pascal compilers?

Well, I have something just for you! And it won't cost a penny, only a bit of your time.

About thirty five years ago, David Slate, the co-author of the Northwestern Chess 4.x program, wrote a demonstration chess program in Pascal which was published in Byte magazine. Named "Chess 0.5" (clever, eh?), the program was written in the Zurich ETH dialect of Pascal for the CDC 6000 series mainframes. This was fine if you happened to have access to one of these monsters, but of limited use otherwise. Still, it was a decent attempt at an educational resource for Pascal and for chess programming. A little hunting will locate this very source on the web.

Since that time, there haven't been too many Pascal chess program sources publicly available. Also, Pascal has evolved over the years, and the dialect employed by Slate has long since gone out of fashion.

I remember when Chess 0.5 was published (See _The Byte Book of Pascal_ which includes a reprint of the articles and source) and I think it's time for a replacement. To bring this about, I've started the Bozochess Project (silly name is silly and will be changed). This is a new bitboard chess program I've started using a modern, more standard Pascal dialect. More portable, too; I'm using the Free Pascal compiler but I'm trying to avoid language features which might be unsupported in other modern Pascal variants.

How else is Bozochess different from Chess 0.5?

1) Bozochess is much more object oriented. Although it does not use Pascal classes (but this may change), it could be easily converted.

2) Bozochess doesn't need a US$5,000,000 computer to run. It might even be possible to run it on a 64 KB RAM microcomputer if some features were removed.

3) Bozochess supports the modern chess data interchange formats (SAN, FEN, EPD, PGN); it does not support the EDN (English Descriptive Notation) used in Chess 0.5.

4) Bozochess routine names are not constrained to the six character limit from the Old Days Pascal. There has been considerable effort to use meaningful and somewhat long names which can be decoded without help from a cheat sheet.

5) There have been several optimizations of bitboard and bitboard database processing. The same is true of move generation, pin detection, and other aspects of the program.

6) There is not a single damn "goto" in the entire program. This ain't Fortran.

7) There is not a single damn variant field list in the entire program. No machine dependency kludges here.

8) The poor string processing of the Old Days Pascal is gone. Exactly how this will be replaced is still uncertain, but might use the ansistring type seen in Free Pascal.

9) Bozochess is not multi-threaded, but is being designed for such.

10) Bozochess plays full legal chess; specifically, it understands all draw conditions and not just stalemate.

11) Bozochess will have a provision for a transposition subsystem, an opening book; maybe tablebases as well.

12) Bozochess is written using the full ASCII character glyph set and not just the six bit display code from the Old Days.

The Bozochess source, a single file, is now about 2,300 lines long. The move generation is not yet complete, but I expect to have it along with a perft routine running in the next week or two. Once Bozochess gets this far, I'll make the source available via email for anyone who would like to take a look and hopefully can make some constructive suggestions. Watch this thread for progress reports.

Sample code (working):

Code: Select all

function bbcount(var bb: bbtype): integer;
var
  sum: integer;
  bbwindex: integer;
begin
  sum := 0;
  for bbwindex := 0 to bbwindexlimit do
    sum := sum + bitcountvec[bb[bbwindex]];
  bbcount := sum;
end; { bbcount }

function bbfirstsq(var bb: bbtype): sqxtype;
var
  firstsq: sqxtype;
  bbwindex: integer;
  wordfirstbit: integer;
begin
  firstsq := sqnil;
  bbwindex := 0;
  while &#40;firstsq = sqnil&#41; and &#40;bbwindex <= bbwindexlimit&#41; do
    begin
      wordfirstbit &#58;= bitfirstvec&#91;bb&#91;bbwindex&#93;&#93;;
      if wordfirstbit >= 0 then
        firstsq &#58;= sqxtype&#40;wordfirstbit + &#40;bbwindex * bbwbitlen&#41;)
      else
        bbwindex &#58;= bbwindex + 1;
    end;
  bbfirstsq &#58;= firstsq;
end; &#123; bbfirstsq &#125;
More sample code (bitboard database stuff, also working):

Code: Select all

procedure bbdbaddattacks&#40;var bbdb&#58; bbdbtype; sq&#58; sqtype; man&#58; manrtype&#41;;
var
  color&#58; colortype;
  dir&#58; dirtype;
  atkfrbb&#58; bbtype;
  atkfrsq&#58; sqxtype;
  dir0, dir1&#58; dirtype;
  scansq&#58; sqxtype;
  stopped&#58; boolean;
begin
  with bbdb do
    begin
      color &#58;= mantocolor&#91;man&#93;;
      
      &#123; Generate the attacks-from-square bitboard &#125;

      case mantopiece&#91;man&#93; of
        pp&#58; atkfrbb &#58;= pawnattackbbvec&#91;color, sq&#93;;
        pn&#58; atkfrbb &#58;= knightattackbbvec&#91;sq&#93;;
        pb, pr, pq&#58;
          begin
            bbreset&#40;atkfrbb&#41;;
            dir0 &#58;= mantodir0&#91;man&#93;;
            dir1 &#58;= mantodir1&#91;man&#93;;
            for dir &#58;= dir0 to dir1 do
              begin
                scansq &#58;= sq;
                stopped &#58;= false;
                while not stopped do
                  begin
                    scansq &#58;= sqdirtonextsq&#91;scansq, dir&#93;;
                    if scansq = sqnil then
                      stopped &#58;= true
                    else
                      begin
                        bbsetsq&#40;atkfrbb, scansq&#41;;
                        if bbtestsq&#40;merge, scansq&#41; then
                          stopped &#58;= true;
                      end;
                  end;
              end;
          end;
        pk&#58; atkfrbb &#58;= kingattackbbvec&#91;sq&#93;;
      end;
      
      &#123; Apply the attacks-from-square bitboard &#125;

      atkfs&#91;sq&#93; &#58;= atkfrbb;
      bbior2d&#40;atkbc&#91;color&#93;, atkfrbb&#41;;
      repeat
        atkfrsq &#58;= bbnextsq&#40;atkfrbb&#41;;
        if atkfrsq <> sqnil then
          bbsetsq&#40;atkts&#91;atkfrsq&#93;, sq&#41;;
      until atkfrsq = sqnil;
    end;
end; &#123; bbdbaddattacks &#125;

procedure bbdbdelattacks&#40;var bbdb&#58; bbdbtype; sq&#58; sqtype; man&#58; manrtype&#41;;
var
  color&#58; colortype;
  atkfrbb&#58; bbtype;
  atkfrsq&#58; sqxtype;
begin
  with bbdb do
    begin
      color &#58;= mantocolor&#91;man&#93;;
      atkfrbb &#58;= atkfs&#91;sq&#93;;
      bbreset&#40;atkfs&#91;sq&#93;);
      repeat
        atkfrsq &#58;= bbnextsq&#40;atkfrbb&#41;;
        if atkfrsq <> sqnil then
          begin
            bbresetsq&#40;atkts&#91;atkfrsq&#93;, sq&#41;;
            if bbni2&#40;locbc&#91;color&#93;, atkts&#91;atkfrsq&#93;) then
              bbresetsq&#40;atkbc&#91;color&#93;, atkfrsq&#41;;
          end;
      until atkfrsq = sqnil;
    end;
end; &#123; bbdbdelattacks &#125;

procedure bbdbproattacks&#40;var bbdb&#58; bbdbtype; sq&#58; sqtype&#41;;
var
  atktobb&#58; bbtype;
  atktosq&#58; sqxtype;
  color&#58; colortype;
  dir&#58; dirtype;
  scansq&#58; sqxtype;
  stopped&#58; boolean;
begin
  with bbdb do
    begin
      atktobb &#58;= atkts&#91;sq&#93;;
      repeat
        atktosq &#58;= bbnextsq&#40;atktobb&#41;;
        if atktosq <> sqnil then
          if bbtestsq&#40;sweep, atktosq&#41; then
            begin
              color &#58;= bbdbsqcolor&#40;bbdb, atktosq&#41;;
              dir &#58;= sqsqtodir&#91;atktosq, sq&#93;;
              scansq &#58;= sq;
              stopped &#58;= false;
              while not stopped do
                begin
                  scansq &#58;= sqdirtonextsq&#91;scansq, dir&#93;;
                  if scansq = sqnil then
                    stopped &#58;= true
                  else
                    begin
                      bbsetsq&#40;atkfs&#91;atktosq&#93;, scansq&#41;;
                      bbsetsq&#40;atkts&#91;scansq&#93;, atktosq&#41;;
                      bbsetsq&#40;atkbc&#91;color&#93;, scansq&#41;;
                      if bbtestsq&#40;merge, scansq&#41; then
                        stopped &#58;= true;
                    end;
                end;
            end;
      until atktosq = sqnil;
    end;
end; &#123; bbdbproattacks &#125;

procedure bbdbcutattacks&#40;var bbdb&#58; bbdbtype; sq&#58; sqtype&#41;;
var
  atktobb&#58; bbtype;
  atktosq&#58; sqxtype;
  color&#58; colortype;
  dir&#58; dirtype;
  scansq&#58; sqxtype;
  stopped&#58; boolean;
begin
  with bbdb do
    begin
      atktobb &#58;= atkts&#91;sq&#93;;
      repeat
        atktosq &#58;= bbnextsq&#40;atktobb&#41;;
        if atktosq <> sqnil then
          if bbtestsq&#40;sweep, atktosq&#41; then
            begin
              color &#58;= bbdbsqcolor&#40;bbdb, atktosq&#41;;
              dir &#58;= sqsqtodir&#91;atktosq, sq&#93;;
              scansq &#58;= sq;
              stopped &#58;= false;
              while not stopped do
                begin
                  scansq &#58;= sqdirtonextsq&#91;scansq, dir&#93;;
                  if scansq = sqnil then
                    stopped &#58;= true
                  else
                    begin
                      bbresetsq&#40;atkfs&#91;atktosq&#93;, scansq&#41;;
                      bbresetsq&#40;atkts&#91;scansq&#93;, atktosq&#41;;
                      if bbni2&#40;locbc&#91;color&#93;, atkts&#91;scansq&#93;) then
                        bbresetsq&#40;atkbc&#91;color&#93;, scansq&#41;;
                      if bbtestsq&#40;merge, scansq&#41; then
                        stopped &#58;= true;
                    end;
                end;
            end;
      until atktosq = sqnil;
    end;
end; &#123; bbdbcutattacks &#125;

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 3:38 pm
by Gerd Isenberg
sje wrote: About thirty five years ago, David Slate, the co-author of the Northwestern Chess 4.x program, wrote a demonstration chess program in Pascal which was published in Byte magazine. Named "Chess 0.5" (clever, eh?), the program was written in the Zurich ETH dialect of Pascal for the CDC 6000 series mainframes. This was fine if you happened to have access to one of these monsters, but of limited use otherwise. Still, it was a decent attempt at an educational resource for Pascal and for chess programming. A little hunting will locate this very source on the web.
Hi Steven,

very interesting!

Small correction though, Chess 0.5 as published in three BYTE articles was by Larry Atkin and Peter W. Frey:

http://www.devili.iki.fi/library/author/1442.en.html
http://www.moorecad.com/standardpascal/ByteChess.txt
http://www.moorecad.com/standardpascal/Chess05.pas

Gerd

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 3:47 pm
by sje
Gerd Isenberg wrote:Small correction though, Chess 0.5 as published in three BYTE articles was by Larry Atkin and Peter W. Frey:

http://www.devili.iki.fi/library/author/1442.en.html
http://www.moorecad.com/standardpascal/ByteChess.txt
http://www.moorecad.com/standardpascal/Chess05.pas
Thank you very much for the correction and for the links. I've been working from some very old memories and so it's no surprise that I'd forgotten the exact details.

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 6:51 pm
by ethanara
What is the goal of this program?
Strength or retroness?
I would maybe learn pascal by this, so maybe if i dont get too lazy i will help

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 7:06 pm
by Steve Maughan
Hi Steven,

I'd certainly like to take a look. I use Delphi to develop all of my commercial applications and have access to Delphi XE2. This provides 64 bit support as well as iOS and Mac support.

Cheers,

Steve

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 8:00 pm
by mike_bike_kite
sje wrote:About thirty five years ago, David Slate, the co-author of the Northwestern Chess 4.x program, wrote a demonstration chess program in Pascal which was published in Byte magazine
How old is that in dog years (or whatever the computer equivalent is)?
Why did you pick a program that's that old?
I can only assume there were no publicly available fortran programs? :)

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 9:48 pm
by sje
Steve Maughan wrote:I use Delphi to develop all of my commercial applications and have access to Delphi XE2. This provides 64 bit support as well as iOS and Mac support.
This is all good to hear. The main reason I'd like to get others to become involved is to help test the portability of the source among different compilers and different machines. This is very important as the intended target audience are those new to Pascal, new to chess programming, or both. These folks do not need problems which are better handled by those with more experience.

For the initial development, I am purposely NOT including a graphical interface. However, I'm also not doing anything which might preclude connecting a graphical interface. The version I hope to have ready soon will have no input interface at all, just some hard-coded perft calculations with text output only.

And a few more working routines for manipulating a bitboard database:

Code: Select all

procedure bbdbaddman&#40;var bbdb&#58; bbdbtype; man&#58; manrtype; sq&#58; sqtype&#41;;
var
  color&#58; colortype;
begin
  with bbdb do
    begin
      color &#58;= mantocolor&#91;man&#93;;
      bbsetsq&#40;merge, sq&#41;;
      if mantosweeper&#91;man&#93; then
        bbsetsq&#40;sweep, sq&#41;;
      bbsetsq&#40;locbc&#91;color&#93;, sq&#41;;
      bbsetsq&#40;locbm&#91;man&#93;, sq&#41;;
      bbdbcutattacks&#40;bbdb, sq&#41;;
      bbdbaddattacks&#40;bbdb, sq, man&#41;;
    end;
end; &#123; bbdbaddman &#125;

procedure bbdbdelman&#40;var bbdb&#58; bbdbtype; man&#58; manrtype; sq&#58; sqtype&#41;;
var
  color&#58; colortype;
begin
  with bbdb do
    begin
      color &#58;= mantocolor&#91;man&#93;;
      bbresetsq&#40;merge, sq&#41;;
      if mantosweeper&#91;man&#93; then
        bbresetsq&#40;sweep, sq&#41;;
      bbresetsq&#40;locbc&#91;color&#93;, sq&#41;;
      bbresetsq&#40;locbm&#91;man&#93;, sq&#41;;
      bbdbdelattacks&#40;bbdb, sq, man&#41;;
      bbdbproattacks&#40;bbdb, sq&#41;;
    end;
end; &#123; bbdbdelman &#125;

procedure bbdbmovman&#40;var bbdb&#58; bbdbtype; man&#58; manrtype; frsq, tosq&#58; sqtype&#41;;
var
  color&#58; colortype;
  sweeper&#58; boolean;
begin
  with bbdb do
    begin
      color &#58;= mantocolor&#91;man&#93;;
      sweeper &#58;= mantosweeper&#91;man&#93;;
  
      &#123; Reset the origination square data &#125;
  
      bbresetsq&#40;merge, frsq&#41;;
      if sweeper then
        bbresetsq&#40;sweep, frsq&#41;;
      bbresetsq&#40;locbc&#91;color&#93;, frsq&#41;;
      bbresetsq&#40;locbm&#91;man&#93;, frsq&#41;;
      bbdbdelattacks&#40;bbdb, frsq, man&#41;;
      bbdbproattacks&#40;bbdb, frsq&#41;;
  
      &#123; Set the destination square data &#125;

      bbsetsq&#40;merge, tosq&#41;;
      if sweeper then
        bbsetsq&#40;sweep, tosq&#41;;
      bbsetsq&#40;locbc&#91;color&#93;, tosq&#41;;
      bbsetsq&#40;locbm&#91;man&#93;, tosq&#41;;
      bbdbcutattacks&#40;bbdb, tosq&#41;;
      bbdbaddattacks&#40;bbdb, tosq, man&#41;;
    end;
end; &#123; bbdbmovman &#125;

Re: Announcement: The Bozochess Project

Posted: Wed Oct 05, 2011 10:48 pm
by Sven
Hi Steven,

good to hear about your new project!
sje wrote:There has been considerable effort to use meaningful and somewhat long names which can be decoded without help from a cheat sheet.

Code: Select all

bbdbaddattacks
You have definitely achieved that goal.

Was it a requirement that a keyboard of which the SHIFT and underline keys are missing had to be used?

;-)

Sven

Re: Announcement: The Bozochess Project

Posted: Thu Oct 06, 2011 1:30 am
by sje
mike_bike_kite wrote:How old is that in dog years (or whatever the computer equivalent is)?
Why did you pick a program that's that old?
I can only assume there were no publicly available fortran programs? :)
ARF! ARF! ARF! YAP! ARF! WOOF! ARF! ARF! (Dog years in base 8.32 +7i Elephant years)

The Chess 0.5 program is mentioned only for purposes of comparison. The purposes it served way back then can be even better served today using a modern pedagogical program in a modern Pascal dialect.

Re: Announcement: The Bozochess Project

Posted: Thu Oct 06, 2011 1:40 am
by sje
Sven Schüle wrote:Was it a requirement that a keyboard of which the SHIFT and underline keys are missing had to be used?
you are making a jest at the expense of those of us with keyboards lacking a shift key. well, it could be worse. what if i had a keyboard that had no vwls or pncttn ks th wrds wld b rlly hrd to rd r wht f i ws lmtd t crllc kbrd &#1042;&#1089;&#1077; &#1087;&#1088;&#1086;&#1095;&#1080;&#1090;&#1072;&#1083;&#1080; &#1073;&#1099; &#1101;&#1090;&#1086; &#1074; &#1088;&#1091;&#1089;&#1089;&#1082;&#1086;&#1084; &#1103;&#1079;&#1099;&#1082;&#1077;?

More seriously, the Pascal tradition has been one of case insensitive source, a holdover from the Old Days. How to deal with this today? Some Pascal compilers are still case insensitive, others aren't, and others allow a user specified option. Which to choose? We don't want to leave any user locked out just because they don't have the "right" compiler?