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
#11
For your information, the following programs from the old published programs contain the word chess.
The number after the publication number is the number of lines in the program.

CXV562 547
DBG614 109
DBX768 1169
FXQ239 2 (1470 lines as text)
GMT047-1 872
GQC905 1223
HBD489 2747
HQQ405 289
HQQ405-0 307
HQQ405-2 403
HQQ405-3 426
JWC757 1203
KBG448 1329
KNR573 1370
MQR842 523
MRH408 1472
NBH742 1156
QXQ421 1157
SFW403 1177
SJQ481 1162
SJQ481-3 1162
SQC882 1214
TKM405 1179
TLL449 149
TNS425 1471
VGR040 1175
VVS441 29

EDIT : two number of lines edited
[-] The following 3 users Like WhTurner's post:
  • AbsoluteBeginner, litdev, Scout
Reply
#12
New UCI Chess Engine SB_Scout 

' Program: UCI-Engine SB_Scout
' based on  BKJK641.000-0 by litdev
' and  LitDev Extension  V 1.2.29.10  for .Net 4.8  framework  and  Small Basic 1.2
'
' submitted by scout
' PDVF923.000    10-10-2024   - add enPassant in MoveState() and MovePiece()
'                                           - add UCI-Command quit
'                                           - add analyze board chesspieces by fonts
'                                           - add DataView for displaying move score
' PDVF923.000-0  10-24-2024  - Drawing selected move from DataView as arrow in the analysis board


My next challenge is the following error 

   
[-] The following 1 user Likes Scout's post:
  • AbsoluteBeginner
Reply
#13
Mmm,

Pawn moving backwards!

I guess the hardest bit is getting it to reproduce if you can't see in the code why it happens.

I think I also didn't implement castling.
Reply
#14
Hi all.

This is a very interesting project.
Even my mood became good. Rolleyes

Now I'll get to know this project better and then, maybe, I'll want to make a SB-AI that will learn to play chess well on its own.
I plan to tell this SB-AI only the rules of the game and give it the ability to learn on its own.

It would probably be cool if this SB-AI was a stand-alone program.
It would be really cool if SB-AI could SEE the chessboard with its "eyes".  Rolleyes

( finally an interesting task has appeared again )
Reply
#15
@litdev
The 15 moves shown in Cute Chess are reproducible, as SB_Scout has always played the same moves.
I'm still considering whether to approach the problem with the debugger or text window output.

Scout
Reply
#16
I was learning pipes and memory maped file just like server client we currently use in SB for transmitting data.
But they are faster than server client but work on local.
I guess I could Implement it in extension for pipes.
ZS
Reply
#17
@Scout 

Naively, it looks like black is moving as if it were white.
I would start with some basic debug output to a file to be really sure which bit of code is the culprit.  You can waste a lot of time chasing rabbits down the wrong holes.
Only move to debugging when you have some sort of idea what could be the issue
[-] The following 1 user Likes litdev's post:
  • Scout
Reply
#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


Forum Jump:


Users browsing this thread: 2 Guest(s)