def test_BlindBoard_changes(): '''Test BlindBoard editing methods''' board = BlindBoard.from_dict({chess.A1: WHITE, chess.B2: WHITE}) board.move_piece(chess.A1, chess.D5) board.change_color_at(chess.B2) nose.tools.eq_(board, BlindBoard.from_dict({chess.D5: WHITE, chess.B2: BLACK}))
def test_BlindBoard_changes(): '''Test BlindBoard editing methods''' board = BlindBoard.from_dict({chess.A1: WHITE, chess.B2: WHITE}) board.move_piece(chess.A1, chess.D5) board.change_color_at(chess.B2) nose.tools.eq_(board, BlindBoard.from_dict({ chess.D5: WHITE, chess.B2: BLACK }))
def test_BlindBoard_identical(): '''Diff 2 identical BlindBoards and check the result''' board_from = BlindBoard.from_dict({chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE}) board_to = BlindBoard.from_dict({chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE}) diff = board_to.diff(board_from) nose.tools.ok_(not diff.emptied) nose.tools.ok_(not diff.filled) nose.tools.ok_(not diff.changed)
def test_take_move_diff(self): '''Test take move deduction''' board_1 = BlindBoard.from_dict({ chess.E2: WHITE, chess.F2: BLACK, }) board_2 = BlindBoard.from_dict({ chess.F2: WHITE, }) diff = BlindBoard.diff_board(board_2, board_1) move = core.diffreader.read(diff) expected_move = Move(chess.E2, chess.F2) nose.tools.eq_(move, expected_move)
def test_take_move_diff(self): '''Test take move deduction''' board_1 = BlindBoard.from_dict( { chess.E2: WHITE, chess.F2: BLACK, }) board_2 = BlindBoard.from_dict( { chess.F2: WHITE, }) diff = BlindBoard.diff_board(board_2, board_1) move = core.diffreader.read(diff) expected_move = Move(chess.E2, chess.F2) nose.tools.eq_(move, expected_move)
def test_BlindBoard_moves(): '''Diff 2 BlinBoards and check the result''' board_from = BlindBoard.from_dict({chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE}) board_to = BlindBoard.from_dict({chess.A1: WHITE, chess.A7: BLACK, chess.A8: WHITE, chess.E4: WHITE}) diff = board_to.diff(board_from) nose.tools.eq_(diff.emptied, chess.BB_E2) nose.tools.eq_(diff.filled, chess.BB_E4) nose.tools.eq_(diff.changed, chess.BB_A8) nose.tools.eq_(diff.__str__(), "emptied:{'e2'} filled:{'e4'} changed:{'a8'}")
def test_queen_castling_move_diff(self): '''Test queen castling move deduction''' board_1 = BlindBoard.from_dict({ chess.E8: BLACK, chess.A8: BLACK, }) board_2 = BlindBoard.from_dict({ chess.D8: BLACK, chess.C8: BLACK, }) diff = BlindBoard.diff_board(board_2, board_1) move = core.diffreader.read(diff) expected_move = Move(chess.E8, chess.C8) nose.tools.eq_(move, expected_move)
def test_king_castling_move_diff(self): '''Test king castling move deduction''' board_1 = BlindBoard.from_dict({ chess.H1: WHITE, chess.E1: WHITE, }) board_2 = BlindBoard.from_dict({ chess.F1: WHITE, chess.G1: WHITE, }) diff = BlindBoard.diff_board(board_2, board_1) move = core.diffreader.read(diff) expected_move = Move(chess.E1, chess.G1) nose.tools.eq_(move, expected_move)
def test_king_castling_move_diff(self): '''Test king castling move deduction''' board_1 = BlindBoard.from_dict( { chess.H1: WHITE, chess.E1: WHITE, }) board_2 = BlindBoard.from_dict( { chess.F1: WHITE, chess.G1: WHITE, }) diff = BlindBoard.diff_board(board_2, board_1) move = core.diffreader.read(diff) expected_move = Move(chess.E1, chess.G1) nose.tools.eq_(move, expected_move)
def test_BlindBoard_identical(): '''Diff 2 identical BlindBoards and check the result''' board_from = BlindBoard.from_dict({ chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE }) board_to = BlindBoard.from_dict({ chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE }) diff = board_to.diff(board_from) nose.tools.ok_(not diff.emptied) nose.tools.ok_(not diff.filled) nose.tools.ok_(not diff.changed)
def test_BlindBoard_moves(): '''Diff 2 BlinBoards and check the result''' board_from = BlindBoard.from_dict({ chess.A1: WHITE, chess.A7: BLACK, chess.A8: BLACK, chess.E2: WHITE }) board_to = BlindBoard.from_dict({ chess.A1: WHITE, chess.A7: BLACK, chess.A8: WHITE, chess.E4: WHITE }) diff = board_to.diff(board_from) nose.tools.eq_(diff.emptied, chess.BB_E2) nose.tools.eq_(diff.filled, chess.BB_E4) nose.tools.eq_(diff.changed, chess.BB_A8) nose.tools.eq_(diff.__str__(), "emptied:{'e2'} filled:{'e4'} changed:{'a8'}")
def get_blindboard(self): """ Converts the numpy array `_blindboard_matrix` into a BlindBoard object """ if self._blindboard_matrix is None: raise ImageProcessorException( "The `.process` method has not been called on this object yet") occupied_squares = {} for (i, j), entry in np.ndenumerate(self._blindboard_matrix): col = j ; row = 7-i if entry is not None: occupied_squares[chess.square(col, row)] = bool(entry) return BlindBoard.from_dict(occupied_squares)
def get_blindboard(self): """ Converts the numpy array `_blindboard_matrix` into a BlindBoard object """ if self._blindboard_matrix is None: raise ImageProcessorException( "The `.process` method has not been called on this object yet") occupied_squares = {} for (i, j), entry in np.ndenumerate(self._blindboard_matrix): col = j row = 7 - i if entry is not None: occupied_squares[chess.square(col, row)] = bool(entry) return BlindBoard.from_dict(occupied_squares)