10-30-2024, 10:41 PM
Fixing the backward-moving pawn
Saving all variables for each move in a file with
LDFile.SaveAllVariables(Program.Directory +"\Dump" + numMove + ".txt")
was not the best way, because the arrays are output without line breaks (\n).
It also generates an error message if not all variables are used once.
After that, I just wrote the valid moves for each move into a file. This works quite well with
LDFile.WriteFromArray(Program.Directory + "\DumpValidMove" + numMove + ".txt" , validMove , "FALSE")
In the 13th move for black, the function ValidMoves() determined the following valid moves:
a7a6
a7a5
b7b6
b7b5
g7g6
g7g5
e6e5
e6e5
f6g6
f6h6
f6f5
f6f4
f6f3
f6g5
f6e5
f6d4
d6c7
d6b8
d6e5
d6f4
d6g3
d6h2
d6c5
d6b4
d6a3
d5c3
d5e3
d5b4
d5f4
d5b6
d5c7
h4h3
h4h5
The incorrect pawn move can be seen at the end of the list. A closer look at the source code for generating the pawn moves revealed that the variable r1 had no initialization and could therefore take on any value from the previous run.
After inserting r1 = rank the faulty move was no longer present and the program continued to run correctly.
The current program ID for SB_Scout is PDVF923.000-1
Saving all variables for each move in a file with
LDFile.SaveAllVariables(Program.Directory +"\Dump" + numMove + ".txt")
was not the best way, because the arrays are output without line breaks (\n).
It also generates an error message if not all variables are used once.
After that, I just wrote the valid moves for each move into a file. This works quite well with
LDFile.WriteFromArray(Program.Directory + "\DumpValidMove" + numMove + ".txt" , validMove , "FALSE")
In the 13th move for black, the function ValidMoves() determined the following valid moves:
a7a6
a7a5
b7b6
b7b5
g7g6
g7g5
e6e5
e6e5
f6g6
f6h6
f6f5
f6f4
f6f3
f6g5
f6e5
f6d4
d6c7
d6b8
d6e5
d6f4
d6g3
d6h2
d6c5
d6b4
d6a3
d5c3
d5e3
d5b4
d5f4
d5b6
d5c7
h4h3
h4h5
The incorrect pawn move can be seen at the end of the list. A closer look at the source code for generating the pawn moves revealed that the variable r1 had no initialization and could therefore take on any value from the previous run.
Code:
'___________________Pawn____________________________
If (piece = "P") Then
If (player = "W" And rank < 8) Then
r = rank+1
ElseIf (player = "B" And rank > 1) Then
r = rank-1
EndIf
If (r <> rank) Then
pos = Text.GetCharacter(charA+file)+r
color = Text.GetSubText(state[pos],1,1)
If (color = "") Then 'straight ahead
numValid = numValid+1
validMove[numValid] = index+pos
If (r = 1 Or r = 8) Then 'Promotion
score[numValid] = 9
validMove[numValid] = validMove[numValid]+"q"
EndIf
r1 = rank 'initialise r1
If (player = "W" And rank = 2) Then 'double step
r1 = rank+2
ElseIf (player = "B" And rank = 7) Then
r1 = rank-2
EndIf
If (r1 <> rank) Then
pos = Text.GetCharacter(charA+file)+r1
color = Text.GetSubText(state[pos],1,1)
If (color = "") Then
numValid = numValid+1
validMove[numValid] = index+pos
EndIf
EndIf
EndIf
If (file > 1) Then
pos = Text.GetCharacter(charA+file-1)+r 'left
color = Text.GetSubText(state[pos],1,1)
If (color = opponent) Then
numValid = numValid+1
validMove[numValid] = index+pos
ScoreMove()
EndIf
EndIf
If (file < 8) Then
pos = Text.GetCharacter(charA+file+1)+r 'right
color = Text.GetSubText(state[pos],1,1)
If (color = opponent) Then
numValid = numValid+1
validMove[numValid] = index+pos
ScoreMove()
EndIf
EndIf
EndIf
The current program ID for SB_Scout is PDVF923.000-1