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: 41
Joined: 24 Feb 2019, 12:45
Location: France

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: 3167
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: 41
Joined: 24 Feb 2019, 12:45
Location: France

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: 3167
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: 41
Joined: 24 Feb 2019, 12:45
Location: France

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: 3167
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Durandal 0.0.1

Postby Roland Chastain » 19 Jul 2019, 19:16

Thanks for this indication.

In case you would be interested in testing it, here is a first working version of the engine. It can play traditional chess, FRC, Capablanca and CRC. It plays very bad, but for now my ambition was only to get a functional program. I hope I will find time to try to make it play a little better.

I tested it with Cute Chess and Winboard.

Durandal 0.0.1
Roland Chastain
 
Posts: 41
Joined: 24 Feb 2019, 12:45
Location: France

Re: Ideas for an engine playing Capablanca chess

Postby H.G.Muller » 24 Jul 2019, 14:57

Indeed, it woks. Like you say, it isn't very strong. I tried it against Fairy-Max, the latter limited to a depth of 1 ply. Fairy-Max scored 91% (82+, 18=, 0-). The draws were all stalemates (which Fairy-Max does not recognize at 1-ply) where Fairy-Max had an overwhelming amount of material against a bare King. So I suppose Durandal does not really think ahead, but is more like the non-searching engines N.E.G. or POS.

Durandal got stuck in games, though, always after the opponent promoted. I guess this is a matter of having too many Queens on the board.

I tried it against N.E.G. in normal Chess. N.E.G. scored 84.5% here (81+ 27= 2-). Durandal wins overwhelmingly against a random mover, though. So much, in fact, that it also gets stuck here when it has many Queens itself, and the random mover has a bare King.

Here are the Capablanca games where it got stuck:

Code: Select all
[Event "Computer Chess Game"]
[Site "MAKRO-PC"]
[Date "2019.07.24"]
[Round "14"]
[White "Fairy-Max 5.0b6"]
[Black "Durandal 0.0.1 (UCI2WB)"]
[Result "*"]
[TimeControl "40/60"]
[Variant "capablanca"]

1. c3 {+0.19/1} a6 2. d3 {+0.18/1} a5 3. Axi7 {+1.27/1} Ci6 4. Af4
{+1.00/1} g5 5. Ae3 {+1.00/1} Cxi2 6. Axg5 {+1.00/1} h6 7. Af4 {+1.00/1} a4
8. Nd2 {+1.18/1} a3 9. bxa3 {+0.97/1} Rxa3 10. Ne4 {+1.09/1} b6 11. Nh3
{+1.15/1} b5 12. Bc2 {+1.01/1} b4 13. cxb4 {+1.94/1} d6 14. Ae3 {+2.00/1}
c6 15. Nf4 {+2.06/1} c5 16. bxc5 {+3.04/1} dxc5 17. Axc5 {+3.00/1} Ra8 18.
h4 {+3.09/1} f6 19. Nxf6 {+4.18/1} Qc6 20. Ng6+ {+3.97/1} Kf7 21. Ne5+
{+4.15/1} Kxf6 22. Nxc6 {+7.19/1} Nxc6 23. Ae4+ {+7.30/1} Ke6 24. Axc6
{+10.60/1} Ra6 25. Axd8+ {+13.90/1} Kd6 26. a4 {+14.09/1} e5 27. e4
{+13.96/1} h5 28. Bh2 {+13.93/1} j6 29. Bg3 {+13.97/1} j5 30. Rb1
{+13.90/1} j4 31. Rc1 {+13.90/1} j3 32. Rd1 {+13.26/1} Nh6 33. Rc1
{+13.26/1} Ng4 34. Rd1 {+13.26/1} Nh6 35. Rb1 {+13.26/1} Ng4 36. Rc1
{+13.26/1} Nh6 37. Rd1 {+13.26/1} Ng4 38. Rb1 {+13.26/1} Nh6 39. Ra1
{+13.26/1} Ng4 40. Ra3 {+13.26/1} Nh6 41. Qd1 {+13.26/1} Ni8 42. Qxh5
{+14.40/1} Ng7 43. Bxe5+ {+15.14/1} Kd7 44. Qg5 {+15.49/1} Ri8 45. Bxg7
{+18.30/1} Bh7 46. Af7 {+18.36/1} Bi6 47. Axj3 {+20.00/1} Rxa4 48. Axi2+
{+27.75/1} Bg4 49. Bxa4+ {+32.30/1} Kc7 50. Axg4 {+36.24/1} Ab6 51. Bc2
{+36.10/1} Rg8 52. Be5+ {+36.06/1} Kb7 53. Qxg8 {+41.01/1} Ac5 54. Qg7+
{+40.75/1} Kb6 55. Qg6+ {+40.75/1} Kb7 56. Rb3+ {+40.75/1} Ka7 57. j4
{+41.07/1} Aa4 58. h5 {+40.82/1} Ac5 59. h6 {+41.35/1} Aa4 60. h7
{+41.97/1} Axb3 61. Bxb3 {+45.50/1} Ka8 62. h8=Q+ {+52.76/1} Ka7 63. Be6
{+52.96/1} Kb7 64. g3 {+52.86/1} Ka7 65. Kg2 {+52.86/1} Kb7 66. f4
{+52.88/1} Ka7 67. Kf3 {+52.86/1} Kb7 68. d4 {+52.84/1} Ka7 69. d5
{+52.91/1} Kb7 70. d6 {+53.44/1} Ka7 71. d7 {+54.06/1} Kb7 72. d8=Q
{+61.32/1}
*

