Ideas for an engine playing Capablanca chess

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Ideas for an engine playing Capablanca chess

Postby Roland Chastain » 24 Jun 2019, 01:46

Hello! I would like to write an engine able to play Capablanca chess.

I have read this discussion and I am trying to see the advantages of a 15x12 board.

I would be glad to hear your ideas and suggestions.

Here is what I made today.

Code: Select all
function SquareToStr(const x, y: integer): string;
begin
  result := Chr(x + Ord('a') - 1) + Chr(y + Ord('1') - 1);
end;

type
  TChessboard = array[0..209] of char;

procedure ShowBoard(const ABoard: TChessboard);
var
  x, y: integer;
begin
  WriteLn('+ ABCDEFGHIJ');
  for y := 8 downto 1 do
  begin
    Write(Chr(y + Ord('0')), ' ');
    for x := 1 to 10 do
      Write(ABoard[15 * x + y + 20]);
    WriteLn;
  end;
end;

procedure InitBoard(var ABoard: TChessboard; const AFen: string);
var
  i: integer;
  x, y: integer;
  j: integer;
begin
  i := 1;
  x := 1;
  y := 8;
  while (i <= Length(AFen)) and (AFen[i] <> ' ') do
  begin
    case AFen[i] of
      'p', 'r', 'n', 'a', 'b', 'q', 'k', 'c', 'P', 'R', 'N', 'A', 'B', 'Q', 'K', 'C':
        begin
          ABoard[15 * x + y + 20] := AFen[i];
          Inc(x);
          Inc(i);
        end;
      '/':
        begin
          x := 1;
          Dec(y);
          Inc(i);
        end;
      '0'..'9':
        if (i < Length(AFen)) and (AFen[i] = '1') and (AFen[Succ(i)] = '0') then
        begin
          for j := 1 to 10 do
          begin
            ABoard[15 * x + y + 20] := '-';
            Inc(x);
          end;
          Inc(i, 2);
        end else
        begin
          for j := 1 to Ord(AFen[i]) - Ord('0') do
          begin
            ABoard[15 * x + y + 20] := '-';
            Inc(x);
          end;
          Inc(i);
        end;
    end;
  end;
end;

const
  CStartPos = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
  CCapablancaStartPos = 'rnabqkbcnr/pppppppppp/10/10/10/10/PPPPPPPPPP/RNABQKBCNR w KQkq - 0 1';

var
  b: TChessboard;
 
begin
  WriteLn('Standard chess start position:');
  FillChar(b, SizeOf(TChessboard), '#');
  InitBoard(b, CStartPos);
  ShowBoard(b);
  WriteLn;
 
  WriteLn('Capablanca chess start position:');
  FillChar(b, SizeOf(TChessboard), '#');
  InitBoard(b, CCapablancaStartPos);
  ShowBoard(b);
end.


Code: Select all
Standard chess start position:
+ ABCDEFGHIJ
8 rnbqkbnr##
7 pppppppp##
6 --------##
5 --------##
4 --------##
3 --------##
2 PPPPPPPP##
1 RNBQKBNR##

Capablanca chess start position:
+ ABCDEFGHIJ
8 rnabqkbcnr
7 pppppppppp
6 ----------
5 ----------
4 ----------
3 ----------
2 PPPPPPPPPP
1 RNABQKBCNR
Roland Chastain
 
Posts: 38
Joined: 24 Feb 2019, 12:45
Location: Dakar, Senegal

Re: Ideas for an engine playing Capablanca chess

Postby H.G.Muller » 25 Jun 2019, 19:10

It can have some advantages to make the board about twice the size of what you need. Then the differend between two on-board square numbers is a unique indication of the move step. If you use a 15x12 area to hold a 10x8 board, you don't have that: a step of >= 6 squares in the long direction can cross the 'guard band' as well as stay on board. So you cannot use the difference of two square numbers as index in a lookup table to get, for instance, the distance between the squares (dist[toSqr - fromSqr]). Of course you could use a 2-dimensional array dist[fromSqr][toSqr], but that would be slower and take a lot more memory space.

For that reason people often use 16x12 boards to hold 8x8.
User avatar
H.G.Muller
 
Posts: 3160
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Ideas for an engine playing Capablanca chess

Postby Roland Chastain » 27 Jun 2019, 16:53

Thank you for your answer. So I will try a 16x12 board. Would you know a code example that I could consult?

I never needed to compute the distance between two squares. Certainly I still have any things to learn. :)
Roland Chastain
 
Posts: 38
Joined: 24 Feb 2019, 12:45
Location: Dakar, Senegal

Re: Ideas for an engine playing Capablanca chess

Postby H.G.Muller » 28 Jun 2019, 21:55

Distance between squares can be important in the evaluation (e.g. between Pawn and Promotion square and between King and promotion square, to see who gets there first in a Pawn ending, and when checkmating a bare King having a short distance between the King is an advantage for the strong side). It can also be used in move generation, when you are in check: non-captures with a piece other than King that land farther away from the King than the checking piece cannot possibly resolve the mate, so you won't have to try those. (And in addition you could use another table indexed by the square difference to identify the direction in which you have to move to get from one to the other, to see if checker and to-square are in the same direction; if not, the move cannot block the check either.)
User avatar
H.G.Muller
 
Posts: 3160
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Ideas for an engine playing Capablanca chess

Postby Roland Chastain » 04 Jul 2019, 11:11

Thank you for your answer. I have almost finished a first version of the engine. It will be very weak, but it will always be one more participant for a possible tournament. :wink:
For now it has a UCI interface. It is easier for me because I already have some code for that. I started to translate to Pascal your Winboard protocol driver example, but I still need time to familiarize myself with this protocol.
Roland Chastain
 
Posts: 38
Joined: 24 Feb 2019, 12:45
Location: Dakar, Senegal

Re: Ideas for an engine playing Capablanca chess

Postby H.G.Muller » 04 Jul 2019, 12:32

Well, UCI is fine, if you would implement the UCI_Variant option as

option name UCI_Variant type combo default capablanca var capablanca

Then it can play through UCI2WB under WinBoard.
User avatar
H.G.Muller
 
Posts: 3160
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 4 guests