Chess game

User projects written in or related to FreeBASIC.
Roland Chastain
Posts: 1003
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Chess game

Post by Roland Chastain »

You have made a good job, frisian.

I compiled your code with fbc 0.90.0, copied the executable in Winboard directory and played a whole game without error. The only bad thing I noticed is that I lost. :)

Code: Select all

[Event "Computer Chess Game"]
[Site "PORTABLE"]
[Date "2014.03.05"]
[Round "-"]
[White "Roland"]
[Black "N_O_m_e_g_a"]
[Result "0-1"]
[TimeControl "40/300"]

1. e4 e5 2. Bc4 Nc6 3. Qf3 Nf6 4. Nc3 Nd4 5. Qd1 b5 6. Bd3 b4 7. Na4 d5 8.
f3 Bb7 9. Nh3 Bc6 10. c3 Ne6 11. c4 dxe4 12. fxe4 Qxd3 13. Qf3 Qxf3 14.
gxf3 Bxa4 15. b3 Bc6
{Black wins on time} 0-1
To run Winboard with Numpty, I used this batch script.

Code: Select all

@echo off

C:\WinBoard-4.7.2\WinBoard\winboard.exe -cp -fcp "nomega_win" -fd "C:\WinBoard-4.7.2\Numpty"

pause
Congratulations to FB_Numpty and frisian ! As soon as I have time, I will have a look into the code.
Last edited by Roland Chastain on Mar 05, 2014 22:11, edited 1 time in total.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

I have placed a new version on mediafire.
I inserted some new data for WP_PST and WP_end_PST from Numpty_DD and remove some text that I had inserted in a line which prevended Arena for printing some info.

You can run the program under Arena but some commands that Arena sends are not correctly processed by the program. You better stick to Winboard to run the program.

link to NoMega

FB_Numpty

When comparing my version with Numpty_DD I spotted something I was totally forgotten, it is something that is easy overlooked.
In the function computer_move(...) near the end there are a few lines that deal with the number of Knight's and Bishop's in the game.

If B(B_M_To) = 2 then Wkn = Wkn - 1
if B(B_M_To) = 3 then WBp = WBp - 1
if B(B_M_To) = -2 then Bkn = Bkn - 1
if B(B_M_To) = -3 then Bkn = Bkn - 1 <== This needs to be Bbp = Bbp - 1

Roland Chastain
How can you lose from NoMega, it is that good. I have seen play against it self, I will post some games later.

Edit:
link points to a newer version, Nomega will now compile with GCC(64) and run under Arena.
Last edited by frisian on Apr 23, 2014 18:37, edited 2 times in total.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

Roland Chastain wrote:
The only bad thing I noticed is that I lost. :)

Code: Select all

[Event "Computer Chess Game"]
[Site "PORTABLE"]
[Date "2014.03.05"]
[Round "-"]
[White "Roland"]
[Black "N_O_m_e_g_a"]
[Result "0-1"]
[TimeControl "40/300"]

1. e4 e5 2. Bc4 Nc6 3. Qf3 Nf6 4. Nc3 Nd4 5. Qd1 b5 6. Bd3 b4 7. Na4 d5 8.
f3 Bb7 9. Nh3 Bc6 10. c3 Ne6 11. c4 dxe4 12. fxe4 Qxd3 13. Qf3 Qxf3 14.
gxf3 Bxa4 15. b3 Bc6
{Black wins on time} 0-1
Think you need to move quicker Roland! (though it looks like game was lost by then)
Congratulations to FB_Numpty and frisian ! As soon as I have time, I will have a look into the code.
Thanks - if you do look at the code, some tips about integrating the rebel book would be really helpful - I'm impressed you have managed to do this with Eschecs - Numpty's book was developed and entered by hand - in hindsight not something to be recommended!
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

Excellent news to get winboard working - great work and many thanks frisian! (I had sussed out about close handle but was struggling beyond that).

I haven't looked at code yet but managed to run a small number of games - there are some problems or errors I've noticed from using to date:

- both winboard enabled versions crash in winboard or arena if compiled with optimization settings (eg -gen gcc -O 3) - so real improvement in strength from speed increase isn't available (not sure why this should be the case?).
- Numpty doesn't use opening book
- the engine crashes if there is a second Queen promotion of the same colour
- I don't think repcheck function is maybe working as intended - I was losing a game pretty convincingly and Numpty walked into a 3 fold repetition (original Numpty won't do this so easily)
- Forcemode doesn't work at the moment resulting in illegal move (this is a problem if you use third party books in chess gui)

I also noticed that in some positions the engine evaluation and search results and resulting move are different from Numpty DD indicating that there are other changes to either or both.

I will have a bit of time this weekend, so will start to have a look and see if I can find and fix some of these issues (I also remember there is the castling bug to find)

