-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.c
118 lines (79 loc) · 2.32 KB
/
io.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
// io.c
#include "stdio.h"
#include "defs.h"
char *PrSq(const int sq) {
static char SqStr[3];
int file = FilesBrd[sq];
int rank = RanksBrd[sq];
sprintf(SqStr, "%c%c", ('a'+file), ('1'+rank));
return SqStr;
}
char *PrMove(const int move) {
static char MvStr[6];
int ff = FilesBrd[FROMSQ(move)];
int rf = RanksBrd[FROMSQ(move)];
int ft = FilesBrd[TOSQ(move)];
int rt = RanksBrd[TOSQ(move)];
int promoted = PROMOTED(move);
if(promoted) {
char pchar = 'q';
if(IsKn(promoted)) {
pchar = 'n';
} else if(IsRQ(promoted) && !IsBQ(promoted)) {
pchar = 'r';
} else if(!IsRQ(promoted) && IsBQ(promoted)) {
pchar = 'b';
}
sprintf(MvStr, "%c%c%c%c%c", ('a'+ff), ('1'+rf), ('a'+ft), ('1'+rt), pchar);
} else {
sprintf(MvStr, "%c%c%c%c", ('a'+ff), ('1'+rf), ('a'+ft), ('1'+rt));
}
return MvStr;
}
int ParseMove(char *ptrChar, S_BOARD *pos) {
ASSERT(CheckBoard(pos));
if(ptrChar[1] > '8' || ptrChar[1] < '1') return NOMOVE;
if(ptrChar[3] > '8' || ptrChar[3] < '1') return NOMOVE;
if(ptrChar[0] > 'h' || ptrChar[0] < 'a') return NOMOVE;
if(ptrChar[2] > 'h' || ptrChar[2] < 'a') return NOMOVE;
int from = FR2SQ(ptrChar[0] - 'a', ptrChar[1] - '1');
int to = FR2SQ(ptrChar[2] - 'a', ptrChar[3] - '1');
ASSERT(SqOnBoard(from) && SqOnBoard(to));
S_MOVELIST list[1];
GenerateAllMoves(pos,list);
int MoveNum = 0;
int Move = 0;
int PromPce = EMPTY;
for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
Move = list->moves[MoveNum].move;
if(FROMSQ(Move)==from && TOSQ(Move)==to) {
PromPce = PROMOTED(Move);
if(PromPce!=EMPTY) {
if(IsRQ(PromPce) && !IsBQ(PromPce) && ptrChar[4]=='r') {
return Move;
} else if(!IsRQ(PromPce) && IsBQ(PromPce) && ptrChar[4]=='b') {
return Move;
} else if(IsRQ(PromPce) && IsBQ(PromPce) && ptrChar[4]=='q') {
return Move;
} else if(IsKn(PromPce)&& ptrChar[4]=='n') {
return Move;
}
continue;
}
return Move;
}
}
return NOMOVE;
}
void PrintMoveList(const S_MOVELIST *list) {
int index = 0;
int score = 0;
int move = 0;
printf("MoveList:\n");
for(index = 0; index < list->count; ++index) {
move = list->moves[index].move;
score = list->moves[index].score;
printf("Move:%d > %s (score:%d)\n",index+1,PrMove(move),score);
}
printf("MoveList Total %d Moves:\n\n",list->count);
}