-
Notifications
You must be signed in to change notification settings - Fork 0
/
hybrid_output.py
68 lines (43 loc) · 1.58 KB
/
hybrid_output.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
62
63
64
65
66
67
68
import os
import numpy
import uuid
line = "========================================"
block = '<>'
output_directory = "out"
if not os.path.exists(output_directory):
os.makedirs(output_directory)
logging_id = str(uuid.uuid4())
os.makedirs(output_directory + "/" + logging_id)
def open_debug():
return open(output_directory + "/" + logging_id + "/debug.txt", 'a')
def open_log():
return open(output_directory + "/" + logging_id + "/out.txt", 'a')
def open_weights():
return open(output_directory + "/" + logging_id + "/weights.txt", 'w')
output = open_log()
debug_output = open_debug()
def game_to_log_message(name, game):
game_as_string = line + '\n'
for row in game.board:
game_as_string += convert_array_to_blocks(row) + '\n'
game_as_string += line
message = name + " = \n"
return message + game_as_string + "\n"
def debug(message, target_object=""):
_write(message, target_object, debug_output)
print(message, target_object)
def out(message, target_object=""):
_write(message, target_object, output)
_write(message, target_object, debug_output)
print(message, target_object)
def weights(weights):
numpy.set_printoptions(threshold=numpy.nan)
_write("", weights, open_weights())
def _write(message, target_object, log_file):
log_message = message + str(target_object) + "\n"
log_file.write(log_message)
log_file.flush()
def convert_array_to_blocks(array):
return str(array).replace('0', ' ').replace(',', ' ').replace('1', block)
def remove_square_brackets(input_string):
return input_string.strip('[]')