Some statistics about promotions and underpromotions.

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Some statistics about promotions and underpromotions.

Post by sje »

Likewise, there is no special marking for an en passant capture, or any kind of a drawing move.
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Some statistics about promotions and underpromotions.

Post by xmas79 »

EP moves are quite easy to detect:

black captures are always a pawn push in 4th rank followed by capture in 3rd rank in the same file. The same principle is for white:

Code: Select all

([abcdefgh])[4][ ]+[abcdefgh]x\1[3]    <--- black ep capture
([abcdefgh])[5][ ]+(\d+)\.[ ]+[abcdefgh]x\1[6] <--- white ep capture
Notice white ep capture is slightly different as there is the move number in between.

edit:
more compact version:

Code: Select all

([abcdefgh])4[ ]+[abcdefgh]x\13    <--- black ep capture
([abcdefgh])5[ ]+\d+\.[ ]+[abcdefgh]x\16 <--- white ep capture
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Some statistics about promotions and underpromotions.

Post by sje »

Won't work. There may be a capture of a different pawn on the same target rank but not file.
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Some statistics about promotions and underpromotions.

Post by xmas79 »

What? How? Still talking about chess? No ep capture... but if the file is the same then it is an ep capture.
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Some statistics about promotions and underpromotions.

Post by xmas79 »

Actually the problem is that this will tirgger false captures:

Code: Select all

([abcdefgh])4[ ]+[abcdefgh]x\13    <--- black ep capture 
([abcdefgh])5[ ]+\d+\.[ ]+[abcdefgh]x\16 <--- white ep capture 

eg: 4.Ng4 fxg3
eg: 4.h3 Ng5 5.fxg6
Solution is to ensure that the first move is actually a pawn move, so no piece or letter or number before destination square:

Code: Select all

\.[ ]*([abcdefgh])4[ ]+[abcdefgh]x\13    <--- black ep capture 
[ ]+([abcdefgh])5[ ]+\d+\.[ ]+[abcdefgh]x\16 <--- white ep capture
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Some statistics about promotions and underpromotions.

Post by sje »

xmas79 wrote:What? How? Still talking about chess? No ep capture... but if the file is the same then it is an ep capture.
[d]
Ba6 Bb5+ Bc4 Bd3 Be2 Ke2 Na3 Nc3 Ne2 Nf3 Nh3 Qe2 Qf3 Qg4 Qh5+ a3 a4 b3 b4 c3 c4 d3 d4 e6 exd6 exf6 f3 f4 g3 g4 h3 h4
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Some statistics about promotions and underpromotions.

Post by xmas79 »

sje wrote:
xmas79 wrote:What? How? Still talking about chess? No ep capture... but if the file is the same then it is an ep capture.
[d]
Ba6 Bb5+ Bc4 Bd3 Be2 Ke2 Na3 Nc3 Ne2 Nf3 Nh3 Qe2 Qf3 Qg4 Qh5+ a3 a4 b3 b4 c3 c4 d3 d4 e6 exd6 exf6 f3 f4 g3 g4 h3 h4
What? I repeat: a pawn push followed by a capture in the same file one rank "before". That is:

1.e4 a5 2.e5 d5 3.exd6

This is what my regex does.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Some statistics about promotions and underpromotions.

Post by sje »

Please show your regex as a grep call. Also, what about the case where the moves are separated by a newline?
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Some statistics about promotions and underpromotions.

Post by xmas79 »

Code: Select all

natale@ubuntu-develop:~$ echo -e "1.e4 h5 2.e5\n\n\n d5 3.   exd6 Nf6 \n \n \n 4.f4\n Ne4 5.f5 g5 6.fxg6 Nf6 7.b4 h4 8.b5 a6 9.Nf3 c5 10.bxa6" | sed ':a;N;$!ba;s/\n/ /g' | egrep -oh "([a-h])5[ ]+[0-9]+\.[ ]*[a-h]x\16" | wc -l
2

natale@ubuntu-develop:~$ echo -e "1.e4 h5 2.e5\n\n\n d5 3.   exd6 Nf6 \n \n \n 4.f4\n Ne4 5.f5 g5 6.fxg6 Nf6 7.b4 h4 8.b5 a6 9.Nf3 c5 10.bxa6" | sed ':a;N;$!ba;s/\n/ /g' | egrep -oh "([a-h])5[ ]+[0-9]+\.[ ]*[a-h]x\16"
d5 3.exd6
g5 6.fxg6

natale@ubuntu-develop:~$ echo -e "1.e4 h5 2.e5\n\n\n d5 3.   exd6 Nf6 \n \n \n 4.f4\n Ne4 5.f5 g5 6.fxg6 Nf6 7.b4 h4 8.b5 a6 9.Nf3 c5 10.bxc6" | sed ':a;N;$!ba;s/\n/ /g' | egrep -oh "([a-h])5[ ]+[0-9]+\.[ ]*[a-h]x\16" | wc -l
3

natale@ubuntu-develop:~$ echo -e "1.e4 h5 2.e5\n\n\n d5 3.   exd6 Nf6 \n \n \n 4.f4\n Ne4 5.f5 g5 6.fxg6 Nf6 7.b4 h4 8.b5 a6 9.Nf3 c5 10.bxc6" | sed ':a;N;$!ba;s/\n/ /g' | egrep -oh "([a-h])5[ ]+[0-9]+\.[ ]*[a-h]x\16"
d5 3.exd6
g5 6.fxg6
c5 10.bxc6
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Some statistics about promotions and underpromotions.

Post by sje »

After a certain point, command line operations for scanning a PGN file searching for certain moves or conditions become too ornate for practical use. Really, a database is needed for this.

For promotions in general, I am reminded of a chess variant seen from long ago where a player could promote a pawn only to a piece which had already been captured. The idea was to remove the need for having extra queens (or whatever) in the physical chess set. It is interesting to ponder how a chess program's search would have to be modified to adapt to this rule.

Today, many of the chess sets for sale (like the Mark of Westminster sets offered by Our Sponsor) have an extra pair of queens included. This practice was unheard of back in Old Days when I never had more than US$5 to spend on a set.