-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessLog.c
163 lines (145 loc) · 3.19 KB
/
ChessLog.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ChessLog.h"
void WriteLog(int piece[], char start[][3], char end[][3], int capture[], int special[])
{
FILE *f;
int j,i;
int turn = 1;
f = fopen("log.txt", "w+");
if(f == NULL)
{
printf("Error creating file!");
exit(10);
}
fprintf(f, "============================================================================================================\n");
fprintf(f, "| Turn\t\tPlayer\t\tPiece\t\tStart\t\tEnd\t\tCapture\t\tSpecial |\n|==========================================================================================================|\n");
for(j = 0; j < 300; j++)
{
if(piece[j] == 0)
break;
if(j % 2 == 0 || j == 0)
{
if(j != 0)
{
fprintf(f, "|----------------------------------------------------------------------------------------------------------|\n");
}
fprintf(f, "| %d.\t\t", turn);
turn++;
}/*end if:seperation line*/
else
fprintf(f, "|\t\t");
/* Prints out the player and the piece */
switch(piece[j])
{
case 1:
fprintf(f, "W\t\tPawn\t\t");
break;
case -1:
fprintf(f, "B\t\tPawn\t\t");
break;
case 2:
fprintf(f, "W\t\tKnight\t\t");
break;
case -2:
fprintf(f, "B\t\tKnight\t\t");
break;
case 3:
fprintf(f, "W\t\tBishop\t\t");
break;
case -3:
fprintf(f, "B\t\tBishop\t\t");
break;
case 4:
fprintf(f, "W\t\tRook\t\t");
break;
case -4:
fprintf(f, "B\t\tRook\t\t");
break;
case 5:
fprintf(f, "W\t\tQueen\t\t");
break;
case -5:
fprintf(f, "B\t\tQueen\t\t");
break;
case 6:
fprintf(f, "W\t\tKing\t\t");
break;
case -6:
fprintf(f, "B\t\tKing\t\t");
break;
default:
fprintf(f, "ERROR");
break;
}/*end switch:player piece*/
/* prints the start and end positions */
for(i = 0; i<4; i++){
if(i < 2){
fprintf(f, "%c", start[j][i]);
}
else{
fprintf(f, "%c", end[j][i-2]);
}
if(i == 1 || i == 3)
fprintf(f, "\t\t");
/*fprintf(f, "%s\t\t%s\t\t", &start[j], &end[j]);*/
}
/* prints out if a piece was captured */
switch(capture[j])
{
case 0:
fprintf(f, "\t\t");
break;
case 1:
case -1:
fprintf(f, "Pawn\t\t");
break;
case 2:
case -2:
fprintf(f, "Knight\t\t");
break;
case 3:
case -3:
fprintf(f, "Bishop\t\t");
break;
case 4:
case -4:
fprintf(f, "Rook\t\t");
break;
case 5:
case -5:
fprintf(f, "Queen\t\t");
break;
case 6:
case -6:
fprintf(f, "King\t\t");
break;
default:
fprintf(f, "ERROR");
break;
}/*end switch: piece capture*/
/* prints out the special moves */
switch(special[j])
{
case 0:
fprintf(f, "\t |\n");
break;
case 1:
fprintf(f, "Castling |\n");
break;
case 2:
fprintf(f, "En Passant |\n");
break;
default:
fprintf(f, "ERROR");
break;
}
}/*end for:go through arrays*/
fprintf(f, "============================================================================================================");
fclose(f);
}/*end Write Chess Log*/
/*Delete Lines for undo*/
void DeleteLines()
{
}/*end Delete line */