Simple extensions?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Simple extensions?

Post by mike_bike_kite »

I'm slowly trying to improve my chess program. It's written in Java and can look ahead 4 ply in a few seconds but going up a level means waiting too long for a reply. I already use ID and remove the worst 20% of moves on each loop. Obviously I could use C/C++/assembler etc to improve speed but I want it to run in a browser.

I tried to implement extensions but this seemed to make it play worse (?) so I guess I messed up. My current plan is to try the following. Does this look right? is it likely to improve it's play? is there anything I need to watch out for? are null moves required or are they just an improvement?

Code: Select all

...
put on move
if the move is check 
   or response to check 
   or the move is a pawn to the 7th or 8th 
   or the move takes a piece on a square played recently then 
      extend by 1
else if the move takes a piece or moves a pawn to 6th 
      extend by 0.5
else
      no extend

score = go up a level( depth + extend )
better score?
takeoff
...
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Simple extensions?

Post by PK »

It's a bad idea to extend both checks and responses to checks by one ply - You might end up extending till some wired in depth limit kicks in. try extending only checks and nothing more, then add ideas one by one and see which one hurts.

as for null move, it is of great help, but some precautions are needed (good material on this and other topics might be found on chesprogramming wiki)
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Simple extensions?

Post by tpetzke »

Hi Mike,

when you extend both check and check escapes make sure you extend only those escapes where the side in check has only one legal move (maybe two but than do not extend a full ply in case of two).

You also want to make sure that you extend not to much when several of your conditions match, so when you get of of check by checking the opponent by a pawn push to the 7th you usually do not want to extend 3 ply, but just one.

Thomas...
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Simple extensions?

Post by tpetzke »

BTW 4 ply in a few seconds seems very slow is this because it runs in a browser because java should not slow you down that much.

How many nodes do you visit in you 4 ply search

Code: Select all

iCE 0.2 build 1036 [2011.8.27]
go depth 4
info depth 1 seldepth 1 time 0 nodes 40 pv e2e4  nps 39999 score cp 29 hashfull 0 tbhits 0
info depth 2 seldepth 2 time 0 nodes 107 pv e2e4 e7e5  nps 106999 score cp 0 hashfull 0 tbhits 0
info depth 3 seldepth 4 time 0 nodes 1212 pv d2d4 d7d5 c1f4  nps 1211999 score cp 15 hashfull 0 tbhits 0
info depth 4 seldepth 6 time 16 nodes 3357 pv e2e4 e7e5 d2d4 e5d4  nps 209812 score cp 10 hashfull 0 tbhits 0
bestmove e2e4 ponder e7e5
so ice manages 4 ply with less than 5000 nodes and it is not because of the 0 move (depth is to low for that).

Is your alpha beta framework performing correctly ?

Thomas...
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: Simple extensions?

Post by mike_bike_kite »

PK : It's a bad idea to extend both checks and responses to checks by one ply I've now implemented it so it doesn't extend on response to check. It works OK but it still makes mistakes - I'm obviously doing something wrong!

tpetzke : when you extend both check and check escapes make sure you extend only those escapes where the side in check has only one legal move (maybe two but than do not extend a full ply in case of two). I'll add this shortly.

tpetzke : BTW 4 ply in a few seconds seems very slow is this because it runs in a browser because java should not slow you down that much.
I'm afraid I had to reorganise the code to generate these figures hence the delay in responding :

Code: Select all

Depth 1
MinMax #n=20 time=79 nps=0k score=71
AlphaBeta #n=20 time=0 nps=0k score=71

Depth 2
MM #n=238 time=15 nps=15k score=3
AB #n=238 time=16 nps=14k score=3

Depth 3
MM #n=3691 time=453 nps=8k score=84
AB #n=3691 time=157 nps=23k score=84

