We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UCI Chess Engine
#18
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.

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
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
[-] The following 1 user Likes Scout's post:
  • litdev
Reply


Messages In This Thread
UCI Chess Engine - by Scout - 05-22-2024, 09:44 PM
RE: UCI Chess Engine - by litdev - 05-23-2024, 05:21 PM
RE: UCI Chess Engine - by Scout - 05-23-2024, 06:38 PM
RE: UCI Chess Engine - by litdev - 05-23-2024, 07:48 PM
RE: UCI Chess Engine - by litdev - 05-24-2024, 08:36 PM
RE: UCI Chess Engine - by Scout - 05-24-2024, 09:46 PM
RE: UCI Chess Engine - by litdev - 06-03-2024, 10:23 PM
RE: UCI Chess Engine - by AbsoluteBeginner - 06-04-2024, 08:42 AM
RE: UCI Chess Engine - by litdev - 06-04-2024, 02:02 PM
RE: UCI Chess Engine - by AbsoluteBeginner - 06-04-2024, 04:06 PM
RE: UCI Chess Engine - by WhTurner - 06-04-2024, 05:42 PM
RE: UCI Chess Engine - by Scout - 10-24-2024, 08:12 PM
RE: UCI Chess Engine - by litdev - 10-25-2024, 07:56 AM
RE: UCI Chess Engine - by AbsoluteBeginner - 10-25-2024, 08:02 AM
RE: UCI Chess Engine - by Scout - 10-25-2024, 08:27 AM
RE: UCI Chess Engine - by z-s - 10-25-2024, 09:46 AM
RE: UCI Chess Engine - by litdev - 10-25-2024, 06:18 PM
RE: UCI Chess Engine - by Scout - 10-30-2024, 10:41 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)