Hi,

I am currently playing around with the GNU Chess engine and patching
around in it for fun, and while doing so, found some minor bugs in the
source.

As I am new to the project and not yet clear about e.g. the coding
style, let me start with a simple and trivial fix: currently one
cannot correctly load EPD files; the following happens:

```
$ cat t
rnbqkb1r/pppppppp/5n2/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - bm 1; id 1;
$ src/gnuchess  --easy
GNU Chess
Can't open file "(null)": Bad address - using defaults
White (1) : post
White (1) : depth 5
Search to a depth of 5.
White (1) : load t

 : Best move = 1

white  KQkq

r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

Error loading EPD file 't'.
White (1) : f4
1. f4

black  KQkq  f3

r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P P . .
. . . . . . . .
P P P P . . P P
R N B Q K B N R

Thinking...
1 -6 0 2 a5
White (1) : 1 -1 0 4 b5
1 +41 0 8 d5
1 +43 0 21 Nc6
2 +9 0 47 Nc6 Nc3
3 +43 0 155 Nc6 Nc3 Nf6
4 +9 0 788 Nc6 Nf3 Nf6 Nc3
5 +37 0 2920 Nc6 Nf3 Nf6 Nc3 d5
5 +37 1 5024 Nc6 Nf3 Nf6 Nc3 d5

white  KQkq

r . b q k b . r
p p p p p p p p
. . n . . n . .
. . . . . . . .
. . . . P P . .
. . . . . . . .
P P P P . . P P
R N B Q K B N R


My move is : Nc6
```

So it's not taking the free pawn on e4.

If I instead don't load, but play the move from scratch, it reliably will.

A clue is the "Error loading EPD file 't'." message, and indeed, the
code has a bug there - it uses strlen on a buffer that's initialized
empty (thus is always 0) when clearly sizeof was intended, and on
failure it seems the board is loaded into some variables but not into
others. After this patch:

```
>From 7655b2c6bb98d1bfec5852124d05adec34df353d Mon Sep 17 00:00:00 2001
From: Rudolf Polzer <[email protected]>
Date: Thu, 29 May 2025 06:46:39 -0400
Subject: [PATCH 1/1] Fix loading EPD files.

---
 src/frontend/cmd.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/frontend/cmd.cc b/src/frontend/cmd.cc
index f038e62..dacbd66 100644
--- a/src/frontend/cmd.cc
+++ b/src/frontend/cmd.cc
@@ -394,7 +394,7 @@ void cmd_load(void)
     printf (_("Board is wrong!\n"));
   } else {
     /* Read EPD file and send contents to engine */
-    if (build_setboard_cmd_from_epd_file(data, epd_filename, strlen(data))) {
+    if (build_setboard_cmd_from_epd_file(data, epd_filename, sizeof(data))) {
       SetDataToEngine( data );
       SetAutoGo( true );
     } else {
-- 
2.39.5
```

it's taking the pawn just fine:

```
$ src/gnuchess --easy
GNU Chess
Can't open file "(null)": Bad address - using defaults
White (1) : post
White (1) : depth 5
Search to a depth of 5.
White (1) : load t

 : Best move = 1

white  KQkq

r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

White (1) : f4
1. f4

black  KQkq  f3

r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P P . .
. . . . . . . .
P P P P . . P P
R N B Q K B N R

Thinking...
Thinking...
1 +168 0 2 Nxe4
Black (1) : 2 +130 0 130 Nxe4 Nc3
3 +132 0 547 Nxe4 Nc3 d5 Nxe4 dxe4
4 +117 0 1471 Nxe4 d3 Nc5 Nc3
5 +135 1 5352 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4
5 +135 1 7197 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4

white  KQkq

r n b q k b . r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . n P . .
. . . . . . . .
P P P P . . P P
R N B Q K B N R


My move is : Nxe4
```

Does this patch look correct? Hope Gmail didn't ruin things - I can
try using another address if it doesn't work well with this mailing
list, but would like any commits to be associated with this primary
one if possible.

Thank you,

Rudolf "divVerent" Polzer

Reply via email to