Exemple #1
0
def test_update_position():
    p = Piece(0, 1, "W", "WB1")
    assert p.rank == 0
    assert p.file == 1
    p.update_position(3, 4)
    assert p.rank == 3
    assert p.file == 4
Exemple #2
0
 def test_add_list_moves_friendly_squares(self, board):
     """Test add list moves with with friendly pieces in the way,
     returns the correct moves"""
     board.is_open.return_value = False
     board.is_enemy.return_value = False
     piece = Piece(board, WHITE, Position(1, 1))
     list_of_moves = [(3, 3), (1, 2)]
     moves = piece.add_list_moves(list_of_moves)
     self.assertEqual(len(moves), 0)
Exemple #3
0
 def test_add_list_moves_enemy_squares(self, board):
     """Test add_list_moves method with enemies and open
     squares, returns the correct moves"""
     board.is_open.return_value = False
     board.is_enemy.return_value = True
     piece = Piece(board, WHITE, Position(1, 1))
     list_of_moves = [(3, 3), (1, 2)]
     moves = piece.add_list_moves(list_of_moves)
     self.assertEqual(len(moves), 2)
     for m in list_of_moves:
         m = piece.position + m
         self.assertIn(m, moves)
Exemple #4
0
 def test_add_line_moves_friendly(self, board):
     """Test add line moves with friendly pieces in the way
     returns the correct moves"""
     direction = (1, 0)
     board.is_open.side_effect = [True, True, False, False]
     board.is_enemy.return_value = False
     piece = Piece(board, WHITE, Position(1, 1))
     moves = piece.add_line_moves(direction)
     self.assertEqual(len(moves), 2)
     position = piece.position.copy()
     for i in range(2):
         position = position + direction
         self.assertIn(position, moves)
Exemple #5
0
 def test_add_line_moves_open_squares(self, board):
     """Test add line moves with only open squers returns
     the correct moves"""
     direction = (1, 0)
     board.is_open.return_value = True
     board.is_enemy.return_value = False
     piece = Piece(board, WHITE, Position(1, 1))
     moves = piece.add_line_moves(direction)
     self.assertEqual(len(moves), 6)
     position = piece.position.copy()
     for i in range(5):
         position = position + direction
         self.assertIn(position, moves)
Exemple #6
0
def test_take_piece():
    p = Piece(0, 0, "W", "WB1")
    assert p.is_taken() == False
    p.set_as_taken()
    assert p.is_taken() == True
    assert p.rank == -1
    assert p.file == -1
Exemple #7
0
 def __init__(self,line,col,couleur):
     """Initialise une dame a la position (ligne,colonne) avec la bonne couleur 0 pour noir, 1 pour blanc"""
     Piece.__init__(self,line,col,couleur)
Exemple #8
0
def generic_piece():
    piece = Piece((randrange(8), randrange(8)), choice(['black', 'white']))
    return piece