Moderator: Andres Valverde
Dieter B?r?ner wrote:Dan did you check it? I think, I do have a pretty fast move generator. I use it for testing legal moves. It is not optimal (in sense of efficiency). Parsing PGNs is more or less CPU bound here. The program will parse about 3.5 Mbyte/s. The disk is much faster. While I type this message, I see that the parsing uses 94% of the CPU time.
Peter Fendrich wrote: Don't take anything for granted!
tnesham wrote:If the PGN is from a ChessBase program, for example, why wouldn't I take it for granted that their PGN is clean?
Peter Fendrich wrote:My method:
...
/Peter
Alessandro Scotti wrote:
Because generating valid moves is so slow in my engine, I've had an idea: to parse a SAN move, I generate the list of pseudo-legal moves, and then only validate those that hit the destination square specified in the SAN move.
tnesham wrote:All this discussion on perfomance is interesting, but I have to challenge the "don't take anything for granted" rule. If the PGN is from a ChessBase program, for example, why wouldn't I take it for granted that their PGN is clean? I'd be willing to wager that their PGN is cleaner than my parser! I mean, they make their living doing that stuff, and I, well, don't.
If the user wants to modify their PGN, that's their risk. GIGO!
In databases there is the concept of optimistic versus pessimistic locking. Consider optimistic versus pessimistic PGN parsing, I will be happy with an optimistic parser. If I may define that as being one that takes a move as PGN text and assumes it is legal, then what is remaining is fairly trivial.
Dieter B?r?ner wrote:Yes, this is a good idea. I actually also thought of it, but nor really for PGN parsing but more important for validating moves from the hash table. This really shows up in profiles of Yace (which most often will have a move in he HT to validate, in case of upper bound and lower bound.) There one could expect a speedup of a factor like you saw at least. Unfortunately it is quite some work. It will duplicate quite some code (which is prone to errors) or will need quite some thinking to avoid the duplication (and still be efficient).
Dieter B?r?ner wrote:I don't use this idea. I of course thought about it, but decided against it. I estimated (after consulting profile outputs)it will at most speed up things by low digit percent. And it would make an already complicated function quite a bit more complicated. For the validation process things are a bit different. The complicated search function would stay untouched. Of course writing this special purpose move generator is not nice.
Perhaps I should try a more pragmatic approach, for validating hash moves (that is not correct in 100%, but only in say 98% of the cases - real collisions are very rare anyway, and they even don't matter much). I am not sure anymore, if Yace can crash, when an illegal move is in the PV (Yace adds the cutoff move from the HT to the PV). Sure, it can be handled at display time, too. I suspect, I am doing it twice already.
As you can see, this makes the optimization "don't generate moves soon, just try hash move first" not too trivial.
>In case of pgn-parsing, I think it should be possible to do without any
>move generation at all, in theory.
Perhaps yes, but not easy. Think of the case of to pieces of the same kind, that both can move to the same target. But one is pinned to the king. It sure can be done, but adding all this logic (and getting it perfectly correct) does not look like a nice job.
BTW. I have to agree with your "optimistic view" for the PGN cleanness, after rethinking it. It is like I started, too. Try to get the specs right, and then fix things, I found with various PGNs, or that got reported. Using an externaly tool for this fixing step would or course be appropriate, too.
Sune Fischer wrote:Yes you have to generate moves "backwards" using the to-square.
In Nf5 go to f5 and look at the knights attacks from f5. How many knights of the right color can be captured by a knight from f5 (this is often how attacks are done with bitboards). If we attack two knights then see if one of them is pinned etc...
Alessandro Scotti wrote:With bitboards, one usually has a enemyOrEmpty bitboard for masking off trivially illegal moves that target friendly pieces. I've got most of the benefits with just one line of code by and-ing that with the target square (if set). However, that wasn't much faster than generating the list of all pseudo legal moves and iterating to remove unwanted entries, I think the overall gain was less than 1% or so...
BTW in Kiwi I try to keep PGN stuff to a minimum because I don't think the PGN parser is so important in a chess engine. For a chess GUI or similar application of course having a robust PGN parser is much more important.
Ok, I suppose this is a simple PGN parsing:Dieter B?r?ner wrote:Peter, I read this several times, but I don't get it Is it only me? Can you say it in other words?
Cheers,
Dieter
while (grab_next_PGN_move(*currmove)){
if (IsMoveLegal(*currmove)) {
Update_position(*currmove); // Make the move and whatever
Position_id++; //I will explain this below
}
else
errorHandling();
}
Peter Fendrich wrote:Does all this make sense ?
/Peter
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 9 guests