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
#1
After finding out how to access the UCI interface with the help of an introductory video, it is now possible to write a chess engine with Small Basic that can be integrated into chess programs.
The C# videos and further information can be found in the following thread: https://litdev.uk/mybb/showthread.php?tid=74

But there is still a long way to go to the first usable engine.
The 4 episodes of the C# video tutorial must be implemented in Small Basic and in C# programs.


Episode 1: Hello World

Code:
'Position Textwindow
TextWindow.Left = Desktop.Width/2+1
TextWindow.Top    = Desktop.Height/2+200
'Movelist for black
Move[1] = "bestmove e7e5"
Move[2] = "bestmove a7a6"
Move[3] = "bestmove b7b5"
Move[4] = "bestmove g8f6"
Move[5] = "bestmove g7g6"
Move[6] = "bestmove h7h5"
Move[7] = "bestmove f8g7"
Move[8] = "bestmove b8c6"
Movecount = 1
'LDTextWindow.Hide()
LDTextWindow.UpdateShowHide = "False"
LDTextWindow.Minimise()
While ("True")
  'TextWindow.PauseIfVisible()
  commandline = TextWindow.Read()
  command = LDText.Split(commandline," ")
  if(command[1] = "uci") Then
    TextWindow.WriteLine("uciok")
  ElseIf(command[1] = "isready") Then
    TextWindow.WriteLine("readyok")
  ElseIf(command[1] = "position") Then
    'Board Update
  elseif(command[1] = "go") Then
    'TextWindow.WriteLine("bestmove e7e5")
    TextWindow.WriteLine(Move[Movecount])
    Movecount = Movecount + 1
  Else
    TextWindow.WriteLine("info string "+ commandline)
  endif
  Program.Delay(7)  
EndWhile

Integrating the exe file as an engine into a chess program is described in the C# thread and in the videos.

   

What is also annoying is that the text window cannot be hidden and it has no content.
But since it can be moved to the side, it is still acceptable.

Update: 
With the features LDTextWindow.UpdateShowHide = "False" and LDTextWindow.Minimise() the text window can be minimized to the taskbar.
This requires the Litdev extension 1.2.28.0 or higher. Alternatively, the two lines can be commented out and the text window will appear on the screen.

Note:
If the SB_UCI.exe engine is distributed or copied to another directory, the DLLs Litdev.dll and SmallBasicLibrary.dll must also be included!
[-] The following 2 users Like Scout's post:
  • AbsoluteBeginner, litdev
Reply
#2
Updated LitDev extension Beta (1.2.28.0) to better manage TW hide and show.  There are a couple issues:

1] TextWindow.Read for example will show the TextWindow if currently hidden
2] TextWindow object keeps track of the current state and this is not updated if the user minimises window for example

This is why minimising TW with Cute Chess works - it is minimised but SB thinks it is shown.

Try using:

Code:
LDTextWindow.UpdateShowHide = "False"
LDTextWindow.Minimise()

or

PHP Code:
LDTextWindow.UpdateShowHide "False"
LDTextWindow.Hide() 

The new property UpdateShowHide (default True) will also update the internal variable, which in this case you don't want since we want TextWindow.Read to think the window is currently shown when in fact it is hidden or minimised.  Its all a bit hacky, but we are working within the original SB code.
Reply
#3
After downloading Litdev_Beta.zip and copying the dll and xml into the lib directory of SB, the new text window methods are not recognized!?
The file version is 1.2.28 but the date is May 3rd.
Is litdev.uk not updated yet?
Reply
#4
Sorry, my mistake - hopefully uploaded correctly now - I tested the download.

I have been playing with your chess program, not following the Youtube so much, but doing it more suitably for Small Basic, first mimicing the game state (mostly done this), next finding valid moves, then choosing one that is at least not a terrible choice.
[-] The following 1 user Likes litdev's post:
  • Scout
Reply
#5
Scout,

Please ignore if you are working on this and having fun working it out on your own, but I got interested and this is my work so far BKJK641.000 - it plays OK (as black only in this version) with Cute Chess, but with poor endgame.  I guess the uploaded chess piece images are yours Smile .

EDIT

Minor update to run as Black or White player, BKJK641.000-0.
[-] The following 1 user Likes litdev's post:
  • Scout
Reply
#6
Litdev,

it's incredible how quickly you can create a chess program. This way I can take a shortcut and not necessarily go through C# MinimalChess. It's a hard road for me to create a new C# program with the videos and the inconsistent source code.  Sad
I think your program is a good starting point and I can compare MinimalChess and Chessforeva with it. Shy
The pieces are from Chessforeva and I modified them to 64x64bit Gif. I assume there are no copyright issues here.
I tend to use font pieces for the engine display anyway so that it doesn't get too big.

Thank you very much
Scout
[-] The following 1 user Likes Scout's post:
  • litdev
Reply
#7
Scout, 

I thought this may interest you, I found a SB chess program from around 2019 in my files - Unfortunately I can't remember who wrote it, but it's quite nice written by someone who clearly knows something about chess, CCBF116.000.

EDIT Based on database of historical SB forum files I think this was written originally by backtothestart, TKM405.

Also, if anyone fancies some 3D challenge, there are some nice free 3D chess pieces out there for fancy visualisation, below is some I had a go with.

[Image: 3DChess.png]
[-] The following 2 users Like litdev's post:
  • AbsoluteBeginner, Scout
Reply
#8
(translated by Google translator)

Hi all.
Nine years ago I was looking for something new in this ancient game called "Chess".
Then I thought that this game could be improved by adding new features.
I didn't change the rules of the game, but I added more cells and figures to the field.
Here's what I got.

   
   

At that time, programming in Small BASIC was not as convenient as it is now using SB-Prime.
If anyone also wants to give an ancient game a new life on a new playing field, then maybe that person will like my version. Rolleyes
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
#9
AB,

64 square chess is hard enough!  Do you have the SB code for this?
Reply
#10
(06-04-2024, 02:02 PM)litdev Wrote: AB,

64 square chess is hard enough!  Do you have the SB code for this?

Yes, 64 chess squares are really difficult if a person knows how to play well. I know from myself that for a person who is an amateur in chess, an 8 by 8 field very soon becomes small.  Wink
A person begins to feel as if he has been playing the same thing for several years now.

And then the idea comes to mind to make a large field and have many figures.
And dreamers like me, in addition, come up with the idea of adding “fog of war” (!) to the game. ( Imagine: each piece has a customizable ability to SEE enemy pieces at a distance of several cells. Pawns can see at a distance of 3 or 4 squares. The queen can see the enemy at a distance of 6 or 8 squares, for example. )
Can you imagine a chess battle in conditions where you don’t see your opponent’s pieces until they are close enough?!
This is great! Isn't it true?!

I still have the code. But this code is not completed yet.
This is working. The program allows you to move all the pieces, so two people can play. It seems to me that I made a function for saving an unfinished batch. ( I don't remember exactly anymore. Besides, nine years ago I was even more of a complete absolute beginner than I am now. )

Rolleyes
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)