def test_piece_can_be_promoted(self): piece = Piece("white", 10) new_piece = piece.promote() assert isinstance(new_piece, King) assert new_piece.player == "white" assert new_piece.square == 10
def test_black_can_take_white(self): board = Board() board.reset() board._board[2, 1] = Piece("black", None) board._board[3, 2] = Piece("white", None) assert board._check_can_take(9, 18)
def test_white_can_take_black(self): board = Board() board.reset() board._board[4, 3] = Piece("white", None) board._board[3, 2] = Piece("black", None) assert board._check_can_take(18, 9)
def test_that_piece_equates_to_str(self): piece = Piece("white", 32) black_piece = Piece("black", 1) assert piece == "white" assert not piece == "black" assert black_piece == "black" assert not black_piece == "white"
def test_cant_take_if_middle_piece_is_same_as_taking_piece(self): board = Board() board.reset() # Put white pieces next to one another board._board[4, 3] = Piece("white", None) board._board[3, 2] = Piece("white", None) assert not board._check_can_take(18, 9)
def test_move_removes_taken_pieces(self): board = Board() board.reset() # Put a black piece next to a white board._board[(5, 4)] = Piece("black", None) piece_taken = board.move(26, 19) assert piece_taken assert board._board[(6, 3)] == EmptyPiece() assert board._board[(5, 4)] == EmptyPiece() assert board._board[(4, 5)] == Piece("white", None)
def test_can_move_pieces(self): board = Board() board.reset() piece_taken = board.move(26, 23) assert not piece_taken assert board._board[(6, 3)] == EmptyPiece() assert board._board[(5, 4)] == Piece("white", None) piece_taken = board.move(6, 10) assert not piece_taken assert board._board[(1, 2)] == EmptyPiece() assert board._board[(2, 3)] == Piece("black", None)
def test_that_empty_peice_equates_to_piece(self): empty = EmptyPiece(10) empty2 = EmptyPiece(11) piece = Piece("white", 32) black_piece = Piece("black", 1) king = King("white", 2) black_king = King("black", 31) assert empty == empty2 assert not empty == piece assert not empty == black_piece assert not empty == king assert not empty == black_king
def test_takes_included_in_valid_moves(self): game = Game() game._board._board[4, 3] = Piece("white", None) game._board._board[3, 4] = Piece("black", None) game._board._board[5, 4] = Piece("black", None) game._board._board[2, 3] = Piece("white", None) assert "18-11" in game.valid_moves("white") assert "15-22" in game.valid_moves("black") assert "18-27" not in game.valid_moves( "white") # because piece can't move backwards assert "15-6" not in game.valid_moves("black")
def test_that_piece_equates_to_piece(self): piece = Piece("white", 32) king = King("white", 1) black_piece = Piece("black", 2) black_king = King("black", 31) assert piece == piece assert piece == king assert not piece == black_piece assert not piece == black_king assert black_piece == black_piece assert black_piece == black_king assert not black_piece == piece assert not black_piece == king
def test_that_king_equates_to_pieces(self): king = King("white", 10) king2 = King("white", 12) piece = Piece("white", 11) black_king = King("black", 1) black_piece = Piece("black", 2) assert king == piece assert king == king2 assert king == king assert not king == black_king assert not king == black_piece assert black_king == black_piece assert not black_king == piece assert not black_king == king
def test_that_white_piece_on_top_row_can_be_promoted(self): board = Board() board.reset() board._board[(0, 1)] = Piece("white", 1) board._promote((0, 1)) assert isinstance(board._board[(0, 1)], King)
def test_that_black_piece_on_bottom_row_can_be_promoted(self): board = Board() board.reset() board._board[(7, 0)] = Piece("black", 29) board._promote((7, 0)) assert isinstance(board._board[(7, 0)], King)
def test_cant_take_if_no_middle_piece(self): board = Board() board.reset() board._board[4, 3] = Piece("white", None) assert not board._check_can_take(18, 9)
def test_valid_moves_considers_player_turn(self): game = Game() game.turn = "black" # Remove existing black pieces game._board._board[:, :2] = EmptyPiece() game._board._board[0, 3] = Piece("black", None) assert game.valid_moves() == ["2-6", "2-7"]
def test_that_reset_resets_game(self): game = Game() game._board._board[5, 4] = Piece("white", None) game._move_list = [1, 2, 3, 4] game.turn = "black" game._pieces_remaining = {"white": 5, "black": 6} game.reset() assert np.array_equal(game._board._board, new_board) assert game._move_list == [] assert game.turn == "white" assert game._pieces_remaining == {"white": 8, "black": 8}
def test_that_white_pieces_can_be_promoted_on_move(self): board = Board() board.reset() # put a white piece within a move of end row board._board[(1, 0)] = Piece("white", None) # remove the black piece in its way board._board[(0, 1)] = EmptyPiece(None) # Move the white piece into the top row board.move(5, 1) assert board._board[(1, 0)] == EmptyPiece() assert board._board[(0, 1)] == King("white", None)
def test_that_black_pieces_can_be_promoted_on_move(self): board = Board() board.reset() # put a black piece within a move of bottom row board._board[(6, 1)] = Piece("black", None) # remove the black piece in its way board._board[(7, 0)] = EmptyPiece(None) # Move the white piece into the bottom row board.move(25, 29) assert board._board[(6, 1)] == EmptyPiece() assert board._board[(7, 0)] == King("black", None)
def test_white_piece_cannot_move_southwest(self): piece = Piece("white", 10) assert not piece.move(Direction.SW)
def test_white_piece_can_move_northwest(self): piece = Piece("white", 10) assert piece.move(Direction.NW)
def test_black_piece_can_move_southwest(self): piece = Piece("black", 10) assert piece.move(Direction.SW)
def test_black_piece_cannot_move_northwest(self): piece = Piece("black", 10) assert not piece.move(Direction.NW)
def test_that_white_piece_prints_to_O(self): piece = Piece("white", 10) assert str(piece) == "O"
def test_that_black_piece_prints_to_X(self): piece = Piece("black", 10) assert str(piece) == "X"
import numpy as np from alphadraughts.draughts.piece import EmptyPiece, Piece new_board = np.array( [ [ EmptyPiece(), Piece("black", 1), EmptyPiece(), Piece("black", 2), EmptyPiece(), Piece("black", 3), EmptyPiece(), Piece("black", 4), ], [ Piece("black", 5), EmptyPiece(), Piece("black", 6), EmptyPiece(), Piece("black", 7), EmptyPiece(), Piece("black", 8), EmptyPiece(), ], [ EmptyPiece(), EmptyPiece(), EmptyPiece(), EmptyPiece(),