forked from stevemaughan/maverick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.cpp
184 lines (164 loc) · 4.06 KB
/
write.cpp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//===========================================================//
//
// Maverick Chess Engine
// Copyright 2013 Steve Maughan
//
//===========================================================//
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <Windows.h>
#include "defs.h"
#include "data.h"
#include "procs.h"
#include "bittwiddle.h"
void write_board(struct t_board *board, char filename[1024])
{
FILE *tfile = NULL;
int i, r, c;
char s[1000];
r = 7;
c = 0;
i = 1;
tfile = fopen(filename, "w");
while (i >= 0)
{
i = (8 * r) + c;
switch (board->square[i])
{
case BLANK :
fprintf(tfile,". ");
break;
case WHITEPAWN :
fprintf(tfile,"P ");
break;
case WHITEKNIGHT :
fprintf(tfile,"N ");
break;
case WHITEBISHOP :
fprintf(tfile,"B ");
break;
case WHITEROOK :
fprintf(tfile,"R ");
break;
case WHITEQUEEN :
fprintf(tfile,"Q ");
break;
case WHITEKING :
fprintf(tfile,"K ");
break;
case BLACKPAWN :
fprintf(tfile,"p ");
break;
case BLACKKNIGHT :
fprintf(tfile,"n ");
break;
case BLACKBISHOP :
fprintf(tfile,"b ");
break;
case BLACKROOK :
fprintf(tfile,"r ");
break;
case BLACKQUEEN :
fprintf(tfile,"q ");
break;
case BLACKKING :
fprintf(tfile,"k ");
break;
}
c++;
if (c > 7)
{
c = 0;
r--;
i = (8 * r) + c;
fprintf(tfile,"\n");
}
}
//-- FEN
strcpy(s, get_fen(board));
fprintf(tfile, s);
fprintf(tfile, "\n");
//-- To Move
if (board->to_move == WHITE)
strcpy(s, "White to move");
else
strcpy(s, "Black to move");
fprintf(tfile, s);
fprintf(tfile, "\n");
//-- In Check
if (board->in_check) {
strcpy(s, "In check!");
fprintf(tfile, s);
fprintf(tfile, "\n");
}
//-- Board Hash
sprintf(s, "Hash = %llu \n", board->hash);
fprintf(tfile, s);
fclose(tfile);
}
void write_move_list(struct t_move_list *move_list, char filename[1024])
{
FILE *tfile = NULL;
int i;
char s[20];
tfile = fopen(filename, "w");
for (i = 0; i < move_list->count; i++) {
sprintf(s, "%d. %s = %lld", i, move_as_str(move_list->move[i]), move_list->value[i]);
fprintf(tfile, s);
//fprintf(tfile," ");
//fprintf(tfile,"%I64d", move_list->value[i]);
fprintf(tfile,"\n");
}
fclose(tfile);
}
void write_path(struct t_board *board, int ply, char filename[1024]) {
FILE *tfile = NULL;
int i;
char s[10];
tfile = fopen(filename, "w");
for (i = 0; i < ply; i++) {
strcpy(s, move_as_str(board->pv_data[i].current_move));
fprintf(tfile, s);
fprintf(tfile, "\n");
}
fclose(tfile);
}
void write_tree(struct t_board *board, struct t_move_record *move, BOOL append, char filename[1024]) {
FILE *tfile = NULL;
static int i;
char s[UCI_BUFFER_SIZE];
if (append) {
tfile = fopen(filename, "a");
sprintf(s, "%d, %s, ""%llu"", %s", ++i, get_fen(board), board->hash, move_as_str(move));
fprintf(tfile, s);
fprintf(tfile, "\n");
}
else {
i = 0;
tfile = fopen(filename, "w");
strcpy(s, "Maverick Tree File");
fprintf(tfile, s);
fprintf(tfile, "\n");
}
fclose(tfile);
}
void write_log(char *s, char *filename, BOOL append, BOOL send)
{
FILE *tfile = NULL;
char t[UCI_BUFFER_SIZE];
if (append) {
tfile = fopen(filename, "a");
}
else {
tfile = fopen(filename, "w");
}
if (send)
sprintf(t, "Sent >> %s", s);
else
sprintf(t, "Received >> %s", s);
fprintf(tfile, t);
fprintf(tfile, "\n");
fclose(tfile);
}