[Event "Computer Chess Game"]
[Site "MAKRO-PC"]
[Date "2019.07.24"]
[Round "19"]
[White "Durandal 0.0.1 (UCI2WB)"]
[Black "Fairy-Max 5.0b6"]
[Result "*"]
[TimeControl "40/60"]
[Variant "capablanca"]

1. a3 c6 {+0.22/1} 2. a4 g6 {+0.22/1} 3. b3 d6 {+0.21/1} 4. a5 Axi2
{+1.14/1} 5. Ci3 Af5 {+1.00/1} 6. g4 Ae6 {+1.00/1} 7. Cxi7 Axg4 {+1.00/1}
8. h3 Ah5 {+1.00/1} 9. Ci5 Nd7 {+1.18/1} 10. a6 bxa6 {+0.97/1} 11. Rxa6 Ne5
{+1.09/1} 12. b4 Nh6 {+1.15/1} 13. b5 cxb5 {+1.94/1} 14. c3 Nf5 {+2.06/1}
15. c4 bxc4 {+3.04/1} 16. d3 h6 {+3.07/1} 17. Ci2 Bh7 {+3.03/1} 18. dxc4
Nxc4 {+3.09/1} 19. f3 Rb8 {+3.00/1} 20. Nc3 Rb2 {+3.00/1} 21. Bxa7 Axf3
{+3.00/1} 22. Qf2 Ah1 {+3.00/1} 23. Axb2 Axi2 {+6.87/1} 24. Qxi2 Nxb2
{+6.87/1} 25. Bc2 Nc4 {+7.13/1} 26. e4 Nce3+ {+7.06/1} 27. Bxe3 Nxe3+
{+7.09/1} 28. Ke1 Nxc2+ {+7.89/1} 29. Qxc2 Bc7 {+7.81/1} 30. h4 Qd7
{+7.80/1} 31. Nh3 Qxh3 {+10.75/1} 32. Ri1 Qxh4+ {+11.90/1} 33. Kd1 Qj4
{+12.12/1} 34. e5 dxe5 {+12.94/1} 35. j3 Qxj3 {+13.91/1} 36. Nb1 Bd6
{+13.99/1} 37. Nd2 j5 {+13.91/1} 38. Nb1 Qh3 {+13.90/1} 39. Nd2 Qj3
{+13.90/1} 40. Nb1 Qg3 {+13.90/1} 41. Rh1 Qf3+ {+13.90/1} 42. Kc1 Qxh1+
{+18.89/1} 43. Kb2 Qi1 {+18.85/1} 44. Nc3 Qj1 {+18.65/1} 45. Na2 Qi1
{+18.65/1} 46. Nc3 Qh1 {+18.65/1} 47. Na2 Qj1 {+18.65/1} 48. Nc3 Qi1
{+18.65/1} 49. Na2 Qh1 {+18.65/1} 50. Nc3 Qg1 {+18.65/1} 51. Na2 Qf1
{+18.65/1} 52. Ra7 e6 {+18.65/1} 53. Nc3 g5 {+18.72/1} 54. Qd2 Bd3
{+18.69/1} 55. Na2 e4 {+18.70/1} 56. Nc3 Bf4 {+18.71/1} 57. Qi2 e3
{+19.23/1} 58. Na2 e2 {+19.85/1} 59. Rxf7+ Kxf7 {+23.34/1} 60. Nb4 e1=Q
{+30.36/1} 61. Na2 Bf5 {+31.01/1} 62. Qi3 Kf6 {+30.99/1} 63. Qb3 e5
{+30.97/1} 64. Qa3 e4 {+31.04/1} 65. Qa4 e3 {+31.57/1} 66. Qa7 e2
{+32.19/1} 67. Qb7 h5 {+32.25/1} 68. Qa7 h4 {+32.32/1} 69. Qb7 h3
{+32.85/1} 70. Qa7 h2 {+33.47/1} 71. Nb4 h1=Q {+40.72/1} 72. Na2 g4
{+40.79/1} 73. Qa6+ Ke5 {+40.79/1} 74. Qa7 g3 {+41.41/1} 75. Qc7+ Ke4
{+41.42/1} 76. Qb7+ Ke5 {+41.42/1} 77. Qa7 g2 {+42.03/1} 78. Nb4 g1=Q
{+49.37/1} 79. Qxg1 Qfxg1 {+49.33/1} 80. Na2 j4 {+49.34/1} 81. Kb3 j3
{+49.96/1} 82. Ka3 j2 {+50.58/1} 83. Nc1 j1=Q {+57.83/1}
*