frisian wrote:I have placed a new version on mediafire.
I inserted some new data for WP_PST and WP_end_PST from Numpty_DD and remove some text that I had inserted in a line which prevended Arena for printing some info.

When comparing my version with Numpty_DD I spotted something I was totally forgotten, it is something that is easy overlooked.
In the function computer_move(...) near the end there are a few lines that deal with the number of Knight's and Bishop's in the game.

If B(B_M_To) = 2 then Wkn = Wkn - 1
if B(B_M_To) = 3 then WBp = WBp - 1
if B(B_M_To) = -2 then Bkn = Bkn - 1
if B(B_M_To) = -3 then Bkn = Bkn - 1 <== This needs to be Bbp = Bbp - 1
Good spot! - this must have been the case almost the beginning - will correct. Thank you again for all your hard work on this - it is much appreciated
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

FB_Numpty

I had a look at a few issues and I must admit that for most off it I am to blame, when i tried to get it to compile with the newer versions of FB I neglected the winboard part because it did not work. I will try this weekend to get things running correctly.
I have partial fixed the crash when compiled with GCC, it does not crash anymore but it does not run under Arena (2 small errors, 1 by me and 1 by you). It runs fine in console mode. It looks if something in the winboard part of the code is not right. I also intend to change some code here and there.

I will post a (hopefully) better version asap.

Regards.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

I had a look at a few issues and I must admit that for most off it I am to blame, when i tried to get it to compile with the newer versions of FB I neglected the winboard part because it did not work. I will try this weekend to get things running correctly.
I have partial fixed the crash when compiled with GCC, it does not crash anymore but it does not run under Arena (2 small errors, 1 by me and 1 by you). It runs fine in console mode. It looks if something in the winboard part of the code is not right. I also intend to change some code here and there.

I will post a (hopefully) better version asap.
Thanks frisian, sounds promising - I've had a bit of time this weekend trying to look for castling bug but found another problem trying to use the perft position from your earlier post:

Code: Select all

fen = r3k2r/8/8/8/8/8/8/R3K2R w - - 0 1
This kept defaulting to illegal fen in the latest version - tracking back the reason for this is that 'o_str' is being passed to the fen subroutine after the following :

Code: Select all

o_str = LCase(Trim(o_str))
This means that setboard option is only picking up black pieces! - (ie lower case characters)

To correct this for simplicity, I just changed round the following:

Code: Select all

Input "move/option"; o_str
      o_str = LCase(Trim(o_str))   '### trim spaces and make lowercase
      If Left(o_str, 9) = "setboard " Then fen(o_str)
to:

Code: Select all

Input "move/option"; o_str
      If Left(o_str, 9) = "setboard " Then fen(o_str)
      o_str = LCase(Trim(o_str))   '### trim spaces and make lowercase


