QB64 Phoenix Edition
QBJS - Chess API - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: QBJS, BAM, and Other BASICs (https://qb64phoenix.com/forum/forumdisplay.php?fid=50)
+--- Thread: QBJS - Chess API (/showthread.php?tid=4453)

Pages: 1 2 3 4 5


QBJS - Chess API - dbox - 02-08-2026

As part of another project I'm working on, I wanted to find a chess engine that I could use from QBJS.  I ended up creating a simple wrapper for the js-chess-engine.  I created the following simple screen 0 chess UI to test it out.  Thought I would share it here.

   




RE: QBJS - Chess API - bplus - 02-08-2026

+1 Cool! assuming it works. Is white always played from bottom of screen or is that the player position? 

yeah looks like it... player is always White

First thing to do with this is translate mouse clicks to moves, too much typing bLOL


RE: QBJS - Chess API - TempodiBasic - 02-08-2026

@dbox

IMHO  you can use Stockfish or any other  chess engines with UCI protocol,(chess engine that uses UCI protocol UCI  protocol for communicating with other programs)


[Image: Stockfish-programs.png]



I think you have already taken a look to this website Chess Programming


RE: QBJS - Chess API - dbox - 02-08-2026

(02-08-2026, 03:32 PM)bplus Wrote: First thing to do with this is translate mouse clicks to moves, too much typing bLOL
Ha, for sure!  This UI was just to demonstrate using the chess API.  It could definitely use a bplus mod.


RE: QBJS - Chess API - bplus - 02-08-2026

2nd thing I'd do is put in black and white checkerboard squares to see diagonals better! I lost a Queen when I set her next to opposing King thinking it was in checkmate because I thought my Bishop backed up the Queen, oops! no! wrong diagonal, dang!


RE: QBJS - Chess API - SMcNeill - 02-08-2026

https://www.dafont.com/chess.font  <— just use that font with it.


RE: QBJS - Chess API - dbox - 02-08-2026

(02-08-2026, 06:09 PM)TempodiBasic Wrote: IMHO  you can use Stockfish or any other  chess engines with UCI protocol,(chess engine that uses UCI protocol UCI  protocol for communicating with other programs)
True, but for my purposes, I liked the simplicity of this API.  There is no complicated protocol to negotiate and there are really only a few methods that are needed.

First just use the QBJS Import statement to include the library:
Code: (Select All)
Import Chess From "https://boxgaming.github.io/qbjs-lib/chess/js-chess-engine.bas"

This will load the API and we can use the following methods to interact with the engine:

Move
Move the piece at a given board location to the specified new location
Code: (Select All)
If Chess.Move("C2", "C3") Then
    ' The move was successful
Else
    ' An error occurred, probably an invalid move
    Print Chess.LastErrorMessage
End If

AIMove
Let the engine make the next move using the specified difficulty level
Code: (Select All)
Chess.AIMove 3

Moves
Returns the list of available moves for the piece at the specified board location
Code: (Select All)
ReDim results(0) As String
results = Chess.Moves("C3")
For i = 1 To UBound(results)
    Print results(i)
Next i

BoardPieces
Returns a map containing the board locations with pieces present.
Code: (Select All)
Dim pieces() As String
pieces = Chess.BoardPieces
Print "B1: "; pieces("B1")
Print "E8: "; pieces("E8")
Print "G5: "; pieces("G5")
In the standard beginning positions the above would output:
Code: (Select All)
B1: N
E8: k
G5: 

The only other methods are NewGame, to reset the board for a new game and a few additional functions that return current game state information (IsCheck, IsCheckMate, IsFinished).


RE: QBJS - Chess API - dbox - 02-08-2026

(02-08-2026, 07:14 PM)SMcNeill Wrote: https://www.dafont.com/chess.font  <— just use that font with it.
Interestingly, the chess pieces are part of the Unicode standard now, so you can use them with most regular fonts too:



RE: QBJS - Chess API - TempodiBasic - 02-09-2026

@dbox
if it is useful,  after winning a game with lowest level, 
as I am lucky, I got this error state that I have captured with snapshot in Opera
here the image file


[Image: JSCHESS-Engine.png]
----------------------------------------------------------------------------------------
About the Screen 0 interface for JSChess_Engine:
for humans it is better:
1. shape of pieces than Letters (each language has its set of letters, which often is the first letter of its name: as curiosity you can recognize that Knight is N and not  K for avoiding confusion with King )

2. use 2 colors very different for brightness and grouping (one with more light and in the range of warm colors, while the second more darkness and in the range of cold colors), it helps the humans to see lines (row, column, diagonals, short lines) and shapes (squares, rectangles, triangles) increasing their speed of thinking

3. use a flipping chess table because the player uses to watch at chesstable from his perspective... it is rare to see a player looking from enemy's point of view or from a side to the 2 players

4. in Screen 0 it is possible to use the mouse for take input

5. the selected cell should be highlighted with a different grade of the same color or with a blinking of the piece that stands there. At the same time the cells of available moves should use a different color of highlighting.

Well. I think to have given too much feedback.
Thanks for sharing.


RE: QBJS - Chess API - bplus - 02-09-2026

(02-09-2026, 12:13 AM)TempodiBasic Wrote: @dbox
if it is useful,  after winning a game with lowest level, 
as I am lucky, I got this error state that I have captured with snapshot in Opera
here the image file


[Image: JSCHESS-Engine.png]
----------------------------------------------------------------------------------------
About the Screen 0 interface for JSChess_Engine:
for humans it is better:
1. shape of pieces than Letters (each language has its set of letters, which often is the first letter of its name: as curiosity you can recognize that Knight is N and not  K for avoiding confusion with King )

2. use 2 colors very different for brightness and grouping (one with more light and in the range of warm colors, while the second more darkness and in the range of cold colors), it helps the humans to see lines (row, column, diagonals, short lines) and shapes (squares, rectangles, triangles) increasing their speed of thinking

3. use a flipping chess table because the player uses to watch at chesstable from his perspective... it is rare to see a player looking from enemy's point of view or from a side to the 2 players

4. in Screen 0 it is possible to use the mouse for take input

5. the selected cell should be highlighted with a different grade of the same color or with a blinking of the piece that stands there. At the same time the cells of available moves should use a different color of highlighting.

Well. I think to have given too much feedback.
Thanks for sharing.

On the great side, its hooked up to a good Chess Engine unlike our previous experience where we had best interface to sucky Chess Engine!