forked from zaphodgjd/class-chess-123
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrecomputeDist.py
42 lines (33 loc) · 962 Bytes
/
PrecomputeDist.py
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
import math
def calculate_distances():
distances = []
for square in range(64):
y = square // 8
x = square - y * 8
north = 7 - y
south = y
west = x
east = 7 - x
dist = [0] * 8
dist[0] = north
dist[1] = east
dist[2] = south
dist[3] = west
dist[4] = min(north, east)
dist[5] = min(south, east)
dist[6] = min(south, west)
dist[7] = min(north, west)
distances.append((square, dist))
return distances
def write_to_file(filename, distances):
with open(filename, 'w') as file:
file.write("int _dist[64][8] = {\n")
for i, dist in distances:
dist_str = ', '.join(map(str, dist))
file.write(f" {{ {dist_str} }},\n")
file.write("};\n")
def main():
distances = calculate_distances()
write_to_file("distances.cpp", distances)
if __name__ == "__main__":
main()