Skip to content

Commit

Permalink
Add test and fix repetition layers
Browse files Browse the repository at this point in the history
  • Loading branch information
joshheinrichs committed Nov 14, 2020
1 parent 58922c5 commit b8ac4c0
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/data_utils/layer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def board_to_layers(board, turn):
board_layers.append(layer)

for i in range(REPETITIONS):
if board.is_repetition(i + 1):
if board.is_repetition(i + 2):
board_layers.append(np.ones(SIZE))
else:
board_layers.append(np.zeros(SIZE))
Expand Down Expand Up @@ -106,8 +106,8 @@ def game_to_layers(game):
print('turn: %s' % i)
print('color: %s' % ('white' if meta_layers.meta.turn == chess.WHITE else 'black'))
print('next move: %s' % (meta_layers.meta.next_move))
print(meta_layers.layers[0])
print(meta_layers.layers[6])
print(meta_layers.layers)
# print(meta_layers.layers[6])
print(meta_layers.layers.shape)
if i == 2:
break
Expand Down
Empty file added src/data_utils/test/__init__.py
Empty file.
137 changes: 137 additions & 0 deletions src/data_utils/test/test_layer_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import numpy as np
import chess

from data_utils.layer_builder import board_to_layers


def test_board_to_layers():
board = chess.Board()
expected = [np.array(a, dtype=np.uint8) for a in [
[
[0,0,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
],
[
[0,1,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
],
[
[0,0,1,0,0,1,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],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0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[1,0,0,0,0,0,0,1],
],
[
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0],
],
[
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0],
],
]]
expected.extend((
np.zeros((8,8)),
np.zeros((8,8))
))
actual = board_to_layers(board, chess.WHITE)

np.testing.assert_array_equal(expected, actual)

0 comments on commit b8ac4c0

Please sign in to comment.