Depth 4
MM #n=41859 time=1515 nps=27k score=-6
AB #n=41859 time=1328 nps=31k score=-6
Depth 1 - numbers look fine to me though your depth 1 showed 40 nodes so I assume your depth 1 is really 2 ply then.
Depth 2 - looks a little odd because the number of nodes (#n) shows 238 - I'd of thought it would be 20*20=400.

Also odd that the AlphaBeta shows the same number of nodes as the MinMax even though it runs quicker - this could be my reporting or the code. At least the scores generated are the same and it's calculating this score in less time :)

The nps on yours is 1211999 while on mine I get around 31000. This suggest yours is 40 times quicker. Java usually uses a JIT (just in time) compiler and normally I don't have issues with speed. C++ is obviously going to be quicker than Java and I'm guessing that you hard core chess programmers use slightly better hardware than I do (Celeron 2.4 Ghz single core with 1GB ram). Going 40 * quicker would allow me to search an extra ply but I don't think that will make a massive difference to the programs strength.
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: Simple extensions?

Post by mike_bike_kite »

I found an issue in the reporting and this looks better. I believe it's showing 420 for minmax at depth 2 because the same function is called to see if any move is available to check for stalemate/checkmate. This output also shows that the number of nodes is always less for alpha beta, faster and generates the same move as it should.

Code: Select all

Level Type   Nodes   Time    Nps   Score  Move
   1   MM       20     78      0      71 Ng1-f3
   1   AB       20      0      0      71 Ng1-f3
   2   MM      420     31     13       3 Pe2-e4
   2   AB      238     31      7       3 Pe2-e4
   3   MM     9322    515     18      84 Pe2-e4
   3   AB     3691    125     29      84 Pe2-e4
   4   MM   207064   7094     29      -6 Ng1-f3
   4   AB    41859   1312     31      -6 Ng1-f3
User avatar
hgm
Posts: 27809
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple extensions?

Post by hgm »

The number of minimax nodes at d=2 should be 400+20+1, if you also count internal nodes. A bit more, in fact, because of quiescence search, as in 14 positions after 2 ply a capture is possible, and in some even deeper captures (e.g. 1. e4 d5 2.exd5 Qxd5). But because of alpha-beta you will have fewer. Some of the ply 1 moves will be rejected before all replies have been tried. If the counts you report are alpha-beta nodes, though, they seem a bit high. In Joker I have:

Code: Select all

  4	0.00	3181	0:00.02	d2d3 d7d5 c2c4 g8f6 c4d5 f6d5
  4	0.00	2424	0:01.00	d2d3 d7d5 c2c4 g8f6 c4d5 f6d5
  4	-0.01	1324	0:01.00	e2e4 d7d5 e4d5 d8d5
  4	-0.03	1063	0:01.00	e2e3 d7d5 d2d4 g7g5
  3	+0.20	576	0:00.01	e2e3 d7d5 d2d4
  3	+0.20	386	0:00.00	e2e3 d7d5 d2d4
  3	+0.08	194	0:00.00	e2e4 d7d5 d2d3 d5e4 d3e4 d8d1 e1d1
  2	-0.01	102	0:00.00	e2e4 d7d5 e4d5 d8d5
  2	-0.01	44	0:00.00	e2e4 d7d5 e4d5 d8d5
  1	+0.28	21	0:00.00	e2e4
and in Fairy-Max

Code: Select all

  4	+0.11	3053	0:00.03	d2d4 d7d5 b1c3 b8c6
  4	+0.09	1394	0:00.02	g1f3 d7d5 d2d4 b8c6
  3	+0.26	677	0:00.00	g1f3 c7c5 c2c4
  3	+0.21	510	0:00.00	b1c3 c7c5 d2d4
  3	+0.18	352	0:00.00	f2f3 c7c5 c2c4
  2	+0.10	50	0:00.00	f2f3 c7c5
  2	+0.06	19	0:00.00	d2d3 c7c5
  1	+0.28	11	0:00.00	d2d3
mike_bike_kite
Posts: 98
Joined: Tue Jul 26, 2011 12:18 am
Location: London

Re: Simple extensions?

Post by mike_bike_kite »

I'm assuming the 1st ply should be 20 but you seem to show 21? do you include resigning as a possible move :) Your report also showed 44 for ply 2 which I don't understand, surely there are 20 moves for white and then 20 for black resulting in 20*20 nodes. I'm certain alpha beta won't knock this down to 44. I know I'm getting 420 nodes at ply 2 but I don't know the reason for this at the moment. The extensions were turned off in my code for this report.

The alphabeta figures were shown as AB and the MinMax as MM in the table above.
User avatar
hgm
Posts: 27809
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple extensions?

Post by hgm »

I count all nodes, also internal ones. The root is also a node.

The 44 is not the complete count after 2 ply, but the count after the PV move was searched. You can see there is a later d=2 output (with the same PV) at the end of the iteration, which reports 102 nodes. If the previous best move would have been overturned, there would have been outputs in between.

So for the remaining 19 first-ply moves, there were 58 nodes needed to search them. 19 to reach them, and then at the second ply 39 to refute them. That means on average only two moves of the 20 possible black replies had to be searched to produce a beta cutoff at ply 2.

I guess Joker does not reset the count between iterations, so the 44 includes the earlier reported 21, which means it took 23 nodes to search 1. e4. That is 1 to get there, and 20 for all possible black replies, plus two QS. After 1. e4 f5 there is probably no QS but a stand-pat cutoff, as f5 is bad enough in itself even if it would not give away the f-Pawn.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Simple extensions?

Post by tpetzke »

Hi Mike,

the ply 1 search reports 40 nodes because all nodes are processed twice, once as a normal horizon node and once as a top node in QS.

Thomas...