Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QBJS - Chess API
#20
@dbox once again QBJS does not like something that works perfectly in QB64.

Code: (Select All)
Function GetMove$
    Dim As String boardX, boardY, retorn, k, b
    Dim As Long mx, my, mb, bx, by

    Do
        While _MouseInput: Wend
        mx = _MouseX: my = _MouseY ' convert into char cells
        mb = _MouseButton(1)
        If mb Then
            Locate 14, 50: Print Space$(15)
            Locate 14, 50: Print mx, my
            boardX = "": boardY = ""
            ' check mx
            If (mx Mod 4) <> 0 Then
                If mx > 4 And mx < 39 Then
                    bx = Int((mx - 4) / 4) + 1
                    boardX = Chr$(64 + bx)
                End If
            End If
            If my Mod 2 = 0 Then
                If my > 3 And my < 19 Then
                    by = Int((my - 2) / 2)
                    boardY = _Trim$(Str$(9 - by))
                End If
            End If
            Locate 15, 50: Print Space$(15)
            Locate 15, 50: Print boardX, boardY
        End If
        If (boardX <> "") And (boardY <> "") Then
            retorn = boardX + boardY
        Else
            k = InKey$
            If Len(k) = 1 And UCase$(k) = "Q" Then
                retorn = k
            Else
                b = b + k
                If Len(b) = 2 Then retorn = b
            End If
        End If
    Loop Until retorn <> ""
    GetMove$ = retorn
End Function

BTW I had to Dim all my variables in the function GetMove$ to get it accepted by QBJS. I thought you fixed all that!

After adding the above routine I commented out the input line in chess program and used GetMove$ to accept mouse clicks or keypresses.

Here is test GetMove$ for QB64, I sim the screen QBJS writes looks like screen 0 as not screen statements say otherwise is that the problem? QBJS has no screen 0. BTW _MouseX and _MouseY in screen 0 of QB64 does char cells not pixels, same with QBJS. Otherwise I dont know why the codes perfectly in QB64 but not QBJS????

Code: (Select All)
' test qbjs get move for chess ' b+ 2026-02-12
Do Until _KeyDown(27)
    PrintBoard
    gm$ = ""
    gm$ = GetMove$
    If gm$ <> "" Then
        Color 7, 0
        Locate 22, 50
        Print gm$; "   zzz... sleeping."
        Sleep
        Cls
        _KeyClear
    End If
Loop

Function GetMove$
    Dim As String boardX, boardY, retorn, k, b
    Dim As Long mx, my, mb, bx, by

    Do
        While _MouseInput: Wend
        mx = _MouseX: my = _MouseY ' convert into char cells
        mb = _MouseButton(1)
        If mb Then
            Locate 14, 50: Print Space$(15)
            Locate 14, 50: Print mx, my
            boardX = "": boardY = ""
            ' check mx
            If (mx Mod 4) <> 0 Then
                If mx > 4 And mx < 39 Then
                    bx = Int((mx - 4) / 4) + 1
                    boardX = Chr$(64 + bx)
                End If
            End If
            If my Mod 2 = 0 Then
                If my > 3 And my < 19 Then
                    by = Int((my - 2) / 2)
                    boardY = _Trim$(Str$(9 - by))
                End If
            End If
            Locate 15, 50: Print Space$(15)
            Locate 15, 50: Print boardX, boardY
        End If
        If (boardX <> "") And (boardY <> "") Then
            retorn = boardX + boardY
        Else
            k = InKey$
            If Len(k) = 1 And UCase$(k) = "Q" Then
                retorn = k
            Else
                b = b + k
                If Len(b) = 2 Then retorn = b
            End If
        End If
    Loop Until retorn <> ""
    GetMove$ = retorn
End Function


Sub PrintBoard ' rework in QB64 to model the board for get move

    Locate 4, 40: Print "Turn:  " '; Chess.Turn; "   "
    Locate 6, 40: Print "Level: " '; levels(aiLevel)
    'Locate 12, 40: Print "Enter 'Q' to Quit"
    'If Chess.IsCheckMate Then
    '    Locate 8, 40: Color 4: Print "Check Mate"
    'ElseIf Chess.IsCheck Then
    '    Locate 8, 40: Color 6: Print "Check"
    'End If

    'PrintHistory

    Locate 1, 1

    'Dim As String bstate, p, s
    'bstate = Chess.BoardPieces
    Dim p$, s$
    Dim As Integer rank, file
    Color 7: Print
    Print "     A   B   C   D   E   F   G   H"
    Print "   ";
    Color 8, 7: Print "|-------------------------------|"
    For file = 8 To 1 Step -1
        Color 7, 0
        Color 7, 0: Print " " + _Trim$(Str$(file)) + " ";


        For rank = Asc("A") To Asc("H")
            '    s$ = Chr$(rank) + _Trim$(Str$(file))
            '    p$ = "" ' bstate(s)
            '    If p$ = "" Then p$ = " "
            '    Color 8, 7: Print " ";
            '    If p$ > "A" And p$ < "Z" Then Color 15 Else Color 0
            '    Print p$;
            '    Print " "
            Color 8, 7: Print "|---";
            'Color 7, 0
        Next rank
        Print "|"
        If file > 1 Then
            Color 7, 0: Print "   ";
            Color 8, 7: Print "|-------------------------------|"
        End If
    Next file
    Color 7, 0: Print "   ";
    Color 8, 7: Print "|-------------------------------|"

