Ideas for an engine playing Capablanca chess
Posted: 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.
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