Chess Version 2.5

Code snippets illustrating how LBB can be used
Rod
Posts: 11
Joined: Fri Apr 06, 2018 7:00 am

Chess Version 2.5

Post by Rod »

I have been advised that my LB Chess program does not run correctly in LBB. Not sure I fully understand what the issue is but it is an easy fix. It seems I need to save and restore a Global value when exiting a recursive loop. Here is the section of code that needs fixed.

This is a link to the original .zip, you will need to amend the .bas, insert the two lines that are marked "'some difference between JB abd LBB"

https://www.libertybasic.club/_files/ar ... 20v2.5.zip



function evaluatecomputermove(sgn,prune)


Level=Level+1
bestscore=10000*sgn
for y= 7 to 0 step -1
if date$("days")*Secday+time$("seconds")>Timecounter then Timecounter=date$("days")*Secday+time$("seconds"):call clock
for x= 7 to 0 step -1
if bsign(x,y)=sgn then
call movelist x,y,sgn
for m=0 to Move
x1=movex(m,Level)
y1=movey(m,Level)
oldscore=Score
'store mover and target data so that it may be restored
moversprite$=board$(x,y)
targetsprite$=board$(x1,y1)
targetvalue=val(mid$(board$(x1,y1),4,4))*bsign(x1,y1)
oldMove=Move 'some difference between JB and LBB
call makemove x,y,x1,y1
if Level<Maxlevel then Score=Score+evaluatecomputermove(0-sgn,bestscore - targetvalue + sgn*(8-abs(4-x1)-abs(4-y1)))
'we unwind the recursion by coming back here until we finaly return to the main program flow
'work out the score adding a small amount to favour forwards and central play
Score=Score+targetvalue-sgn*(8-abs(4-x1)-abs(4-y1))
'if it results in a better score than previously then store it as best
if (sgn<0 and Score > bestscore) or (sgn>0 and Score < bestscore) then
bestx(Level)=x
besty(Level)=y
bestx1(Level)=x1
besty1(Level)=y1
bestscore = Score
'if it isn't as good as as a previous pieces move then cut the search short
if (sgn<0 and bestscore>=prune) or (sgn>0 and bestscore<=prune) then
'reset play
board$(x,y)=moversprite$
board$(x1,y1)=targetsprite$
Score=oldscore
Level=Level-1
evaluatecomputermove=bestscore
exit function
end if
end if
'reset play
board$(x,y)=moversprite$
board$(x1,y1)=targetsprite$
Score=oldscore
Move=oldMove 'some difference between JB and LBB
next
end if
next
next
Level=Level-1
evaluatecomputermove=bestscore
end function
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: Chess Version 2.5

Post by guest »

Rod wrote: Mon Dec 18, 2023 1:44 pm This is a link to the original .zip, you will need to amend the .bas, insert the two lines that are marked "'some difference between JB abd LBB"
I am somewhat confused, because chess.bas does not even compile successfully in LBB, it is reporting a 'Handle #1 used for incompatible devices' error. This is because handle #1 is used to represent a graphics window in line 751 and a file in line 1113; LBB requires each handle name to refer only to a specific type of device. So if it doesn't even compile, I can't begin to investigate the issue you have raised. Have I misunderstood something?
Rod
Posts: 11
Joined: Fri Apr 06, 2018 7:00 am

Re: Chess Version 2.5

Post by Rod »

No, it’s my fault because I was also told that I had reused a handle but did not realise the significance. It is where I open a window to gauge the size of the client area and then reuse that handle later in the code. Both issues are probably bad practice on my part. But the handle reuse obviously stops the compile, another easy fix.

I am told that the code runs many times faster on LBB which isn’t a surprise.
tsh73
Posts: 44
Joined: Fri Apr 06, 2018 7:58 pm

Re: Chess Version 2.5

Post by tsh73 »

I have been advised that my LB Chess program does not run correctly in LBB.
actually, it RUNS
and it appears working OK
but if you run it side-by-side with JB you 'll see it takes DIFFERENT MOVES

Got to log some trace to file and look for the differense. And it was on some 4xx line ;)
- rather hard to pinpoint - but visible on second black's move, so hard to miss.

as to the issue, that might be it
FOR difference with JB/LB4
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: Chess Version 2.5

Post by guest »

tsh73 wrote: Mon Dec 18, 2023 8:43 pm as to the issue, that might be it
FOR difference with JB/LB4
If this is indeed the 'issue', a simpler (more localised, and therefore more understandable and less risky) fix might be this:

Code: Select all

tempMove = Move
for m=0 to tempMove
This ensures that the 'loop limit' doesn't get modified within the loop.
tsh73
Posts: 44
Joined: Fri Apr 06, 2018 7:58 pm

Re: Chess Version 2.5

Post by tsh73 »

Nice one.
I would say simple solutions are most hard to come by.
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: Chess Version 2.5

Post by guest »

tsh73 wrote: Thu Dec 21, 2023 6:00 pm I would say simple solutions are most hard to come by.
If they work! With that modification, does the program make the same chess moves in LBB as in JB?
tsh73
Posts: 44
Joined: Fri Apr 06, 2018 7:58 pm

Re: Chess Version 2.5

Post by tsh73 »

Yes it does for me.