-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtils.cpp
64 lines (58 loc) · 1.08 KB
/
Utils.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
#include <string.h>
#include "Checkers.h"
unsigned Map_45_to_64[] =
{
0, 0, 0, 0, 0,
1, 3, 5, 7,
8, 10, 12, 14, 0,
17, 19, 21, 23,
24, 26, 28, 30, 0,
33, 35, 37, 39,
40, 42, 44, 46, 0,
49, 51, 53, 55,
56, 58, 60, 62
};
void SquareToStr(unsigned sq, char *s)
{
sq = Map_45_to_64[sq];
s[0] = sq % 8 + 'a';
s[1] = 8 - sq / 8 + '0';
s[2] = 0;
}
void MoveToStr(Move *m, char *s)
{
unsigned i;
SquareToStr(m->from, s);
for (i = 0; m->cap_sq[i]; i++)
{
s[i * 3 + 2] = ':';
SquareToStr(m->cap_sq[i], s + i * 3 + 3);
}
if (m->cap_sq[0])
{
s[i * 3 + 2] = ':';
SquareToStr(m->to, s + i * 3 + 3);
} else SquareToStr(m->to, s + 2);
}
unsigned StrToSquare(char *sq)
{
return Map_64_to_45[sq[0] - 'a' + 8 * ('8' - sq[1])];
}
void StrToMove(char *s, Move *m)
{
char str_move[128];
MP = MoveBuffer;
GenerateAllMoves();
for (Move *pm = MoveBuffer; pm != MP; pm++)
{
MoveToStr(pm, str_move);
if (!strcmp(str_move, s))
{
*m = *pm;
MP = MoveBuffer;
return;
}
}
MP = MoveBuffer;
m->from = 0;
}