-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitboard.c
82 lines (75 loc) · 2.51 KB
/
bitboard.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
#include <stdio.h>
#include <stdlib.h>
#include "global_const.h"
// square(0~24) を bitboard に変換
BitBoard bitboard(int square)
{
return 1 << square;
}
// 以下の関数は square の位置にある駒の動ける場所を表す bitboard を返す(他の駒との衝突はここでは無視)
BitBoard generate_FU_movable(int square)
{
if (square >= 20) return 0;
return bitboard(square + 5);
}
BitBoard generate_KI_movable(int square)
{
BitBoard res = 0;
int row = square / 5, col = square % 5;
if (row >= 1) res |= bitboard(square - 5);
if (row <= 3) res |= bitboard(square + 5);
if (col >= 1) res |= bitboard(square - 1);
if (col <= 3) res |= bitboard(square + 1);
if (row <= 3 && col >= 1) res |= bitboard(square + 4);
if (row <= 3 && col <= 3) res |= bitboard(square + 6);
return res;
}
BitBoard generate_GI_movable(int square)
{
BitBoard res = 0;
int row = square / 5, col = square % 5;
if (row <= 3) res |= bitboard(square + 5);
if (row >= 1 && col >= 1) res |= bitboard(square - 6);
if (row >= 1 && col <= 3) res |= bitboard(square - 4);
if (row <= 3 && col >= 1) res |= bitboard(square + 4);
if (row <= 3 && col <= 3) res |= bitboard(square + 6);
return res;
}
BitBoard generate_OU_movable(int square)
{
BitBoard res = 0;
int row = square / 5, col = square % 5;
if (row >= 1) res |= bitboard(square - 5);
if (row <= 3) res |= bitboard(square + 5);
if (col >= 1) res |= bitboard(square - 1);
if (col <= 3) res |= bitboard(square + 1);
if (row >= 1 && col >= 1) res |= bitboard(square - 6);
if (row >= 1 && col <= 3) res |= bitboard(square - 4);
if (row <= 3 && col >= 1) res |= bitboard(square + 4);
if (row <= 3 && col <= 3) res |= bitboard(square + 6);
return res;
}
int main()
{
printf("const int FU_movable[25] = { \n\t");
for (int square = 0; square < 25; square++) {
printf("%d, ", generate_FU_movable(square));
}
printf("\n};\n");
printf("const int KI_movable[25] = { \n\t");
for (int square = 0; square < 25; square++) {
printf("%d, ", generate_KI_movable(square));
}
printf("\n};\n");
printf("const int GI_movable[25] = { \n\t");
for (int square = 0; square < 25; square++) {
printf("%d, ", generate_GI_movable(square));
}
printf("\n};\n");
printf("const int OU_movable[25] = { \n\t");
for (int square = 0; square < 25; square++) {
printf("%d, ", generate_OU_movable(square));
}
printf("\n};\n");
return 0;
}