def test_Piece_movement(): board = Board(20) w1 = Piece('white',[5,2],board) w1.move_to([4,3]) assert w1.x == 4 assert w1.y == 3 assert w1.position == [4,3]
def test_is_peaceable(): board = Board(10) w1 = Piece('white', [5, 2], board) b1 = Piece('black', [9, 3], board) assert metrics.is_peaceable(board) b2 = Piece('black', [7, 4], board) assert not metrics.is_peaceable(board)
def test_board(): board0 = Board([8, 15]) assert board0.shape == [8, 15] assert board0.grid.shape == (8, 15, 2) assert np.sum(board0.grid) == 0 board1 = Board(10) assert board1.shape == [10, 10] assert board1.black_pieces == [] assert board1.white_pieces == [] assert board1.pieces == [] assert board1.is_peaceable() assert not board1.is_filled_at([1, 1]) assert np.sum(board1.black_vision_grid) == 0 assert np.sum(board1.white_vision_grid) == 0 assert np.sum(board1.full_vision_grid) == 0 w0 = Piece('white', [2, 4], board1) assert len(board1.black_pieces) == 0 assert len(board1.white_pieces) == 1 assert len(board1.pieces) == 1 assert board1.is_peaceable() assert not board1.is_filled_at([1, 1]) assert board1.is_filled_at([2, 4]) assert np.sum(board1.black_vision_grid) == 0 assert np.sum(board1.white_vision_grid) != 0 assert np.sum(board1.full_vision_grid) != 0 assert board1.ID_list == [0] w1 = Piece('white', [4, 7], board1) assert len(board1.black_pieces) == 0 assert len(board1.white_pieces) == 2 assert len(board1.pieces) == 2 assert board1.is_peaceable() assert board1.ID_list == [0, 1] b1 = Piece('black', [7, 7], board1) assert len(board1.black_pieces) == 1 assert len(board1.white_pieces) == 2 assert len(board1.pieces) == 3 assert not board1.is_peaceable() assert np.sum(board1.black_vision_grid) != 0 assert np.sum(board1.grid[..., 0]) == 1 #black pieces on grid assert np.sum(board1.grid[..., 1]) == 2 #white pieces on grid assert np.sum(board1.black_grid) == 1 #black pieces on grid assert np.sum(board1.white_grid) == 2 #white pieces on grid assert board1.ID_list == [0, 1, 2] board1.remove_piece(w1.ID) assert board1.ID_list == [0, 2] board1.reassign_IDs() assert board1.ID_list == [0, 1] assert board1.is_peaceable() assert len(board1.pieces) == 2 assert len(board1.white_pieces) == 1 assert np.sum(board1.white_grid) == 1 #white pieces on grid board1.move_piece(w0.ID, [5, 7]) assert not board1.is_peaceable()
def test_piece_count(): board = Board(8) w1 = Piece('white', [5, 2], board) assert metrics.piece_count(board) == 1 b1 = Piece('black', [7, 3], board) assert metrics.piece_count(board) == 2 b2 = Piece('black', [7, 4], board) assert metrics.piece_count(board) == 3 board.remove_piece(b1.ID) assert metrics.piece_count(board) == 2
def test_Piece_initialization(): board = Board(20) w1 = Piece('white',[5,2],board) assert w1.x == 5 assert w1.y == 2 assert w1.position == [5,2] with pytest.raises(ValueError): Piece('black',[-1,-1],board) with pytest.raises(ValueError): Piece('not_white_or_black',[1,1],board) with pytest.raises(ValueError): Piece('black',[5,2],board)
def test_vision_grid_sparsity(): board1 = Board(3) w1 = Piece('white', [1, 1], board1) assert metrics.vision_grid_sparsity(board1) == 9 / 18 b1 = Piece('black', [0, 1], board1) assert metrics.vision_grid_sparsity(board1) == 2 / 18 board2 = Board(5) w2 = Piece('white', [2, 2], board2) assert metrics.vision_grid_sparsity(board2) == 33 / 50 board3 = Board(8) w3 = Piece('white', [0, 0], board3) assert metrics.vision_grid_sparsity(board3) == 106 / 128 board4 = Board(3) w4 = Piece('white', [0, 0], board4) b2 = Piece('black', [2, 2], board4) assert metrics.vision_grid_sparsity(board4) == 4 / 18 board5 = Board([13, 18]) w5 = Piece('white', [10, 10], board5) assert metrics.vision_grid_sparsity(board5) == (13 * 18 * 2 - 51) / (13 * 18 * 2)
def test_Piece_diagonal_intersections(): board = Board([40,60]) w1 = Piece('white',[0,0],board) UL,UR,LL,LR = w1._diagonal_intersections() assert UL==[0,0] assert UR==[0,0] assert LL==[0,0] assert LR==[39,39] w2 = Piece('white',[39,0],board) UL,UR,LL,LR = w2._diagonal_intersections() assert UL==[39,0] assert UR==[39,0] assert LL==[0,39] assert LR==[39,0] w3 = Piece('white',[0,59],board) UL,UR,LL,LR = w3._diagonal_intersections() assert UL==[0,59] assert UR==[39,20] assert LL==[0,59] assert LR==[0,59] w4 = Piece('white',[11,25],board) UL,UR,LL,LR = w4._diagonal_intersections() assert UL==[0,14] assert UR==[36,0] assert LL==[0,36] assert LR==[39,53]