File: fen2gnu.c

package info (click to toggle)
gnuchess 4.0.pl79-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,976 kB
  • ctags: 1,335
  • sloc: ansic: 14,583; sh: 453; makefile: 379; csh: 29
file content (97 lines) | stat: -rw-r--r-- 2,160 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <strings.h>
/* convert fen notation to gnu save format */
char            b[8][8];
char            fn[12],*color;
int             i, j, k, l;
int             r, c;
int		eps;
char           *p, *q;
FILE           *F, *O;
int             wq, wk, bq, bk;
char            in[128];
/*						*/
/*		fen2gnu fen-file > outfile 	*/
/* 						*/
main(argc,argv)
int argc;
char *argv[];
{
	k = 1;
	F = fopen(argv[1], "r");
	while (fgets(in, 128, F) != NULL) {
		if (strncmp("svfe", in, 4) == 0) {
			wq = wk = bq = bk = 10;
			for (i = 0; i < 8; i++) {
				for (j = 0; j < 8; j++) {
					b[i][j] = '.';
				}
			}
			p = &in[5];
			r = 0;
			c = 0;
			while (*p != ' ') {
				if (isdigit(*p)) {
					c += (*p - '0');
				} else if (*p == '/') {
					r++;
					c = 0;
				} else {
					if(isupper(*p))*p = tolower(*p);
					else *p = toupper(*p);
					b[r][c] = *p;
					c++;
				}
				p++;

			}
			p++;
			if(*p == 'W') color = "White"; else color = "Black";
			p += 2;
			if (*p == 'K') {
				wk = 0;
				p++;
			}
			if (*p == 'Q') {
				wq = 0;
				p++;
			}
			if (*p == 'k') {
				bk = 0;
				p++;
			}
			if (*p == 'q') {
				bq = 0;
				p++;
			}
			while (*p != ' ')
				p++;
			p++;
			q = p;
			while (*q != ' ')
				q++;
			*q = '\0';
			if(*p == 'n')eps = -1; else eps = (*p -'a')*8 + *(p+1)-'0';

		} else if (strncmp("srch", in, 4) == 0) {
			sprintf(fn, "bk%03d", k);
			k++;
			O = fopen(fn, "w");
			fprintf(O, "White computer Black Human 1 eps %d # To move %s correct move %sCastled White false Black false # ep %s\nTimeControl 0 Operator Time 0\nWhite Clock 0000 Moves 0\nBlack Clock 0000 Moves 0\n\n", eps,color,&in[5], p);
			for (r = 0; r < 8; r++) {
				fprintf(O, "%c ", '0' + r);
				for (c = 0; c < 8; c++) {
					fprintf(O, "%c", b[r][c]);
				}
				if (r == 0)
					fprintf(O, " %d 10 10 10 %d 10 10 %d\n", bq, ((bq + bk) > 10) ? 10 : 0, bk);
				else if (r == 7)
					fprintf(O, " %d 10 10 10 %d 10 10 %d\n", wq, ((wq + wk) > 10) ? 10 : 0, wk);
				else
					fprintf(O, " 10 10 10 10 10 10 10 10\n");
			}
			fprintf(O, "  abcdefgh\n\nmove  score depth  nodes  time flags capture color\n");
			fclose(O);
		}
	}
}