0

I will try to explain what I want here:
-this is command I got from somebody in TCEC chat :

perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r])/!$1/g;print;" games.pgn>blackwon.pgn 

(this command working in Perl's command prompt)

I am using it to make all black moves "!"-signed in the database finished 0-1. Similar command is signing all white moves "!" in database contains games finished 1-0.

Similar command is this:

perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r])/?$1/g;print;" games.pgn>blacklost.pgn 

this signed all black moves "?" in every game in the whole database contains games finished 1-0.

And these commands are perfectly working with sign !!, !?, ?! and ?? too (only need to put them in the command line instead existing ! or ? sign).

I am using these "signed games" for make ctg.book.

But I tried ( unsuccessfully ) to get commands to put this sign ($18) or combination ($144 $40 for ex.) on the right place in the pgn.file. It is not same as commands about !,? signs because ($18) comes after extra space ahead move (white or black). Another problem is that $ is not simple letter/sign in Perl ( but a dollar sign ($) has some function).

Here is example what signs exist -

$18
$19
$16
$17
$14
$15
$11
$13
$36
$44
$32

Or a combination:

$144 $40

Like in the next game:

1. e4 $18 c6 $19 2. d4 $16 d5 $17 3. e5 $14 Bf5 $15 4. Nf3 $11 e6 $13 5. Be2 $36 Nd7 $44 6. O-O $144 $40 Ne7 $32 * 

And what we can to do about that? Can somebody very smart to make program to put this "sign" $18 in pgn games of whole database after every white move or after every black move or in same time after every white and black move?

Here is example game where did import sign $14 after every white move (but notice that after white move and sign $14 have space):

[Event "?"] 
[Site "?"] 
[Date "2018.04.11"] 
[Round "?"] 
[White "Bond"] 
[Black "Tor"] 
[Result "1/2-1/2"] 
[ECO "C88"] 
[Annotator "Top"] 
[PlyCount "26"] 
[SourceDate "2018.04.11"] 
[SourceVersionDate "2018.04.11"]

1. e4 $14 e5 2. Nf3 $14 Nc6 3. Bb5 $14 a6 
4. Ba4 $14 Nf6 5. O-O $14 Be7 6. Re1 $14 b5 
7. Bb3 $14 O-O 8. h3 $14 Bb7 9. d3 $14 d6 
10. a3 $14 Nb8 11. Nbd2 $14 Nbd7 12. Nf1 $14 Re8 
13. Ng3 $14 Bf8 1/2-1/2
darmar
  • 29
  • 4
  • White annotation: `perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r]\w+[ \t\n\r])/$1\$14 /g;print;" games.pgn>dollar14.pgn` Black annotation: `perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r][^ \t\n\r]+?[ \t\n\r][^ \t\n\r]+)/$1 \$18/g;print;" games.pgn>dollar18.pgn` [Demo](https://regex101.com/r/wu6SKZ/2) – wp78de Apr 11 '18 at 03:06
  • These are God's commands. People who think my question is unuseful know nothing about chess database, chess openbooks and many others thinks. In the answer of this great person you can learn how to substitute '$' a dollar sign like simple letter and functions of '^' and '\w+'. Thank you very much. I am going in [link](talkchess.com) to say everybody "we got the tool to change chess world" – darmar Apr 11 '18 at 03:42
  • @wp78de why did you delete the answer? It looked perfectly valid. The question is a bit odd, but in my opinion it has sample code, sample data, a description of the problem and attempt at solving it. It's a bit of an unusual domain that we don't see often here, but that's what makes this place fun imho. :) – simbabque Apr 11 '18 at 09:05
  • @simbabque well, it was down-voted. – wp78de Apr 11 '18 at 14:30
  • @wp78de I think that downvote came from someone who didn't believe this question should be answered. Don't let yourself be stopped from a single downvote. – simbabque Apr 11 '18 at 15:04

1 Answers1

0

The problem here is, the move no. with the dot is not the anchor for your rexep replacement. The second thing is, you have to escape the $ sign in replace pattern.

Try this:

perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r]\w+[ \t\n\r])/$1\$14 /g;print;" games.pgn>dollar14.pgn

Demo

In a similar fashion you can annotate the black moves:

perl -00 -ne "s/([ \t\n\r][0-9]+[.][ \t\n\r][^ \t\n\r]+?[ \t\n\r][^ \t\n\r]+)/$1 \$18/g;print;" games.pgn>dollar18.pgn

Demo2

wp78de
  • 18,207
  • 7
  • 43
  • 71
  • Thank you very much! Unbelievable it's working Please what is command line to sign every black moves with "$15" ? – darmar Apr 11 '18 at 01:55
  • @darmar sure thing. BTW: Why are you doing this? – wp78de Apr 11 '18 at 02:08
  • Command for black moves is signed every 2nd black move, not every black move. Something is wrong 1. c4 Nf6 2. g3 c5 $18 3. Bg2 Nc6 4. Nc3 g6 $18 5. Nf3 Bg7 6. O-O O-O 7. d4 d6 $18 8. d5 Na5 9. Nd2 a6 $18 10. Qc2 Rb8 11. b3 b5 $18 12. Rb1 e5 13. Bb2 Ne8 $18 14. e3 f5 15. Ne2 Bd7 $18 16. Nc1 Nf6 17. Nd3 e4 $18 18. Nf4 Qe7 19. h4 Ng4 $18 20. Rfc1 Bxb2 21. Qxb2 Ne5 $18 22. Qa3 Qd8 23. f3 exf3 $18 24. Nxf3 Ng4 25. Ng5 Qb6 $18 26. h5 gxh5 27. Bh3 bxc4 $18 28. Bxg4 hxg4 29. Qb2 Qd8 $18 30. Nge6 Qf6 31. Nxf8 Qxb2 $18 32. Rxb2 Kxf8 33. Rcb1 Rb5 $18 34. Kf2 Be8 35. Ne6+ Ke7 1/2-1/2 – darmar Apr 11 '18 at 02:17
  • I am using "signed" games for make open book ctg. format ( it ctg.book can works in Fritz chess program ) – darmar Apr 11 '18 at 02:27
  • 1
    I have split all games in 3 different database : 1. correspondence chess gamess (only players rating 2300+); 2. Playchess engine games - long time control ( 120 min, 180 min ); 3. Playchess engine games - blitz strongest players only And all these games are inported in the openbook ctg. format. I need different signed moves for every database because I can to know what move in the book is from which database. Correspondence moves are strongest, than long time control and bliz moves are weakest ... – darmar Apr 11 '18 at 02:43
  • Happy New Year . Please can you improve commands for white and black games? I will try to explain what the problem is for black moves signed games, http://prntscr.com/m2fcqf .First 7 moves are in same line but 8th move has 2 possibility: a) in the 1st line are number (8) and dot (.) but move (Bh4) is in the 2nd line (seems between exists Shift+Enter command and because black move didn't signed with ($15).; b) in end of 1st line is full 8th white move (8. d5) but in 2nd line black move isn't signed with sign ($15) because 'Split line downwards' exits there – darmar Jan 03 '19 at 04:39
  • Similarly for white moves: http://prntscr.com/m2fclj , in the 1st line is "8." and in the 2nd line is "f3" which isn't signed because between them exists 'Shift+Enter' command or 'Split line downwards'. Can you include 'Split line downwards' in commands ? – darmar Jan 03 '19 at 04:47
  • Ahhh I see every move in new line isn't signed. I believe it's easy to improve commands to sign all moves. Here is picture and there are some CR LF characters http://prntscr.com/m2g11w – darmar Jan 03 '19 at 05:52