|
Post by tsh73 on Feb 6, 2021 19:35:22 GMT
I was fiddling with this program. I think I got something useful, but it based on some previous version. I've got somewhat fed with it so I better show it. Main problem is that it (Chess2) is awfully slow on my computer (Atom netbook). I probably could fit it over to Chess2.4 basically I added parameter what prints info to a mainwin (usual catch is then you mess cursor position, mainwin printing messes up) 'debugLev=0 'off debugLev=1 'show moves 'debugLev=2 'show variants
So, let's see debugLev=1 Maxlevel=2 (on Maxlevel=3 first move takes 20 sec, further moves takes minutes) For AI move it shows score, time taken, number of evaluatecomputermove calls, number of moves tested and number of cuts (cuts is still mistery for me so I watched this) (now I see that disabling cuts sharply increase number of calls/moves and hence time).
Feb 06, 2021 22:05:43 New game Player is White Maxlevel is 2 doNotCut is 0 checkLev is 2 1 PE2-E4 1 PE7-E5 0 4250ms 21 245 15 2 NG1-F3 2 PF7-F5 -101 6216ms 30 679 25 3 PD2-D3 3 PF5:PE4 0 1360ms 31 119 29 4 PD3:PE4 4 PD7-D5 -101 7467ms 29 836 24 5 PE4:PD5 5 PE5-E4 1 1595ms 38 139 36 6 NF3-G5 6 PE4-E3 -100 10178ms 36 1133 34 7 BC1:PE3 7 BC8-F5 -96 10188ms 35 1157 31 8 QD1-F3 8 BF5:PC2 -199 10491ms 40 1193 37 9 QF3-F7+
now debugLev=2 we can see what moves it checks, what is score of these moves, and how much time it spent on it.
Feb 06, 2021 22:21:37 New game Player is White Maxlevel is 2 doNotCut is 0 checkLev is 2 1 PE2-E4 PH7 2 moves (1) PH7-H6 -4 329ms (2) PH7-H5 -100 133ms PG7 2 moves (1) PG7-G6 -3 282ms (2) PG7-G5 -2 297ms PF7 2 moves (1) PF7-F6 -2 219ms (2) PF7-F5 -100 265ms PE7 2 moves (1) PE7-E6 -1 281ms (2) PE7-E5 0 281ms PD7 2 moves (1) PD7-D6 -1 32ms (2) PD7-D5 0 31ms PC7 2 moves (1) PC7-C6 -2 16ms (2) PC7-C5 -1 31ms PB7 2 moves (1) PB7-B6 -3 15ms (2) PB7-B5 -2 15ms PA7 2 moves (1) PA7-A6 -4 15ms (2) PA7-A5 -3 16ms NG8 2 moves (1) NG8-F6 -1 15ms (2) NG8-H6 -3 16ms NB8 2 moves (1) NB8-A6 -4 16ms (2) NB8-C6 -2 31ms 1 PE7-E5 0 2644ms 21 245 15
Also I did a mod - then under check, moves that does not end check gets discarded ASAP. This improves responce time for check or checkmate. Variable "checkLev" responsible for that. I tried 'checkLev=1 'checks only 1st level checkLev=2 'any level if on the enter on evaluatecomputermove was in check 'checkLev=3 'any level regardless of initial check
Level 2 changes gameplay, and I have position stored then on Maxlevel=3 AI blocks his own view allowing for checkmate on next move - with checkLev=2 it selects other move. (or with Maxlevel=4, but it takes about an hour for single move)
Well, if I agree then valid AI move cannot end with AI in check, I just test all moves That will be checkLev=3. But it looks like it makes program 1.5x slower.
|
|
|
Post by Rod on Feb 7, 2021 9:26:21 GMT
Ok, I agree optimisation is next on the agenda. I will look at incheck(). On my Pc at maxlevel 3 I am getting first move in 7s I can get six moves from the AI in about two minutes, so average 20s per move. I have no real statistical proof but I agree that it does not play very well at maxlevel 2.
Edit: actually thinking about it, evaluation must know it achieved check so it just needs to flag it rather than just value it. Also movelist might be able to see check. Needs some thinking time.....
Edit2: I measure the incheck() function as trivial time delay. Time is mostly spent assessing moves. anything from 1000 to 2000 moves per play. Couple of things in my head now for optimisation. First is change data storage and reduce the number of save / retrieves to play then reset play. Just one data statement in board() might replace bsprite bvalue bsgn bpiece etc etc and the management of them. Second is where to start looking for the move. The highest paying moves might be centred on the board. Currently we simply sweep bottom right to top left. We might get better result if we circle out from the centre. That way the pruning might find a high value early and so reduce total assessments.
|
|
|
Post by Rod on Feb 8, 2021 10:55:41 GMT
I have impressed myself, now getting a complete game, itself on itself, in under three minutes. I have introduced a bug or two so will work on those. I used a new board$() array with "SNX0000" as the format "WR1 500" for example. Now the sprite name is the first three letters SNX, the sign is set by the first letter S, the name by the second letter N and the value as the last four times the sign as -1 or 1.
All of that cut out swathes of code in the intensive loop because it just swaps and replaces one array item instead of four.
As soon as I get the big bugs out I will post version 2.5 Then I will test circular polling rather than raster polling.
|
|
|
Post by Rod on Feb 8, 2021 15:00:49 GMT
Ok, take this as a beta of v2.5 a super speedy new version. gamebin.webs.com/Chess%20v2.5.zipIf it does not fall apart under test I will move on to circular polling but this speed difference almost makes that need redundant. unfortunately J-Board will need tweaked for this new version. Once debugged I would like to bundle J-Board in the .zip if that ok.
|
|
|
Post by tsh73 on Feb 8, 2021 17:29:24 GMT
Holy macarony. It's fast! I will update J-Board but I'm not that fast :)
sure OK
just now I playing with maxLevel=4 It still do really weird moves, strategy-wise. But it looks like it managed to fend off my cavalry attack :)
It finally resigned (timer stopped, text panel did not redraw) then checkmate became imminent on next move.
|
|
|
Post by tsh73 on Feb 8, 2021 19:27:41 GMT
First bug found :) Just did 0-0-0 for white It placed king B2, rook C2 Should - C2 and D2 EDIT indeed it's OLD bug - I see it in 2.4 and in program I worked on (about v2) too...
EDIT it was right in original code should be smth like this (not tested)
'player clicked castle left if xx>5 and xx<105 and yy>125 and yy<150 then playwave "click.wav",async if AI=Black then if mid$(board$(0,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and mid$(board$(3,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,2,7 'here change call makemove 0,7,3,7 'here change
and
'player clicked castle right if xx>5 and xx<105 and yy>155 and yy<180 then playwave "click.wav",async if AI=Black then '... else if mid$(board$(7,7),2,1)="R" and mid$(board$(3,7),2,1)="K" and mid$(board$(4,7),2,1)=" " and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(-1)=0 then call makemove 3,7,5,7 call makemove 7,7,4,7
EDIT found one more small bug - for black 0-0 didn't work So, now tested (for these bugs only) fixed castling piece
'player clicked castle left if xx>5 and xx<105 and yy>125 and yy<150 then playwave "click.wav",async if AI=Black then if mid$(board$(0,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and mid$(board$(3,7),2,1)=" " and incheck(1)=0 then ' call makemove 4,7,1,7 ' call makemove 0,7,2,7 call makemove 4,7,2,7 call makemove 0,7,3,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if else if mid$(board$(0,7),2,1)="R" and mid$(board$(3,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and incheck(-1)=0 then call makemove 3,7,1,7 call makemove 0,7,2,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if
end if
'player clicked castle right if xx>5 and xx<105 and yy>155 and yy<180 then playwave "click.wav",async if AI=Black then if mid$(board$(7,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,6,7 call makemove 7,7,5,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if else if mid$(board$(7,7),2,1)="R" and mid$(board$(3,7),2,1)="K" and mid$(board$(4,7),2,1)=" " and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(-1)=0 then ' call makemove 3,7,6,7 ' call makemove 7,7,5,7 call makemove 3,7,5,7 call makemove 7,7,4,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if
end if
|
|
|
Post by Rod on Feb 8, 2021 20:12:16 GMT
Thanks, I changed the castle code, I simplified it as well as correct the error. It does not really care whether it is black or white castling.
'player clicked castle left if xx>5 and xx<105 and yy>125 and yy<150 then playwave "click.wav",async if mid$(board$(0,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and mid$(board$(3,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,2,7 call makemove 0,7,3,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if
'player clicked castle right if xx>5 and xx<105 and yy>155 and yy<180 then playwave "click.wav",async if mid$(board$(7,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,6,7 call makemove 7,7,5,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if
|
|
|
Post by tsh73 on Feb 8, 2021 20:25:42 GMT
Err? I substituted your code - it does not work for black at all
|
|
|
Post by Rod on Feb 9, 2021 10:09:17 GMT
Thanks, think it is the incheck() function call which needs to be set to player sign.
Edit, more than that actually. now back to semi complicated but working!
'player clicked castle left if xx>5 and xx<105 and yy>125 and yy<150 then playwave "click.wav",async if AI=White then 'player is black if mid$(board$(0,7),2,1)="R" and mid$(board$(3,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and incheck(-1)=0 then call makemove 3,7,1,7 call makemove 0,7,2,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if else 'player is white if mid$(board$(0,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(1,7),2,1)=" " and mid$(board$(2,7),2,1)=" " and mid$(board$(3,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,2,7 call makemove 0,7,3,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if end if
'player clicked castle right if xx>5 and xx<105 and yy>155 and yy<180 then playwave "click.wav",async if AI=White then 'player is black if mid$(board$(7,7),2,1)="R" and mid$(board$(3,7),2,1)="K" and mid$(board$(4,7),2,1)=" " and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(-1)=0 then call makemove 3,7,5,7 call makemove 7,7,4,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if else 'player is white if mid$(board$(7,7),2,1)="R" and mid$(board$(4,7),2,1)="K" and mid$(board$(5,7),2,1)=" " and mid$(board$(6,7),2,1)=" " and incheck(1)=0 then call makemove 4,7,6,7 call makemove 7,7,5,7 call text "Castles" #w.g "drawsprites" exit sub else call text "Illegal move" goto [err] end if end if end if
|
|
|
Post by Rod on Feb 9, 2021 15:12:15 GMT
Another bug, pawn promotion, hopefully fixed. J-Board will help test stuff no rush. sub makemove x,y,x1,y1
'fill square taken board$(x1,y1)=board$(x,y)
'erase square vacated board$(x,y)=" 0"
'promote pawn if it reaches board edge if (y1=0 or y1=7) and mid$(board$(x1,y1),2,1)="P" and Level=0 then
'switch off original sprite #w.g "spritevisible ";left$(board$(x1,y1),3);" off" Spritetaken$=Spritetaken$+left$(board$(x1,y1),3)+"," 'add new queen sprite 'wp1 wp8 become wq2-wq9 board$(x1,y1)=mid$(board$(x1,y1),1,1)+"Q"+mid$(board$(x1,y1),3,1)+" 900" if left$(board$(x1,y1),1)="W" then #w.g "addsprite ";left$(board$(x1,y1),3);" WQ WQ1" #w.g "spritexy ";left$(board$(x1,y1),3);" ";x1;" ";y1 Spriteadded$=Spriteadded$+left$(board$(x1,y1),3)+" WQ WQ1," call text "New white Queen" else #w.g "addsprite ";left$(board$(x1,y1),3);" BQ BQ1" #w.g "spritexy ";left$(board$(x1,y1),3);" ";x1;" ";y1 Spriteadded$=Spriteadded$+left$(board$(x1,y1),3)+" BQ BQ1," call text "New black Queen" end if end if end sub
|
|
|
Post by Rod on Feb 9, 2021 15:18:51 GMT
Ok this is the fast version, I will bundle J_Board next and might post an .exe version on some other forum to let other BASIC folks try it. gamebin.webs.com/Chess%20v2.5.zip
|
|
|
Post by B+ on Feb 9, 2021 18:31:38 GMT
Yea for fast I will check it out when I need break on Interpreter I am working on. What is status on recording a game?
|
|
|
Post by Rod on Feb 9, 2021 19:48:55 GMT
Depends how much functionality is needed. easy to write to a file as well as show on screen. But that cryptic printing isn't the industry standard. Also then folks might want to play it back, move through it. Can of worms?
Working on vector based pin ball collisions and enjoying the break!
|
|
|
Post by tsh73 on Feb 12, 2021 20:08:36 GMT
|
|
|
Post by tsh73 on Feb 13, 2021 7:57:36 GMT
fixed exporting "extra pieces" situation (two queens then pawn promoted) (just woke up, thought "ya, it should be this way" - fixed - and went back to sleep %) )
|
|