[Event "Computer Chess Game"]
[Site "MAKRO-PC"]
[Date "2019.07.24"]
[Round "77"]
[White "Durandal 0.0.1 (UCI2WB)"]
[Black "Fairy-Max 5.0b6"]
[Result "*"]
[TimeControl "40/60"]
[Variant "capablanca"]

1. a3 g6 {+0.20/1} 2. a4 Nh6 {+0.25/1} 3. a5 d6 {+0.18/1} 4. a6 Nxa6
{+1.17/1} 5. b3 Axi2 {+2.01/1} 6. Rxa6 Axh1 {+7.65/1} 7. Ra5 c5 {+7.77/1}
8. Ra3 Nf5 {+7.71/1} 9. b4 cxb4 {+8.55/1} 10. Rb3 Ai2 {+8.65/1} 11. Rxb4
Axj1 {+11.40/1} 12. Rxb7 h5 {+11.53/1} 13. c3 Bh7 {+11.43/1} 14. c4 Ai2
{+11.40/1} 15. c5 dxc5 {+12.36/1} 16. d3 Qc6 {+12.40/1} 17. Rb3 Ci8
{+12.40/1} 18. d4 cxd4 {+13.42/1} 19. Nc3 dxc3 {+15.15/1} 20. e3 c2
{+17.64/1} 21. Bxc2 Qxc2 {+18.99/1} 22. Aa3 Qxb3 {+23.75/1} 23. Ac5 Qb2
{+23.75/1} 24. e4 Qc2 {+23.75/1} 25. exf5 Qxc5 {+28.95/1} 26. fxg6 Bxg6
{+29.06/1} 27. f3 Qxg1+ {+32.40/1} 28. Ke2 Qxh2 {+33.54/1} 29. f4 Qxf4
{+34.40/1} 30. g3 Axg3+ {+35.40/1} 31. Qxg3 Qxg3 {+36.65/1} 32. j3 Qxi1
{+39.75/1} 33. j4 a5 {+39.82/1} 34. j5 e5 {+39.82/1} 35. Kd2 Bg5+
{+39.90/1} 36. Ke2 O-O-O {+39.86/1} 37. Kf2 Kd7 {+39.86/1} 38. Ke2 f5
{+39.82/1} 39. Kf2 f4 {+39.85/1} 40. Ke2 i5 {+39.82/1} 41. jxi6 jxi6
{+39.81/1} 42. Kd2 f3+ {+40.38/1} 43. Kc3 f2 {+41.00/1} 44. Kb3 f1=Q
{+48.25/1} 45. Ka3 Ke6 {+48.37/1} 46. Ka4 Qe1 {+48.30/1} 47. Ka3 i5
{+48.33/1} 48. Ka4 Kf5 {+48.33/1} 49. Ka3 e4 {+48.31/1} 50. Ka4 e3
{+48.93/1} 51. Ka3 e2 {+49.55/1} 52. Ka4 h4 {+49.59/1} 53. Ka3 h3
{+50.21/1} 54. Ka4 h2 {+50.83/1} 55. Ka3 h1=Q {+58.08/1} 56. Ka4 i4
{+58.14/1} 57. Ka3 i3 {+58.76/1} 58. Ka4 i2 {+59.38/1} 59. Ka3 Bf4
{+59.42/1} 60. Ka4 Qa1+ {+59.41/1} 61. Kb5 e1=Q {+66.63/1}
*
User avatar
H.G.Muller
 
Posts: 3167
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Ideas for an engine playing Capablanca chess

Postby Roland Chastain » 24 Jul 2019, 17:14

Thank you very much for taking the time to try Durandal and give a detailed report. It's very nice and it will encourage me to improve the program. 8-)

I think I know what is causing the problem of the program stuck after promotions. I will make the necessary changes before releasing the next version.

By the way, I opened a repository on GitHub.
Roland Chastain
 
Posts: 41
Joined: 24 Feb 2019, 12:45
Location: France

Re: Ideas for an engine playing Capablanca chess

Postby Roland Chastain » 26 Jul 2019, 15:53

Released Durandal 0.0.2. The issue previously discussed (program stuck after promotions) should be solved. The ZIP archive includes a random mover.

Code: Select all
Rank Name                          Elo     +/-   Games   Score   Draws
   1 Moustique 0.2                 382     252      20   90.0%   20.0%
   2 Belofte 0.2.7                 168     175      20   72.5%   15.0%
   3 NEG 0.3                       -17     105      20   47.5%   55.0%
   4 Durandal 0.0.2                -89     118      20   37.5%   45.0%
   5 Iota 0.3                     -108     112      20   35.0%   50.0%
   6 Durandom                     -269     230      20   17.5%   15.0%
Finished match
Roland Chastain
 
Posts: 41
Joined: 24 Feb 2019, 12:45
Location: France


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 3 guests