-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_sorter.py
61 lines (52 loc) · 2.15 KB
/
data_sorter.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
""" This is meant to simplify our dictionaries, and separate them into black and white
datasets."""
import pickle
def process_file(filename, Giant_White_Dataset, Giant_Black_Dataset):
print "Processing File: " + filename
try:
f = open(filename, 'r')
board_dictionary = pickle.load(f)
f.close()
except EOFError:
return Giant_White_Dataset, Giant_Black_Dataset
for board_state in board_dictionary:
move_dict = board_dictionary[board_state]
if board_state[1] == True: #Checks to see if it's a board that White moves on
if board_state[0] not in Giant_White_Dataset:
Giant_White_Dataset[board_state[0]] = move_dict
else:
for move in move_dict:
if move in Giant_White_Dataset[board_state[0]]:
#Updates the [win, loss, draw] results of a move for a given board
Giant_White_Dataset[board_state[0]][move][0] += move_dict[move][0]
Giant_White_Dataset[board_state[0]][move][1] += move_dict[move][1]
Giant_White_Dataset[board_state[0]][move][2] += move_dict[move][2]
else:
Giant_White_Dataset[board_state[0]][move] = move_dict[move]
else:
if board_state[0] not in Giant_Black_Dataset:
Giant_Black_Dataset[board_state[0]] = move_dict
else:
for move in move_dict:
if move in Giant_Black_Dataset[board_state[0]]:
#Updates the [win, loss, draw] results of a move for a given board
Giant_Black_Dataset[board_state[0]][move][0] += move_dict[move][0]
Giant_Black_Dataset[board_state[0]][move][1] += move_dict[move][1]
Giant_Black_Dataset[board_state[0]][move][2] += move_dict[move][2]
else:
Giant_Black_Dataset[board_state[0]][move] = move_dict[move]
return Giant_White_Dataset, Giant_Black_Dataset
if __name__ == '__main__':
file_list = []
for i in range(1999,2013):
file_list.append(str(i) + '_data.txt')
Giant_White_Dataset = {}
Giant_Black_Dataset = {}
for filename in file_list:
Giant_White_Dataset, Giant_Black_Dataset = process_file(filename, Giant_White_Dataset, Giant_Black_Dataset)
f = open('Giant_Black_Dataset.txt', 'w')
pickle.dump(Giant_Black_Dataset, f)
f.close()
f = open('Giant_White_Dataset.txt', 'w')
pickle.dump(Giant_White_Dataset, f)
f.close()