How do you organize your program to avoid writing similiar code often?
I want to have function to calculate different informations about pgn files.
The problem is that I do not like to write the same code number of times and today I need to do it(the situation now is better than the situation in the past but still not ideal and I will be happy to get some good advise how to organize my program better)
Here are the functions that I use now to calculate sum of perft.
The problem is that if I want to write a function to calculate the sum of passed pawns that I have in the pgn file based on function that calculate the number of passed pawn in specific position I will need similiar code that is the same except the fact that instead of perft I use a different function and instead of sumperftpgn I will have sum_passed_pawn_pgn.
void calc_sum_perft(char *gamesname,int i)
{
int m;
BitBoard sumperftpgn=0;
if (i<1)
return;
setup("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
m=get_next_move_in_pgn();
while (m>0)
{
sumperftpgn+=perft(i-1);
makemove(m);
m=get_next_move_in_pgn();
}
printf("perft=%I64u \n",sumperftpgn);
}
void perftpgn(char *gamesname,int depth)
{
if (startpgn(gamesname))
calc_sum_perft(gamesname,depth);
}