-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_board_to_encoding.py
55 lines (42 loc) · 1.47 KB
/
game_board_to_encoding.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
# Script to convert an a human readable board into an encoded gamestate. Just enter the encoded
# gamestate and run the script.
#
# To not track changes of this file in your git: git update-index --assume-unchanged game_board_to_encoding.py
# To revert the above: git update-index --no-assume-unchanged game_board_to_encoding.py
# Enter the gamestate of the board to be encoded here
game_board ="""
O O O O O O O
O O O O O O O
O O O O O O O
O O O O O O O
O O O O O O O
O O O O O O O
"""
if __name__ == '__main__':
res = 0
row_counter = 1
column_counter = 1
# Loop through the string and add encoding number (see gamestate_helpers.rs) to res if current
# char is valid Letter
for i in range(len(game_board)):
was_letter = True
# Check if current char is valid letter
match game_board[i]:
case 'O':
res += 0
case 'B':
res += pow(2, 14 * (row_counter - 1) + 2 * (column_counter - 1))
case 'R':
res += pow(2, 14 * (row_counter - 1) + 2 * (column_counter - 1)) * 2
case other:
was_letter = False
if(was_letter):
if column_counter == 7:
column_counter = 1
row_counter += 1
else:
column_counter += 1
print("Full board of that encoding is:")
print(res + (res * 2))
print("Encoding of given gamestate is:")
print(res)