End Sub



Note: it does takes the keypresses from the GetMove$ function but you have to Edit above, add () to GetMove function. But the point of all my labors today was todo mouse clicks! Sad
   
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
QBJS - Chess API - by dbox - 02-08-2026, 02:17 AM
RE: QBJS - Chess API - by bplus - 02-08-2026, 03:32 PM
RE: QBJS - Chess API - by dbox - 02-08-2026, 06:10 PM
RE: QBJS - Chess API - by TempodiBasic - 02-08-2026, 06:09 PM
RE: QBJS - Chess API - by dbox - 02-08-2026, 08:32 PM
RE: QBJS - Chess API - by bplus - 02-08-2026, 07:04 PM
RE: QBJS - Chess API - by SMcNeill - 02-08-2026, 07:14 PM
RE: QBJS - Chess API - by dbox - 02-08-2026, 08:42 PM
RE: QBJS - Chess API - by TempodiBasic - 02-09-2026, 12:13 AM
RE: QBJS - Chess API - by bplus - 02-09-2026, 12:37 AM
RE: QBJS - Chess API - by TempodiBasic - 02-09-2026, 01:17 AM
RE: QBJS - Chess API - by dbox - 02-09-2026, 04:50 PM
RE: QBJS - Chess API - by TempodiBasic - 02-09-2026, 01:27 AM
RE: QBJS - Chess API - by dbox - 02-10-2026, 05:01 PM
RE: QBJS - Chess API - by bplus - 02-10-2026, 05:53 PM
RE: QBJS - Chess API - by dbox - 02-10-2026, 10:26 PM
RE: QBJS - Chess API - by bplus - 02-10-2026, 11:14 PM
RE: QBJS - Chess API - by dbox - 02-11-2026, 12:58 AM
RE: QBJS - Chess API - by bplus - 02-11-2026, 01:50 AM
RE: QBJS - Chess API - by bplus - 02-12-2026, 07:05 PM
RE: QBJS - Chess API - by dbox - 02-12-2026, 09:45 PM
RE: QBJS - Chess API - by TempodiBasic - 02-12-2026, 07:25 PM
RE: QBJS - Chess API - by bplus - 02-12-2026, 10:15 PM
RE: QBJS - Chess API - by bplus - 02-12-2026, 10:55 PM
RE: QBJS - Chess API - by dbox - 02-13-2026, 01:07 AM
RE: QBJS - Chess API - by TempodiBasic - 02-13-2026, 09:39 AM
RE: QBJS - Chess API - by dbox - 02-13-2026, 05:15 PM
RE: QBJS - Chess API - by bplus - 02-13-2026, 02:30 PM
RE: QBJS - Chess API - by dbox - 02-13-2026, 05:22 PM
RE: QBJS - Chess API - by bplus - 02-13-2026, 06:53 PM
RE: QBJS - Chess API - by TempodiBasic - 02-15-2026, 07:02 PM
RE: QBJS - Chess API - by dbox - 02-15-2026, 08:06 PM
RE: QBJS - Chess API - by bplus - 02-15-2026, 09:08 PM
RE: QBJS - Chess API - by dbox - 02-15-2026, 09:58 PM
RE: QBJS - Chess API - by bplus - 02-15-2026, 10:12 PM
RE: QBJS - Chess API - by TempodiBasic - 02-16-2026, 01:54 AM
RE: QBJS - Chess API - by dbox - 02-16-2026, 02:48 AM
RE: QBJS - Chess API - by TempodiBasic - 02-16-2026, 04:36 PM
RE: QBJS - Chess API - by TempodiBasic - 02-24-2026, 10:49 AM
RE: QBJS - Chess API - by dbox - 02-24-2026, 03:35 PM
RE: QBJS - Chess API - by TempodiBasic - 02-24-2026, 10:23 PM
RE: QBJS - Chess API - by dbox - 02-25-2026, 12:24 PM
RE: QBJS - Chess API - by TempodiBasic - 02-25-2026, 11:11 PM
RE: QBJS - Chess API - by TempodiBasic - 03-01-2026, 07:02 PM
RE: QBJS - Chess API - by dbox - 03-01-2026, 08:20 PM
RE: QBJS - Chess API - by TempodiBasic - 03-02-2026, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Amazing Grace to test out Web Audio API CharlieJV 0 443 11-30-2022, 03:09 AM
Last Post: CharlieJV

Forum Jump:


Users browsing this thread: 1 Guest(s)