setboard then works (don't think this impacts adversely elsewhere). Having done this and run perft - the latest version does indeed report wrong values:
perft(1) should be 24 - original Numpty (ie DD) reports this correctly and I've confirmed this value with other engines with perft function

Numpty_win_DD gives perft(1) = 31 and (thanks to another change of yours!) it is easy to tell which moves are incorrect - all relate to the rook on h1 and 'extra' illegal moves are:
h1-'2 , h1-i1 , h1-a2 , h1-b2 , h1-c2 , h1-d2 , h1-e2
So first thing before testing castling is to look at move gen function which I can work on if you are doing the other things - I wonder if you can confirm my findings above?
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

Re my earlier post - I've found the problem with the error in illegal move generation - it's not the move gen function but a problem related to using setboard again.

The clear board subroutine is not initialising accurately meaning that the off-board guardian values (-99) are not being set for invalid squares, so the board is effectively wrapping around:

Code: Select all


Sub clear_board
  Print "clear_board"
  Dim As Integer x, y

  For x = 0 To 119
    B(x) = -99
  Next x

 
  For X = 20 To 90                               ' ###   
    For Y = X+1 To X+8                           ' ###
      'B(X*10+Y) = 0
      B(Y) = 0                                   ' ###
    Next Y
  Next X


End Sub

variable X needs to be stepped by 10 as it is 10x12 board and guardians are the 2 squares either side of the board

Code: Select all

 For X = 20 To 90  step 10
With the above change the perft values from the previous post for Nomega_Win_DD are correct.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

FB_Numpty wrote:Re my earlier post - I've found the problem with the error in illegal move generation - it's not the move gen function but a problem related to using setboard again.

The clear board subroutine is not initialising accurately meaning that the off-board guardian values (-99) are not being set for invalid squares, so the board is effectively wrapping around:

variable X needs to be stepped by 10 as it is 10x12 board and guardians are the 2 squares either side of the board

With the above change the perft values from the previous post for Nomega_Win_DD are correct.
I altered something but remove/added to much, my apologize for that.

First About GCC I found what made GCC crash under winboard/arena.
After compile with -exx I found that it stop with a error message array out of bounds. I made act_epsq an UInteger but a -1 is loaded into it so it needs to be a Integer. Secondly there is check using B(act_epsq) since act_epsq can be -1 the array b() was out of bounds (0 to 119) needs to be (-1 to 119).

Code: Select all

Dim Shared As Integer B(-1 To 119)  
Dim Shared As Integer act_epsq                      ' actual ep-square value (ie post-move)

Restore

For x = -1 To 119
  B(x) = -99
Next x
It stopped crashing but it will not work under winboard/arena, it receives data from winboard/arena but sending date does not work. I don't know why. In console mode GCC runs just like FB.
(Need to make it a habit to testing with -exx, even when array are out of bound FB does not allways crash).

Stop working when there is a promoted queen.
With hindsight it made sense, data is send in lower case the test for it uses upper case letters

Code: Select all

	  ' ...in winboard mode
  If WinboardMode = 1 And B(MoveTo) = 1 And MoveTo > 90 Then
    If pr_str = "Q" Then B(MoveTo) = 6    need to be "q", "r", "b", "n"
    If pr_str = "R" Then B(MoveTo) = 4
    If pr_str = "B" Then B(MoveTo) = 3
    If pr_str = "N" Then B(MoveTo) = 2
  End If

  If WinboardMode = 1 And B(MoveTo) = -1 And MoveTo < 29 Then
    If pr_str = "Q" Then B(MoveTo) = -6      
    If pr_str = "R" Then B(MoveTo) = -4
    If pr_str = "B" Then B(MoveTo) = -3
    If pr_str = "N" Then B(MoveTo) = -2
  End If
Something I changed and forgot about

Code: Select all

	If O$ = "go" then
        if side = white then cmpclr = 1 
        if side = black then cmpclr = 1 <== need to be -1
        call computer_move(side)
        call display()
        if assessboard(side,best_score) = true then call ending()
        side = -side
    end if

When working on the program I got a idea for the incheck/attack routine for check by Bishop/Rook/Queen

Code: Select all

    Do
      K += Move_Offset(N)
    Loop Until (B(k) <> 0)   'keep looping until a non zero field is found

    If B(k) = val_bishop Or B(k) = val_queen Then   ' if it contains a bishop or queen then  incheck= true else try next direction
      Return TRUE                                               
    End If
simple code, guess a roll out will bring some speed up.

I called it it castling problem but it that looks to be wrong, it looks more a problem where the king is incheck and then makes the wrong move. Have a look a the following game data.

Code: Select all

[Event "Test111hla1"]
[Site "USER-PC"]
[Date "2014.03.10"]
[Round "2"]
[White "Numpty_DD"]
[Black "nomega"]
[Result "1-0"]
[BlackElo "2200"]
[ECO "C43"]
[Opening "Russian Game"]
[Time "14:28:42"]
[Variation "Modern Attack, 3...Nxe4 4.Bd3 d5 5.Nxe5 Be7"]
[WhiteElo "2200"]
[TimeControl "30/300:30/300:30/300"]
[Termination "rules infraction"]
[PlyCount "47"]
[WhiteType "program"]
[BlackType "program"]

1. e4 e5 2. Nf3 Nf6 3. d4 Nxe4 4. Bd3 d5 5. Nxe5 Nd7 6. Nd2 {(b1d2) +0.02/6
11} Nec5 {(e4c5) -0.32/6 11} 7. O-O {(e1g1) 0.00/6 11} Nxe5 {(d7e5) -0.27/6
11} 8. dxe5 {(d4e5) +0.22/7 19} Nxd3 {(c5d3) -0.22/6 11} 9. cxd3 {(c2d3)
-0.08/4 0} Be7 {(f8e7) -0.22/6 11} 10. d4 {(d3d4) -0.15/6 11} O-O {(e8g8)
-0.15/6 11} 11. Nf3 {(d2f3) -0.20/6 10} Be6 {(c8e6) -0.15/6 7} 12. Qb3
{(d1b3) -0.05/6 10} Rb8 {(a8b8) -0.15/6 12} 13. Be3 {(c1e3) -0.15/6 11} f6
{(f7f6) -0.08/6 11} 14. Rad1 {(a1d1) -0.13/6 12} Bg4 {(e6g4) +0.05/6 11}
15. Bf4 {(e3f4) -0.20/6 11} fxe5 {(f6e5) +0.11/6 11} 16. Bxe5 {(f4e5)
-0.04/7 10} Qd7 {(d8d7) +0.04/6 12} 17. Rc1 {(d1c1) -0.18/6 12} Rfc8
{(f8c8) +0.01/6 12} 18. Bf4 {(e5f4) -0.11/6 11} Bf5 {(g4f5) -0.02/6 13} 19.
Rfe1 {(f1e1) -0.11/6 12} Bf6 {(e7f6) -0.19/6 11} 20. Qc3 {(b3c3) +0.19/5 8}
Ra8 {(b8a8) -0.14/6 13} 21. Qc5 {(c3c5) +0.14/5 9} b6 {(b7b6) -0.27/6 13}
22. Qc6 {(c5c6) +0.52/6 13} Qxc6 {(d7c6) -0.62/6 14} 23. Rxc6 {(c1c6)
+0.52/4 0} Bd8 {(f6d8) -0.62/6 11} 24. Re8 {(e1e8) +0.57/6 14  Arena
Adjudication. Illegal move!} 1-0
If you look at the first part of the FEN you can see that the black king is attack by a white rook,

r1rbR1k1/p1p3pp/1pR5/3p1b2/3P1B2/5N2/PP3PPP/6K1 b - - 2 24

black plays Bf5-g6 ignoring the fact that it is checked, the only legal move for black is Kg8-f7.

I entered the FEN with setboard and saved it (loading it is easier than retyping it).
When I loaded it, I gave a perft command, level 1,and I got a answer of 30 nodes. This is wrong and thinking about it I realized that the load routine does not set wkloc and bkloc to it proper value's. Added some code to do this and tried again, the answer was 1 node. The best idea I now have about the problem is that the program somehow loses track of the position of the king's.

new version
It uses the book for openings and also uses the variations. Endgames vary, kings tends to prefer the center leaving pawns on the edge on there own, when both sides are equal in strength most games end in 3 fold repetions.

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:40, edited 1 time in total.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

I altered something but remove/added to much, my apologize for that.
No worries frisian, I appreciate all the hard work you have put in especially given your greater programming skills and the opportunity to update the program into more recent FB has re-ignited my interest in looking at the code.
Secondly there is check using B(act_epsq) since act_epsq can be -1 the array b() was out of bounds (0 to 119) needs to be (-1 to 119).
Thanks for the explanation - I'm not sure but will changing the Board array throw out any of the initializing calculations - eg within the array the actual board is currently a1 = B(21) .... h8 = B(98)?
Stop working when there is a promoted queen.
With hindsight it made sense, data is send in lower case the test for it uses upper case letters
Yes good point - I never thought about the implications of using lower case elsewhere in the program.
It stopped crashing but it will not work under winboard/arena, it receives data from winboard/arena but sending date does not work
I can confirm sadly latest version still crashes in arena with optimisation - this is a real pity and maybe something that can be fixed later - your latest version in the current FB compiled without any optimisation or options is only about 5-10% faster than the original Numpty from 0.15b - (part of this is due to extra nodes being counted - another issue to resolve!) so the real benefit in the translation is in the speed increase from optimisation - without winboard interfacing I think the program has only limited interest.
It uses the book for openings and also uses the variations. Endgames vary, kings tends to prefer the center leaving pawns on the edge on there own, when both sides are equal in strength most games end in 3 fold repetions.
Thanks for the updated version and for fixing the book and force mode issues (the latter is particularly helpful for replicating and fixing bugs with move errors) - I think it is good if you keep the master version. Not sure what you mean about endgames - have you changed any evaluation terms?
The best idea I now have about the problem is that the program somehow loses track of the position of the king's.
Thanks for posting the game - I looked at this and understand your conclusion. I'm not sure yet though - when originally debugging the engine I was painfully aware that using setboard to try and replicate a bug from a game was not always successful as they use different code. This was particularly the case when trying to resolve bugs with en-passant square etc. This is why force mode was so important, as to find the bug, often the best way is simply to:
- compile a version which enables printing of all moves searched
- walk through the game manually (eg with edit in arena) until the move before
- set level or depth accordingly and get engine to think - in this case probably start at d = 1
- see what moves are considered and which is played and repeat as necessary etc

I've done a bit of investigative work on the castling bug and you're right there is certainly an issue. I've used the perft positions on the chess programming wiki - latest version passes most of the tests already but chokes on the following:
r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
All is good to perft 5 where current version then starts to over-report moves - in particular the following are incorrect:
e1-f1, e1-d1, a1-b1, a1-c1, a1-d1, h1-g1-f1
Given the errors start at (d=5) I suspect what is happening is something like the following 1 Rb1 ... 3 Ra1... 5 O-O-O so essentially the engine is 'forgetting' the fact that from an earlier depth it can't cancel and then is then incorrectly castling on the 5th move. And the same for the cases where the King moves first. I suspect with the changes you have made to the code in this area it may be quicker for you to try and fix this. i don't yet fully understand your changes (I spent a lot of time last night and failed so far to find and fix the bug). One error i did spot I think which if so, should be corrected:

Code: Select all

      ' if K-side castled then unmake rook move at root
      If side = white And w_casflags(depth, 1) = 1 And w_cas(1) = 0 Then
        B(26) = 0 : B(28) = 4
        w_casflags(depth, 1) = w_casflags(depth-1, 1)                ' reset kingside castle flag
        'corrected 24/3/09 thanks Leo!
      ElseIf side = black And b_casflags(depth, 1) = 1 And b_cas(1) = 0 Then
        B(96) = 0 : B(98) = -4
        b_casflags(depth, 1) = b_casflags(depth-1, 2) <-------------------- s/be 1?
      End If


However this in itself isn't the reason for the error in the perft results.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

FB_Numpty wrote:
Secondly there is check using B(act_epsq) since act_epsq can be -1 the array b() was out of bounds (0 to 119) needs to be (-1 to 119).
Thanks for the explanation - I'm not sure but will changing the Board array throw out any of the initializing calculations - eg within the array the actual board is currently a1 = B(21) .... h8 = B(98)?
Doing it this way is the easiest fix, it will not affect the rest of the array. Since B(-1) was not intialize at startup it could have any value including 0, the program did not write to that location so nothing happens but it not the right way. I could have changed -1 into a other value but that would have been more work.

If you write a new version you can make things a lot easier. if you make act_epsq 0 (ZERO) when there is no ep and when there is make the act_epsq the value of the ep square. I gen_move you test if the square is empty ( if B(act_epsq) = 0 then) but that is not needed, the square has to be empty to make ep possible.
It stopped crashing but it will not work under winboard/arena, it receives data from winboard/arena but sending date does not work
I test it again and you are right on this, I don't what causes this. I put this issue on the back burner for now, will look into it later.

Code: Select all

      ' if K-side castled then unmake rook move at root
      If side = white And w_casflags(depth, 1) = 1 And w_cas(1) = 0 Then
        B(26) = 0 : B(28) = 4
        w_casflags(depth, 1) = w_casflags(depth-1, 1)                ' reset kingside castle flag
        'corrected 24/3/09 thanks Leo!
      ElseIf side = black And b_casflags(depth, 1) = 1 And b_cas(1) = 0 Then
        B(96) = 0 : B(98) = -4
        b_casflags(depth, 1) = b_casflags(depth-1, 2) <-------------------- s/be 1?
      End If

Your right about that, the "2" needs to be a "1".

I'm trying at the moment to get the results for perft correct, the result is mixed some FEN's give the correct answer others fail at depth 7.
I have nomega doing a perft depth 10 to see if a alteration I made works when depth get higher, I have added some code that seems to work in some cases but in other it does not work, see if the code works or that it looks that it works. But this takes time to get results.

I also came across a other problem I Numpty_DD and NoMega play a tournament (at night) under Arena (40 moves / 5 min). The following morning they had played 35 games Numpty_DD won 19 of them.
NoMega lost 5 games due to the fact it run out of time. No illegal moves this time. I checked the code that controls the timing aspect of the program but they a equal , so there must be something else.

While checking NoMega code agains Numpty_DD I saw some thing that can be alter in order to get small increases in speed.

But for now I have to wait until NoMega finish the perft tests.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

Doing it this way is the easiest fix, it will not affect the rest of the array. Since B(-1) was not intialize at startup it could have any value including 0, the program did not write to that location so nothing happens but it not the right way. I could have changed -1 into a other value but that would have been more work.

If you write a new version you can make things a lot easier. if you make act_epsq 0 (ZERO) when there is no ep and when there is make the act_epsq the value of the ep square. I gen_move you test if the square is empty ( if B(act_epsq) = 0 then) but that is not needed, the square has to be empty to make ep possible.
This is helpful, and another helpful suggestion, thanks
I'm trying at the moment to get the results for perft correct, the result is mixed some FEN's give the correct answer others fail at depth 7.
I have nomega doing a perft depth 10 to see if a alteration I made works when depth get higher, I have added some code that seems to work in some cases but in other it does not work, see if the code works or that it looks that it works. But this takes time to get results.
Let me know if you want me to run any specific tests to help speed up the testing.
I also came across a other problem I Numpty_DD and NoMega play a tournament (at night) under Arena (40 moves / 5 min). The following morning they had played 35 games Numpty_DD won 19 of them.
NoMega lost 5 games due to the fact it run out of time. No illegal moves this time. I checked the code that controls the timing aspect of the program but they a equal , so there must be something else.
I'm assuming NoMega is your latest version? - if so, I think I have found the same problem - I didn't mention this as I thought we had enough problems with perft and winboard! :)

