Chess game
Chess game
Hi
For info I've recently released an update to my chess engine (Numpty) - https://sites.google.com/site/numptychess/ I thought I'd mention it here as after 9 years this project is now probably finished and I got some friendly help from members on this forum when I first started.
It's not great programming (far from it) but the source code has always been available to hopefully encourage anyone else interested in chess or strategy related games (on the Numpty site there are also FB sources for X&O and Connect 4)
Revisiting the forum recently I noticed that my chess program has been discussed a few times over the years and generated some queries/problems.
Firstly, I'm sorry if people have not been able to compile the source - Numpty started in 2005 in Just Basic and when I ported to FB in 2006 I started using v0.15b - and I've never stopped (I didn't keep up with this forum or subsequent FB updates - lesson learned for me!). So for anyone interested in the source - it will compile perfectly but you will need to downgrade!)
Programming a stable chess engine that plays a legal game consistently is not easy (certainly for an amateur hobbyist like me). But since at least 2009 I am confident that Numpty is fundamentally bug free in terms of move generation and basic search (eg it plays regularly without problem in computer tournaments and also on-line against humans on FICS). Certainly for anyone working on a chess program I would recommend writing a 'perft' debugging function to test the validity of the move generation code before worrying about evaluation or how strongly it plays.
For info I've recently released an update to my chess engine (Numpty) - https://sites.google.com/site/numptychess/ I thought I'd mention it here as after 9 years this project is now probably finished and I got some friendly help from members on this forum when I first started.
It's not great programming (far from it) but the source code has always been available to hopefully encourage anyone else interested in chess or strategy related games (on the Numpty site there are also FB sources for X&O and Connect 4)
Revisiting the forum recently I noticed that my chess program has been discussed a few times over the years and generated some queries/problems.
Firstly, I'm sorry if people have not been able to compile the source - Numpty started in 2005 in Just Basic and when I ported to FB in 2006 I started using v0.15b - and I've never stopped (I didn't keep up with this forum or subsequent FB updates - lesson learned for me!). So for anyone interested in the source - it will compile perfectly but you will need to downgrade!)
Programming a stable chess engine that plays a legal game consistently is not easy (certainly for an amateur hobbyist like me). But since at least 2009 I am confident that Numpty is fundamentally bug free in terms of move generation and basic search (eg it plays regularly without problem in computer tournaments and also on-line against humans on FICS). Certainly for anyone working on a chess program I would recommend writing a 'perft' debugging function to test the validity of the move generation code before worrying about evaluation or how strongly it plays.
Re: Chess game
Welcome to the board nice to hear from you.FB_Numpty wrote:Programming a stable chess engine that plays a legal game consistently is not easy (certainly for an amateur hobbyist like me). But since at least 2009 I am confident that Numpty is fundamentally bug free in terms of move generation and basic search (eg it plays regularly without problem in computer tournaments and also on-line against humans on FICS). Certainly for anyone working on a chess program I would recommend writing a 'perft' debugging function to test the validity of the move generation code before worrying about evaluation or how strongly it plays.
Sadly your program has a problem in certain situations it does not produce the correct number of moves. When you do "setboard 4k3/8/8/8/8/8/8/4K2R b K - 0 1" then do "perft" for depth 1 it gives a always the correct answer (5), and for depth 2 the answer = 75 nodes, but when have played a game a then do "setboard ..." it the answer for depth 2 can vary , it seems that some variables are not correctly set/reset when setboard is executed. The only time "setboard" / "perft" gives the correct answer if "setboard" is impliedly executed after starting the program.
Also "save" and "load" do not save and load some information like castling and ep, but I think you already knew that.
What are your plans for Numpty?
I have adopted NoMega.bas to run under FB .23 (started nearly two years ago,I did not work constanly on it). It will run in console mode but it will not run with winboard or arena. I must admit that I have thinkered with it so the code is somewhat messy.
Regards.
Re: Chess game
Thanks for the welcome and taking the time to feedback also!
Thanks again for your interest and feedback!
Yes this is quite correct - this is interesting as I didn't expect anyone really to use the engine outside of a GUI. Console mode was really only for my development & test purposes not practical use. The read me picks up the issue you raise - in GUI framework engine needs manual restarting for multiple use of setboard comand. There is no 'New' command - this is poor design. It isn't a problem for normal game play as Numpty uses the (Reuse=0) winboard feature which kills the engine process after every game and starts a fresh one for the following game. This does cause a specific issue with use in Chessbase (also highlighted in the readme) I think due to its implementation of the protocol.Sadly your program has a problem in certain situations it does not produce the correct number of moves. When you do "setboard 4k3/8/8/8/8/8/8/4K2R b K - 0 1" then do "perft" for depth 1 it gives a always the correct answer (5), and for depth 2 the answer = 75 nodes, but when have played a game a then do "setboard ..." it the answer for depth 2 can vary , it seems that some variables are not correctly set/reset when setboard is executed. The only time "setboard" / "perft" gives the correct answer if "setboard" is impliedly executed after starting the program.
Yes - this functionality was put in early in development before winboard functionality and wasn't revisited - it would be easy to change - I had wondered about removing console functionality altogether in the latest release.Also "save" and "load" do not save and load some information like castling and ep, but I think you already knew that.
The source is overlong, messy and not well programmed (as you will have seen!) - for me at least I am unlikely to make it a lot stronger without starting from scratch - there are a lot of things I would do differently (thinking about program design, data structures and representation before starting for one thing!). One thing I might do is to add some additional winboard functionality ( eg 'new' (given your feedback!) 'undo', draw and maybe resign options).What are your plans for Numpty?
Impressive! - I did once try and compile using newer FB but knowing the code thought this would be too big a job to correct (how long did it take?). One thing I was always interested in was the effect of compiling in a newer FB with added compiler options particularly optimization. If possible could you say run perft 6 from the start position with your update and see how long it takes, it would be interesting to compare with the standard version.I have adopted NoMega.bas to run under FB .23 (started nearly two years ago,I did not work constanly on it). It will run in console mode but it will not run with winboard or arena. I must admit that I have thinkered with it so the code is somewhat messy.
Thanks again for your interest and feedback!
Re: Chess game
Here some timings for Numpty_DD and NoMega compiled with FB .91 .
[/list]
1.) rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 depth 6
2.) 4k3/8/8/8/8/8/8/4K2R b K - 0 1 depth 8
3.) r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1 depth 6
4.) r3k2r/8/8/8/8/8/8/R3K2R w - - 0 1 depth 6
All are enter with setboard after a new start.Gcc compiled with Gcc -O max.
nodes for 1, 2 and 3 where correct. But for 4 only Numpty_DD produced the correct number for total nodes. My NoMega gave a total number that was to high. When trying a even depth the result where always to high for odd depth the count is correct. It includes moves for castling while these a not aloud. It seems that I didn't succeeded in getting rid off the problem completely. The problem seems to be that the value for castling is not proper handled (specially when it's -1, no castling allowed). I looked into it but for the moment I can't find a proper solution.
The timings for Gcc indicate that there is potential for more speed under Gas. I have made some changes to get the program faster but I have not gone to the limit. When I started it was my goal to get the program compiled with FB 0.23 (nearly 2 years ago). I think that I spend in total some 6 weeks on it. Getting it running was not a great problem more to get some thing fixed that are no longer aloud in newer FB versions. Also the fact that that variables need to be DIMed before use and the fact that there is in difference global en local. Getting rid of the string suffix $ was not a great problem. Still haven't worked on the winboard interface.
I have rewrite the display sub routine and added a few things.
[/list]
1.) rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 depth 6
2.) 4k3/8/8/8/8/8/8/4K2R b K - 0 1 depth 8
3.) r3k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1 depth 6
4.) r3k2r/8/8/8/8/8/8/R3K2R w - - 0 1 depth 6
All are enter with setboard after a new start.
Code: Select all
Numpty_DD NoMega (Gas) Nomega (Gcc) Nomega (Gcc 64bit)
1. 59.59 sec. 43.69 sec. 17.67 sec. 12.39 sec.
2. 63.40 sec. 48.97 sec. 17.28 sec. 13.11 sec.
3. 112.34 sec. 87.67 sec. 30.41 sec. 23.28 sec.
4. 92.02 sec. 79.72 sec. 25.07 sec. 21.14 sec
nodes for 1, 2 and 3 where correct. But for 4 only Numpty_DD produced the correct number for total nodes. My NoMega gave a total number that was to high. When trying a even depth the result where always to high for odd depth the count is correct. It includes moves for castling while these a not aloud. It seems that I didn't succeeded in getting rid off the problem completely. The problem seems to be that the value for castling is not proper handled (specially when it's -1, no castling allowed). I looked into it but for the moment I can't find a proper solution.
The timings for Gcc indicate that there is potential for more speed under Gas. I have made some changes to get the program faster but I have not gone to the limit. When I started it was my goal to get the program compiled with FB 0.23 (nearly 2 years ago). I think that I spend in total some 6 weeks on it. Getting it running was not a great problem more to get some thing fixed that are no longer aloud in newer FB versions. Also the fact that that variables need to be DIMed before use and the fact that there is in difference global en local. Getting rid of the string suffix $ was not a great problem. Still haven't worked on the winboard interface.
I have rewrite the display sub routine and added a few things.
Code: Select all
Sub display ' ### rewrote the display routine to avoid flipping the board if player = black
'***************************************
' DisplayBoard
' Prints board to screen
'***************************************
If WinboardMode = 1 Then Return ' skip if in winboard mode
Dim As Byte x, y, piece
Dim As Byte x1 = 9, x2 = 2, x3 = -1
Dim As Byte y1 = 1, y2 = 8, y3 = 1
' if player = white
' x1 = 9 : x2 = 2 : x3 = -1
' y1 = 1 : y2 = 8 : y3 = 1
' if player = black
' x1 = 2 : x2 = 9 : x3 = 1
' y1 = 8 : y2 = 1 : y3 = -1
If cmpclr = 1 Then
Swap x1, x2
Swap y1, y2
Swap x3, y3
End If
Cls
' Print #99, moveno
Print : Print
For x = x1 To x2 Step x3
For y = x*10 + y1 To x*10 + y2 Step y3
piece = B(y)
If piece < 0 Then piece += 20
Print " "; b_str(piece);
Next y
Print " *** "; x - 1
Print " -----------------------------"
Next x
Print " *********************************** "
Print " *********************************** "
If cmpclr = -1 Then
Print " a b c d e f g h "
Else
Print " h g f e d c b a "
End If
' Print #99, moveno
If move_hist(MoveNo, 1) = 0 Then
Print "NOmega's move... <list empty>"
Else
If BookHit = 1 Then
If cmpclr = -1 Then
Print "NOmega's move... "; move_2_str(move_hist(MoveNo, 3)); "-"; move_2_str(move_hist(MoveNo, 4)); " < Book move >"
Else
Print "NOmega's move... "; move_2_str(move_hist(MoveNo, 1)); "-"; move_2_str(move_hist(MoveNo, 2)); " < Book move >"
End If
End If
If MoveNo >= 1 And BookHit = 0 Then
If cmpclr = 1 Then
Print "NOmega's move... "; move_2_str(move_hist(MoveNo, 1)); "-"; move_2_str(move_hist(MoveNo, 2)); " Eval = "; best_score
Else
Print "NOmega's move... "; move_2_str(move_hist(MoveNo, 3)); "-"; move_2_str(move_hist(MoveNo, 4)); " Eval = "; best_score
End If
End If
End If
If MoveNo >= 1 And Bookhit = 1 And perft = FALSE Then Print "Total nodes searched = 0" Else Print "Total nodes searched = "; display_node
Print : Print "---------------------------------------"
If cmpclr = -1 Then Print "White # Move No:"; MoveNo + 1 Else Print "Black # Move No: "; MoveNo
End Sub
Re: Chess game
removed, double posting.
Last edited by frisian on Feb 08, 2014 15:55, edited 2 times in total.
Re: Chess game
Many thanks for these tests frisian - very interesting.
I didn't expect quite such a marked difference (is this all down to FB version & compiler options or are there some of your code improvements?). Presumably Numpty_DD result is 0.15b compiled version?
It seems this alone would provide a significant improvement to strength especially as Numpty's search function is simple and average search depth is comparatively poor (being simple alpha-beta only).
I would interested in what coding changes you made to improve speed - you will see my amateurish attempts in the code (which as a result started to get even more unreadable). I tested some changes manually using some sample opening/mid and endgame positions rather than profiling.
The perft feedback is also helpful - I think I can explain this and show the relevant change to code but will check and test this when I have more time at the weekend. Of course running thousands of games without crash or illegal move is no guarantee on its own that perft is sound. I tested Numpty versions (again manually) using the tricky sample positions on the chess programming wiki together with validated perft figures for sample positions I developed myself which are on the Numpty homepage. In hindsight an automated testing routine would have been better as there are sample perft specific epd suites.
Thanks for your code snippet - I am delighted you have taken the code and improved and developed it - this was one of my specific aims in making it available. I would certainly encourage you to make the winboard changes also as I think an enhanced version would be enjoyed by a wider audience (myself included).
I didn't expect quite such a marked difference (is this all down to FB version & compiler options or are there some of your code improvements?). Presumably Numpty_DD result is 0.15b compiled version?
It seems this alone would provide a significant improvement to strength especially as Numpty's search function is simple and average search depth is comparatively poor (being simple alpha-beta only).
I would interested in what coding changes you made to improve speed - you will see my amateurish attempts in the code (which as a result started to get even more unreadable). I tested some changes manually using some sample opening/mid and endgame positions rather than profiling.
The perft feedback is also helpful - I think I can explain this and show the relevant change to code but will check and test this when I have more time at the weekend. Of course running thousands of games without crash or illegal move is no guarantee on its own that perft is sound. I tested Numpty versions (again manually) using the tricky sample positions on the chess programming wiki together with validated perft figures for sample positions I developed myself which are on the Numpty homepage. In hindsight an automated testing routine would have been better as there are sample perft specific epd suites.
Thanks for your code snippet - I am delighted you have taken the code and improved and developed it - this was one of my specific aims in making it available. I would certainly encourage you to make the winboard changes also as I think an enhanced version would be enjoyed by a wider audience (myself included).
Re: Chess game
First a macro that is used in the display routine.
#Macro move_2_str(num)
(Chr(num Mod 10 + 96) + Chr(num \ 10 + 47))
#EndMacro
After level 4 I still have trouble with castling when castling is a allowed, when at the start no castling is allowed the is no problem.
In order to get it compiled I had to change a few things, and yes I have altered some code to let it run faster. First some explanation about some changes. Integer is the fastest variable so when ever possible I have change single's to integer. Also note that unsigned integers are slightly faster than signed integers, dividing and multiplying are slow in comparison to adding and subtracting. Except for numbers in the form 2^N, the compiler will change those into 2 Shl N or 2 Shr N. Also some variables where turned into constant since they never change during the course of the program. Further more the code was somewhat cleaned up. Also tried to reduce the amount of variables. Rewrote the sort routine to use SWAP.
Some examples what I have don.
when a variable is Dim'ed it value is set to 0 so doing w_cas(1) = 0 etc. is useless as is w_casflags(depth,1) = 0 etc.
I changed the for next that read in data, by doing the multiplying my self.
FOR X = 90 TO 20 STEP -10
FOR Y = X+1 TO X+8
B(Y) = 0
NEXT Y
NEXT X
In doing it this way I made it faster (64 times multiply and 64 times adding into just 16 times adding).
Replaced the previous code with
When the first test fails so will the rest fail, if the first test is true than test the rest else continue after the End If. (Avoid testing the same thing again).
I have defined True to be 1 and False to be 0
The compiler wants variable inside a sub/function be declared.
This routine tries to avoid multiplying if it can. Also it does K = R only when necessary. It Dim's some variables only when the routine gets there.
EDIT:
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena
#Macro move_2_str(num)
(Chr(num Mod 10 + 96) + Chr(num \ 10 + 47))
#EndMacro
After level 4 I still have trouble with castling when castling is a allowed, when at the start no castling is allowed the is no problem.
Numpty_DD is compiled with 0.15b. Nomega was compiled with 0.91 (x86 and x64 version) new versionFB_Numpty wrote:I didn't expect quite such a marked difference (is this all down to FB version & compiler options or are there some of your code improvements?). Presumably Numpty_DD result is 0.15b compiled version?
In order to get it compiled I had to change a few things, and yes I have altered some code to let it run faster. First some explanation about some changes. Integer is the fastest variable so when ever possible I have change single's to integer. Also note that unsigned integers are slightly faster than signed integers, dividing and multiplying are slow in comparison to adding and subtracting. Except for numbers in the form 2^N, the compiler will change those into 2 Shl N or 2 Shr N. Also some variables where turned into constant since they never change during the course of the program. Further more the code was somewhat cleaned up. Also tried to reduce the amount of variables. Rewrote the sort routine to use SWAP.
Some examples what I have don.
Code: Select all
From numpty_DD
dim shared w_cas(2), b_cas(2) ' black/white castling status - actual values
w_cas(1) = 0:w_cas(2) = 0:b_cas(1) = 0:b_cas(2) = 0 ' 1 = king-side; 2 = queen-side; 0 = castling possible (default val)
Dim shared w_casflags(depth,2),b_casflags(depth,2)
' white & black castle flags in search '1 = O-O; 2 = O-O-O
' vals: -1 no castle, 0 - available, 1 - done!
w_casflags(depth,1) = 0:w_casflags(depth,2) = 0
b_casflags(depth,1) = 0:b_casflags(depth,2) = 0
Code: Select all
function clear_board()
FOR ClrBd = 0 TO 119
B(ClrBd) = -99
NEXT ClrBd
FOR X = 9 TO 2 STEP -1
FOR Y = 1 TO 8
READ Brd
B(X*10+Y) = Brd
NEXT Y
NEXT X
DATA 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0,0
DATA 0, 0, 0, 0, 0, 0, 0,0
DATA 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0
end function
FOR X = 90 TO 20 STEP -10
FOR Y = X+1 TO X+8
B(Y) = 0
NEXT Y
NEXT X
In doing it this way I made it faster (64 times multiply and 64 times adding into just 16 times adding).
Code: Select all
if Move_List(depth,w,2) > 90 and B(Move_List(depth,w,2)) = 1 then wprom(depth) = 1 'set promotion flag
if Move_List(depth,w,2) > 90 and B(Move_List(depth,w,2)) = 1 and Move_List(depth,w,3) = 6 then B(Move_List(depth,w,2)) = 6
if Move_List(depth,w,2) > 90 and B(Move_List(depth,w,2)) = 1 and Move_List(depth,w,3) = 4 then B(Move_List(depth,w,2)) = 4
if Move_List(depth,w,2) > 90 and B(Move_List(depth,w,2)) = 1 and Move_List(depth,w,3) = 3 then B(Move_List(depth,w,2)) = 3
if Move_List(depth,w,2) > 90 and B(Move_List(depth,w,2)) = 1 and Move_List(depth,w,3) = 2 then B(Move_List(depth,w,2)) = 2
Code: Select all
If Move_List(depth, w, 2) > 90 And B(Move_List(depth, w, 2)) = 1 Then
wprom(depth) = 1 'set promotion flag
If Move_List(depth, w, 3) = 6 Then B(Move_List(depth, w, 2)) = 6
If Move_List(depth, w, 3) = 4 Then B(Move_List(depth, w, 2)) = 4
If Move_List(depth, w, 3) = 3 Then B(Move_List(depth, w, 2)) = 3
If Move_List(depth, w, 3) = 2 Then B(Move_List(depth, w, 2)) = 2
End If
I have defined True to be 1 and False to be 0
The compiler wants variable inside a sub/function be declared.
Code: Select all
Function incheck(side As Byte) As Byte
'*******************************************************
' InCheck routine
' method:
' 1) Find king location
' 2) For each piece trace move from K position
' to see if check is given
'
' InCheck routine (with adaptation) is based on code
' written by Bill Rogers in his program Warlord X1b and
' is used with his permission.
'*******************************************************
Dim As Byte K = IIf(side = white, wkloc, bkloc)
Dim As Byte R = K, M, N
'***********************************
' test for check by pawn
'***********************************
If side = white Then
If b(k+9) = -1 Or b(k+11) = -1 Then Return TRUE
Else
If b(k-9) = 1 Or b(k-11) = 1 Then Return TRUE
EndIf
'************************************
'test for check by Knight
'************************************
Dim As Byte val_knight = IIf(side = White, -2, 2)
For N = 9 To 16
If B(R + Move_Offset(N)) = val_knight Then
Return TRUE
End If
Next N
'************************************
'test for check by Bishop / Queen
'************************************
Dim As Byte val_bishop = IIf(side = White, -3, 3)
Dim As Byte val_queen = IIf(side = White, -6, 6)
For N = 1 To 4
k = r
For M = 1 To 7
K += Move_Offset(N)
If B(K) = 0 Then Continue For
If B(K) = -99 Then
Exit For
End If
If B(K) * Side > 0 Then
Exit For
End If
If B(k) = val_bishop Or b(k) = val_queen Then
Return TRUE
Else
Exit For
End If
Next M
Next N
'************************************
'test for check by Rook / Queen
'************************************
Dim As Byte val_rook = IIf(side = White, -4, 4)
For N = 5 To 8
k = r
For M = 1 To 7
K += Move_Offset(N)
If B(K) = 0 Then Continue For
If B(K) = -99 Then
Exit For
End If
If B(K) * Side > 0 Then
Exit For
End If
If B(K) = val_rook Or B(K) = val_queen Then
Return TRUE
Else
Exit For
End If
Next M
Next N
Return FALSE
End Function
EDIT:
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena
Last edited by frisian on Apr 23, 2014 18:49, edited 2 times in total.
Re: Chess game
Many thanks for your sample code and advice - much appreciated - all I can say is you can see why it has taken me 9 years to get this far! :)
I've had a quick go with some of your suggestions (including dropping in your revised incheck routine - hope this is ok?). Not gone through all code but to date only managed 2-3% speed-up which maybe suggests much bigger impact is due to new FB and compiler optimisations. In terms of impact - what really kills nps is the big loop over all the squares in the evaluation function - again this is messy but I remember when I put in the goto statements for each individual piece - it resulted in a 25% speed up! So it would be interesting if you made any changes to this function and particularly the code in this loop
In hindsight, were I starting again I think evaluating key criteria such as material and pst incrementally in make and undo functions would be a better bet
In terms of your earlier post and different perft results for Nomega and DD versions (ie latter is right and former wrong) - I think this may be explained by a bug fixed in the latest version - I found it in a game between Nomega and my Mephisto MMIV dedicated computer. In the following position:
r3k2r/pp3ppp/2pQp1b1/1q4B1/2R2n2/1B3NN1/PP3PPP/5RK1 b kq - 0 17
Nomega played Nd3?? and fails to see the resulting mate in 1 and lost next move.
I tracked down the bug eventually - essentially in the search function the ordering of the 'test for check' and the 'castling through check test' were not aligned properly - this meant that in rare positions the engine could castle earlier in the search and this would not be picked up as going through check.
To fix this in the absearch function I moved the following:
from after :
to immediately before:
I've had a quick go with some of your suggestions (including dropping in your revised incheck routine - hope this is ok?). Not gone through all code but to date only managed 2-3% speed-up which maybe suggests much bigger impact is due to new FB and compiler optimisations. In terms of impact - what really kills nps is the big loop over all the squares in the evaluation function - again this is messy but I remember when I put in the goto statements for each individual piece - it resulted in a 25% speed up! So it would be interesting if you made any changes to this function and particularly the code in this loop
In hindsight, were I starting again I think evaluating key criteria such as material and pst incrementally in make and undo functions would be a better bet
In terms of your earlier post and different perft results for Nomega and DD versions (ie latter is right and former wrong) - I think this may be explained by a bug fixed in the latest version - I found it in a game between Nomega and my Mephisto MMIV dedicated computer. In the following position:
r3k2r/pp3ppp/2pQp1b1/1q4B1/2R2n2/1B3NN1/PP3PPP/5RK1 b kq - 0 17
Nomega played Nd3?? and fails to see the resulting mate in 1 and lost next move.
I tracked down the bug eventually - essentially in the search function the ordering of the 'test for check' and the 'castling through check test' were not aligned properly - this meant that in rare positions the engine could castle earlier in the search and this would not be picked up as going through check.
To fix this in the absearch function I moved the following:
Code: Select all
Check = incheck(side)
If Check = True then goto p1
Code: Select all
Call make_move(side,depth,Pseu_Moves(),y,epsqr(),w_casflags(),b_casflags(),wprom(),bprom(),fmove())
Code: Select all
xg = xg + 1 ' if here then must be a legal move
score = -ab_search(-side,depth-1,-beta, -alpha, epsqr(),w_casflags(),b_casflags(),fmove())
Re: Chess game
FB_Numpty
Here my version of NoMega that will compile with the latest version of FreeBasic.
It was intended for personal use so it is a bit off a mess, it was merely don as a challenge to get it running under the latest version of FB.
It has a problem with castling don't know what the cause of it.
It also will not communicate with winboard (or arena), I used console mode
You can find my version here new version
I removed a lot of goto's by using EXIT FOR and CONTINUE FOR and reworked the way some IF THEN statements worked.
In Computer_move there was a jump from outside a FOR NEXT loop to the inside of the loop modern FB does not like this so I had to resort to some trickery.
I also placed all the testing for castling inside Gen_move making all the checks for castling obsolete in the rest of the program.
After ready over optimization for assembler code I change all Ubyte and Byte to Uinteger and Integer (about 10% faster).
P.S.
I had intended to post it last week but I had problems with my hard disk.
Edit.
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena
Here my version of NoMega that will compile with the latest version of FreeBasic.
It was intended for personal use so it is a bit off a mess, it was merely don as a challenge to get it running under the latest version of FB.
It has a problem with castling don't know what the cause of it.
It also will not communicate with winboard (or arena), I used console mode
You can find my version here new version
I removed a lot of goto's by using EXIT FOR and CONTINUE FOR and reworked the way some IF THEN statements worked.
In Computer_move there was a jump from outside a FOR NEXT loop to the inside of the loop modern FB does not like this so I had to resort to some trickery.
I also placed all the testing for castling inside Gen_move making all the checks for castling obsolete in the rest of the program.
After ready over optimization for assembler code I change all Ubyte and Byte to Uinteger and Integer (about 10% faster).
P.S.
I had intended to post it last week but I had problems with my hard disk.
Edit.
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena
Last edited by frisian on Apr 23, 2014 18:52, edited 3 times in total.
Re: Chess game
Many thanks for sharing your work frisian - haven't had a chance to look at in detail yet but can see you have put in a lot of work on the code.
It has been quite a while since I looked at the source in detail - more recent work has been tinkering with a few parameters - but I will refresh myself and have a look and see if I can help find the castling bug for you - using the test positions you gave in an earlier post - might take me a bit of time but will be a good challenge!
Your work has inspired me to download and have a play around with latest FB - seem to be getting the hang of it and I have managed to translate my old connect 4 program on the website (also in FB 0.15) - compiles in new version now, nearly functioning as original version but interestingly is so far about 20% slower - so still a lot to learn!
Thanks again
It has been quite a while since I looked at the source in detail - more recent work has been tinkering with a few parameters - but I will refresh myself and have a look and see if I can help find the castling bug for you - using the test positions you gave in an earlier post - might take me a bit of time but will be a good challenge!
Your work has inspired me to download and have a play around with latest FB - seem to be getting the hang of it and I have managed to translate my old connect 4 program on the website (also in FB 0.15) - compiles in new version now, nearly functioning as original version but interestingly is so far about 20% slower - so still a lot to learn!
Thanks again
-
- Posts: 993
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: Chess game
Hello ! It would be great to have a new version of Numpty. But it would be regrettable to give up the Winboard protocol support, which isn't the less interesting side of the program.frisian wrote:It also will not communicate with winboard (or arena), I used console mode.
Re: Chess game
I have tried to get winboard protocol working but I did not get it working but perhaps there is someone that can get to work. Having it working would make testing must easier.Roland Chastain wrote:Hello ! It would be great to have a new version of Numpty. But it would be regrettable to give up the Winboard protocol support, which isn't the less interesting side of the program.frisian wrote:It also will not communicate with winboard (or arena), I used console mode.
FB_Numpty
FB has evolved over time some things have been added and other things have been altered in there working.
For instance in your connect four program you have
Code: Select all
function book_move ()
Dim board_position(47) ' array to hold current board position
For x = 1 to 47
if x/8 = int(x/8) then goto a1 ' skip edge of board markers
board_position(x) = position(x) ' copy current board position
a1:
next x
For jumping to next x we have Continue For and for leaving a For Next loop we have Continue For.
If x/8 = int(x/8) then goto a1 can be rewritten as If x Mod 8 = 0 Then Exit For.
The optimization of FB is somewhat limited but x Mod 8 is replaced by x And 7 which doesn't need a division at all. (x mod 2^n get replaced by x and 2^n-1).
In LINXBOOK.DAT you have
0 -1 0 1 0 -1 0 0 0 1 ... ... 0 0 0 0 0 0 0 0 0 99 <== ???
0 0 0 0 0 0 0 0 0 0 ... ... 0 0 0 0 0 0 0 0 0 99
It looks to me that the line before the last line should not end on 99. (99 = stop book search).
Feel free to use my code if you find it use full.
Regards.
PS.
I only had a quick look at LINX.
Personally I would write if x/8 = int(x/8) then goto a1 as If x Mod 8 = 0 Then x = x + 1
Re: Chess game
Agreed - I hope there is someone who could help us get this part of the code working - especially given the speed improvements from translating and updating into latest FB - it is particularly frustrating as the winboard related code works perfectly in FB 0.15 so there is some probkem relating to the code update to more recent FB version.I have tried to get winboard protocol working but I did not get it working but perhaps there is someone that can get to work. Having it working would make testing must easier.
The core winboard framework I/O code was given to me by an another programmer many years ago - it is beyond my programming abilities - from this code - although it took me a long time - I managed to implement the relevant winboard features and integrate them into Numpty myself.
With Frisian's updated version all I've been able to determine so far is that nothing is being received - STemp is not being filled - so in the following code the function is terminating prematurely as no data is being retrieved
Code: Select all
Function GetCommand As String
Dim As Integer inputHandle = GetStdHandle(STD_INPUT_HANDLE)
'This function will retrieve one command at a time from winboard.
Dim As String sBuff
Dim As Integer iBytesRead, iTotalBytes, iAvailBytes, iReturnCode
'GetCommand = ""
STemp = ""
' Null character will make sBuff a C style empty string
sBuff = Chr(0)
' PeekNamedPipe tells us if there is any data waiting to be retrieved.
iReturnCode = PeekNamedPipe(InputHandle, ByVal StrPtr(sBuff), 1, iBytesRead, iTotalBytes, iAvailBytes)
' return empty string when there is no data to be retrieved.
If iTotalBytes = 0 Then Exit Function
' Retrieve data
Do
iReturnCode = ReadFile(InputHandle, ByVal StrPtr(sBuff), 1, iBytesRead, NULL)
If sBuff = Chr(10) Then Exit Do ' exit on line feed
sTemp += sBuff
Loop
GetCommand = sTemp
CloseHandle(inputhandle)
End Function
Re: Chess game
I managed to get the winboard protocol working, it needed a bit of tinkering.
I have added #Include "windows.bi" at the beginning of the program, it contains declares and definitions for the some routine rendering some other stuff obsolete.
In the sendcommand and getcommand routine's added a few @ making it pointers to a variable instead of the variable itself. And most important removed the CloseHandle statements (it seems that the pipe needs to be open all the time).
It works under winboard and arena. Under arena I had play against it self, in one of the games arena complained about a illegal move. Will run a little competition to see how it performs.
new version
I normally stick to console, it looks not great but it works.
Let me know what you think of it.
Edit.
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena.
I have added #Include "windows.bi" at the beginning of the program, it contains declares and definitions for the some routine rendering some other stuff obsolete.
In the sendcommand and getcommand routine's added a few @ making it pointers to a variable instead of the variable itself. And most important removed the CloseHandle statements (it seems that the pipe needs to be open all the time).
It works under winboard and arena. Under arena I had play against it self, in one of the games arena complained about a illegal move. Will run a little competition to see how it performs.
new version
I normally stick to console, it looks not great but it works.
Let me know what you think of it.
Edit.
Link points to a newer version, Nomega will compile with GCC(64) and run under Arena.
Last edited by frisian on Apr 23, 2014 18:54, edited 3 times in total.
-
- Posts: 993
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: Chess game
Great ! I download it at once.