I played a couple of games between them earlier in the week and NoMega lost one game on time on move 75 (no crash but didn't finish thinking - it was trying to move out check (which given the limited number of moves meant it had reached a high depth of search). I used to have this problem in earlier Numpty versions and that's why put in the time check in the ab search so there would be more frequent checks if time was running out. I've only had a quick look but the change you made here - If fix_depth = 0..... shouldn't make any difference - I will also have a look at this but from memory don't think you changed any of the time time parameters.
While checking NoMega code agains Numpty_DD I saw some thing that can be alter in order to get small increases in speed.
This will be good - the faster the better!
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »

Ok I've had a look to try and resolve the problems with illegal moves and losses on time.

Firstly, a test run of 60/1 in Arena gave results of 28:22 to Numpty over Nomega 140310 - in the 50 games there were 19 losses on time and 3 losses by rules infraction (ie illegal moves).

After digging about, and looking at some of the losses I think I found two specific problems causing these losses.

Firstly, using the test game below
[Event "New nomega test1"]
[Site "MY-PC"]
[Date "2014.03.15"]
[Round "20"]
[White "Numpty_DD"]
[Black "Nomega_140310"]
[Result "1-0"]
[BlackElo "2200"]
[ECO "B22"]
[Opening "Sicilian"]
[Variation "Alapin, 2...d5 3.exd5 Qxd5 4.d4 Nc6 5.Nf3"]
[WhiteElo "2200"]
[TimeControl "60/60:60/60:60/60"]
[Termination "rules infraction"]
[PlyCount "51"]
[WhiteType "program"]
[BlackType "program"]

1. e4 c5 2. Nf3 Nc6 3. c3 d5 4. exd5 Qxd5 5. d4 e6 6. Be2 Nf6 7. O-O cxd4
8. cxd4 Be7 9. Nc3 Qd7 10. Be3 Ng4 11. Bf4 O-O 12. Bc4 Rd8 13. Bb5 a6 14.
Bc4 Nf6 15. Ne2 Nd5 16. Ne5 Qc7 17. Bxd5 Rxd5 18. Qc2 Bd6 19. Rac1 Bd7 20.
Nxd7 Bxf4 21. Nxf4 Qxf4 22. Nb6 Nxd4 23. Nxd5 Qd6 24. Qc8+ Qd8 25. Ne7+ Kh8
26. Qxd8 {Arena Adjudication. Illegal move!} 1-0

Fen: r2Q3k/1p2Nppp/p3p3/8/3n4/8/PP3PPP/2R2RK1 b - - 0 1
The problems are in computermove function. The illegal move is happening because the only valid move Rxd8 returns a score of -399 but for some reason all the invalid moves are returning a score of 0 (even though the code still jumps to Cm2a bypassing the score function). This doesn't happen in original Numpty versions in FB 0.15 and can't see anything obviously wrong with your code (maybe a foible of the newer version? (however I did remove the Do..While loop around the score function). So to fix this situation I added (root > 0) to condition statement for updating best score & move (ie there has to be at least one valid move to update the score):

Code: Select all


 If root > 0 and score > best_score And check_root = FALSE Then
        best_score = score                       ' set new best-score
        B_M_From = Move_List(depth, w, 1)
        B_M_To = Move_List(depth, w, 2)
        Pe = B(Move_List(depth, w, 1))
        'reset promotion flag if promotion is no longer best move in current ply
        If prom_last_ply = 1 Then prom_last_ply = 0
        If side = white And wprom(depth) = 1 Then
          prom_last_ply = 1
          Pe = Move_List(depth, w, 3)            'if promoted piece then update sqr with new piece
          Move_List(depth, w, 3) = 0             ' reset prom piece else 2nd prom with Q on back rank turns Q back to P! 14/11/08
        End If
        If side = black And bprom(depth) = 1 Then
          prom_last_ply = 1
          Pe = Move_List(depth, w, 3)            'if promoted piece then update sqr with new piece
          Move_List(depth, w, 3) = 0             ' reset prom piece else 2nd prom with Q on back rank turns Q back to P! 14/11/08
        End If
        If it_depth > 3 Then                     ' for depth > 3 then display pv etc
          elp_time = Timer
          accum1 = (elp_time - ply_start_time)
          BMFROM_str = move_2_str(Move_List(depth, w, 1))
          BMTO_str = move_2_str(Move_List(depth, w, 2))
          If post = 1 Then Print it_depth; " "; best_score; " "; CInt((elp_time - ply_start_time) * 100); " "; total_nodes + nodes; "  "; BMFROM_str; BMTO_str
        End If
      End If

It feels a bit of a hack but it works - I found the other problem causing the time losses with this game:
[Event "New nomega test3"]
[Site "MY-PC"]
[Date "2014.03.16"]
[Round "1"]
[White "Nomega_140310"]
[Black "Numpty_DD"]
[Result "0-1"]
[BlackElo "2200"]
[ECO "B23"]
[Opening "Sicilian"]
[Variation "Closed, 1.e4 c5 2.Nc3 d6 3.f4"]
[WhiteElo "2200"]
[TimeControl "60/60:60/60:60/60"]
[Termination "time forfeit"]
[PlyCount "112"]
[WhiteType "program"]
[BlackType "program"]

1. e4 c5 2. Nc3 d6 3. f4 g6 4. Nf3 Bg7 5. Bb5+ Bd7 6. Bxd7+ Qxd7 7. O-O Nc6
8. d3 Nd4 9. Be3 e6 10. Qd2 Ne7 11. Qf2 Nxf3+ 12. Qxf3 O-O 13. Rad1 Bxc3
14. bxc3 Qa4 15. e5 Nd5 16. exd6 Qxc2 17. Bxc5 Nxc3 18. d7 Rfd8 19. Ra1
Ne2+ 20. Kh1 Rxd7 21. Qe3 Rxd3 22. Qe4 Rc8 23. Bxa7 Rd7 24. Qf3 Ra8 25. Qb3
Qxb3 26. axb3 f5 27. Be3 Rxa1 28. Rxa1 Rd3 29. Bc5 Nxf4 30. b4 Kf7 31. g3
Ne2 32. Ra7 Rd7 33. Kg2 e5 34. Kf3 Nc3 35. h4 Nd5 36. b5 e4+ 37. Kf2 Ke6
38. Bd4 Rc7 39. b6 Rc4 40. Bg7 Rc2+ 41. Ke1 Nxb6 42. Rxb7 Nd5 43. Bh6 Rg2
44. Rxh7 Rxg3 45. Bg5 Rb3 46. Rg7 Rb1+ 47. Kd2 Ke5 48. Rxg6 Rb2+ 49. Kc1
Rh2 50. Rh6 e3 51. Rh8 Rg2 52. Re8+ Kd4 53. Rd8 Ke4 54. Rg8 f4 55. Re8+ Kd3
56. Bxf4 Rc2+ 57. ... {White forfeits on time} 0-1

Fen: 4R3/8/8/3n4/5B1P/3kp3/2r5/2K5 w - - 1 1
In this case there are two valid moves for white but both lead to mate and the best evaluation is -9994. It took a while to find out why Nomega would not play one of these moves then I realised that at the start of computermove function - in this version the best_score is set to -9000 instead of -10000.

So this means that because the best move found in the search is a losing mate and in this cases scores -9994 it is never higher than the initial value of -9000 and therefore the 'if score > best_score...' condition is never triggered and no move is made.

So to correct this just reverted back to orginal value:

Code: Select all


 best_score = -10000  
 


Just finished another 50 game match under the same conditions - NumptyDD wins by 30:20 - so it seems there still some other things that need to be resolved but at least there were no illegal moves or time losses in these games.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Chess game

Post by FB_Numpty »


Just finished another 50 game match under the same conditions - NumptyDD wins by 30:20 - so it seems there still some other things that need to be resolved but at least there were no illegal moves or time losses in these games.

50 games isn't a big enough sample to form a view, and 500 is better though still not enough. Good news! - over a larger number of games (still at 60/1) the new version pulls through!

Code: Select all


1: Nomega_140310 266.5/500 
2: Numpty_DD     233.5/500

This equates to about 23 elo with a likelihood of superiority (LoS) of 96.4% which is very promising. No time losses or illegal moves in 500 games. I think optimisation alone would add at least another 100 elo notwithstanding any other improvements that can be made (I certainly found a bug with Numpty playing at this fast control that is not replicated at slower time controls).
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

FB_Numpty

Will add your suggestions and see how things go. I had seen the thing about score = 0 and thought that it could give problems, but had a closer look into it.

I have (hopefully) solved the castling problem, I added code that store and place back the values of w_cas and b_cas. Since I altered a few things I need to adjust some old code to work with the new code. Sadly the program has lost some speed due to the new code. I have some plans for further speedups that could merge with the new code gaining some time back that was lost. I have run a perft on some FEN's (depth 10) and they all gave the correct answer.

I have also replaced the incheck() and attack() routines it takes 2k extra but is much faster then the old code. The combined speed gain is about 15%.

The new code, after making some adjustments look the work correct. Arena made some restarts and I had even a few crashes. I haven't figured out what caused the problem, could be Arena.

If you have time you should have a look to at the make_move and unmake_move routines, unmake "unmakes" more things than "make" makes.

I also came across a problem with the 3-fold repetition routine. Have a look at the following game file

Code: Select all

[Event "Test"]
[Site "USER-PC"]
[Date "2014.03.17"]
[Round "73"]
[White "Numpty_DDorg"]
[Black "Nomega"]
[Result "*"]
[BlackElo "2200"]
[ECO "B17"]
[Opening "Caro-Kann"]
[Time "18:29:11"]
[Variation "Steinitz, 5.Bc4 Ngf6"]
[WhiteElo "2200"]
[Termination "unterminated"]
[PlyCount "55"]
[WhiteType "program"]
[BlackType "program"]

1. d4 d5 2. c4 e6 3. Nc3 c6 4. e4 Nf6 {(g8f6) -0.80/4 0} 5. e5 {(e4e5)
+0.50/4 0} Ne4 {(f6e4) -1.00/4 0} 6. Nxe4 {(c3e4) +0.50/4 0} dxe4 {(d5e4)
-0.75/4 0} 7. Ne2 {(g1e2) +0.45/4 0} Nd7 {(b8d7) -0.70/4 0} 8. c5 {(c4c5)
+0.28/4 0} f6 {(f7f6) -0.65/4 0} 9. exf6 {(e5f6) +0.25/4 0} Nxf6 {(d7f6)
-0.50/4 0} 10. Be3 {(c1e3) +0.13/4 0} Be7 {(f8e7) -0.38/4 0} 11. Nc3
{(e2c3) +0.18/4 0} O-O {(e8g8) -0.55/4 0} 12. Qc2 {(d1c2) +0.28/4 0} Nd5
{(f6d5) -1.12/4 0} 13. Nxe4 {(c3e4) +0.91/4 0} Nxe3 {(d5e3) -1.12/4 0} 14.
fxe3 {(f2e3) +0.91/4 0} Qa5+ {(d8a5) -1.22/4 0} 15. Kd1 {(e1d1) +1.08/4 0}
Bd7 {(c8d7) -1.17/4 0} 16. Bc4 {(f1c4) +1.00/4 0} Qb4 {(a5b4) -1.22/4 0}
17. a3 {(a2a3) +1.08/4 0} Qa5 {(b4a5) -2.12/4 0} 18. Qb3 {(c2b3) +1.91/4 0}
Qc7 {(a5c7) -2.02/4 0} 19. Bxe6+ {(c4e6) +2.02/4 0} Bxe6 {(d7e6) -2.09/4 0}
20. Qxe6+ {(b3e6) +1.94/4 0} Kh8 {(g8h8) -2.22/4 0} 21. Ke2 {(d1e2) +2.02/4
0} Rad8 {(a8d8) -2.24/4 0} 22. Rad1 {(a1d1) +2.02/4 0} Rfe8 {(f8e8) -2.27/4
0} 23. Qc4 {(e6c4) +2.02/4 0} b6 {(b7b6) -2.19/4 0} 24. b4 {(b2b4) +2.02/4
0} Rf8 {(e8f8) -2.17/4 0} 25. Rde1 {(d1e1) +2.02/4 0} Rfe8 {(f8e8) -2.14/4
0} 26. Rd1 {(e1d1) +2.02/4 0} Rf8 {(e8f8) -2.17/4 0} 27. Rde1 {(d1e1)
+2.02/4 0} Rfe8 {(f8e8) -2.14/4 0} 28. Rd1 {(e1d1) +2.02/4 0} *
After white move the pawn from b2 to b4 in move 24 the only two pieces that are moved are two rooks.
When white moves in move 28 (e1d1) there is a claim for draw by 3-fold repetition (don't know which side).
But Arena will not show the text draw by 3-fold repetition (only after black has moved). I have read the wiki text on 3-fold repetition, it states that draw by 3-fold repetition can be claimed if the same position has occurred 3 times and the same side is to move and is to make the same move. Since the position is made by moving of the white pawn, white can not claim a draw when the position occurs for the third time it moves the rook not the pawn, therefor black needs to play its move before it can claim a draw.
In other words if in the same position the same move has to be made (white has only made 2 the same moves) 3 times then a draw can be claimed.
It's something I have been struggling to understand.

I will run a few games to see if every thing works as it should be.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Chess game

Post by frisian »

New version of my version of NoMega

Changed the code for incheck() and attack(), and added my own code for keeping track of castling. Also included two fixes by FB_Numpty.
Run a tournament of 22 games, non of them ended with a illegal move.
The problem with a GCC compiled program running under Arena/Winboard still exists.

The crashes that I had seems to caused by third program. Nomega needs to be stopped and reloaded when it needs to start a new game since it has a new function. Arena was running a tournament with 4 half moves per turn, this is very fast probably there was something like a hick up.

the link to the new version is here

Let me know if have any problem with the program.

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:43, edited 6 times in total.
Post Reply