class TestAttackSteps(unittest.TestCase): def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'a', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '4', 'black') self.another_black_pawn = Pawn(self.board, 'b', '3', 'black') self.test_black_pawn = Pawn(self.board, 'b', '7', 'black') self.attack_white_pawn= Pawn(self.board, 'c', '6', 'white') self.another_attack_white_pawn = Pawn(self.board, 'c', '5', 'white') def test_white_moves(self): result = self.pawn.get_possible_moves() self.assertEqual(len(self.pawn.__moves__), 4) self.assertIn((0, 2), self.pawn.__moves__) self.assertIn((0, 3), self.pawn.__moves__) self.assertIn((1, 2), self.pawn.__moves__) self.assertIn((1, 2), self.pawn.__moves__) def test_black_moves(self): result = self.test_black_pawn.get_possible_moves() self.assertEqual(len(self.test_black_pawn.__moves__), 4) self.assertIn((1, 5), self.test_black_pawn.__moves__) self.assertIn((1, 4), self.test_black_pawn.__moves__) self.assertIn((2, 5), self.test_black_pawn.__moves__) self.assertIn((2, 4), self.test_black_pawn.__moves__)
def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'a', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '4', 'black') self.another_black_pawn = Pawn(self.board, 'b', '3', 'black') self.test_black_pawn = Pawn(self.board, 'b', '7', 'black') self.attack_white_pawn= Pawn(self.board, 'c', '6', 'white') self.another_attack_white_pawn = Pawn(self.board, 'c', '5', 'white')
def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'b', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '7', 'black') self.blocking_white_pawn = Pawn(self.board, 'b', '3', 'white') self.blocking_black_pawn = Pawn(self.board, 'b', '6', 'white') self.another_pawn = Pawn(self.board, 'd', '2', 'white') self.another_blocking_pawn = Pawn(self.board, 'd', '4', 'white')
class TestPawnSingleMove(unittest.TestCase): def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'c', '5', 'white') self.black_pawn = Pawn(self.board, 'b', '3', 'black') def test_single_possible_move(self): result = self.pawn.get_possible_moves() self.assertIn((2, 5), self.pawn.__moves__) self.assertIn("Pawn at <C:5> can move to <C:6>", result) result = self.black_pawn.get_possible_moves() self.assertIn((1,1,), self.black_pawn.__moves__) self.assertIn("Pawn at <B:3> can move to <B:2>", result)
class TestDoubleMove(unittest.TestCase): def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'b', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '7', 'black') def test_double_step_move(self): result = self.pawn.get_possible_moves() self.assertIn((1,2), self.pawn.__moves__) self.assertIn((1,3), self.pawn.__moves__) self.assertIn("Pawn at <B:2> can move to <B:3>", result) self.assertIn("Pawn at <B:2> can move to <B:4>", result) result = self.black_pawn.get_possible_moves() self.assertIn((1,5), self.black_pawn.__moves__) self.assertIn((1,4), self.black_pawn.__moves__) self.assertIn("Pawn at <B:7> can move to <B:6>", result) self.assertIn("Pawn at <B:7> can move to <B:5>", result)
class TestBlockedSteps(unittest.TestCase): def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'b', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '7', 'black') self.blocking_white_pawn = Pawn(self.board, 'b', '3', 'white') self.blocking_black_pawn = Pawn(self.board, 'b', '6', 'white') self.another_pawn = Pawn(self.board, 'd', '2', 'white') self.another_blocking_pawn = Pawn(self.board, 'd', '4', 'white') def test_white_block_moves(self): result = self.pawn.get_possible_moves() self.assertEqual(len(self.pawn.__moves__), 0) def test_black_block_moves(self): result = self.black_pawn.get_possible_moves() self.assertEqual(len(self.black_pawn.__moves__), 0) def test_another_white_pawn(self): result = self.another_pawn.get_possible_moves() self.assertEqual(len(self.another_pawn.__moves__), 1) self.assertIn((3,2), self.another_pawn.__moves__)
def create(self): for i in range(8): for j in range(8): if i == 0 or i == 1: color = 'black' if i == 6 or i == 7: color = 'white' if i == 0 or i == 7: if j == 0 or j == 7: self.figures.append( Rook(j, i, color, figures_images[color + 'Rook']['Image'], self.board)) if j == 1 or j == 6: self.figures.append( Knight(j, i, color, figures_images[color + 'Knight']['Image'], self.board)) if j == 2 or j == 5: self.figures.append( Bishop(j, i, color, figures_images[color + 'Bishop']['Image'], self.board)) if j == 3: self.figures.append( King(j, i, color, figures_images[color + 'King']['Image'], self.board)) if j == 4: self.figures.append( Queen(j, i, color, figures_images[color + 'Queen']['Image'], self.board)) if i == 1 or i == 6: self.figures.append( Pawn(j, i, color, figures_images[color + 'Pawn']['Image'], self.board))
def __init__(self) -> None: self.field = [] self.current_color = Color.WHITE for i in range(self.FIELD_SIZE): self.field.append([None] * self.FIELD_SIZE) # стандартная расстановка self.field[0] = [ Rook(0, 0, Color.WHITE, self), Knight(0, 1, Color.WHITE, self), Bishop(0, 2, Color.WHITE, self), Queen(0, 3, Color.WHITE, self), King(0, 4, Color.WHITE, self), Bishop(0, 5, Color.WHITE, self), Knight(0, 6, Color.WHITE, self), Rook(0, 7, Color.WHITE, self), ] self.field[1] = [ Pawn(1, 0, Color.WHITE, self), Pawn(1, 1, Color.WHITE, self), Pawn(1, 2, Color.WHITE, self), Pawn(1, 3, Color.WHITE, self), Pawn(1, 4, Color.WHITE, self), Pawn(1, 5, Color.WHITE, self), Pawn(1, 6, Color.WHITE, self), Pawn(1, 7, Color.WHITE, self), ] self.field[6] = [ Pawn(6, 0, Color.BLACK, self), Pawn(6, 1, Color.BLACK, self), Pawn(6, 2, Color.BLACK, self), Pawn(6, 3, Color.BLACK, self), Pawn(6, 4, Color.BLACK, self), Pawn(6, 5, Color.BLACK, self), Pawn(6, 6, Color.BLACK, self), Pawn(6, 7, Color.BLACK, self), ] self.field[7] = [ Rook(7, 0, Color.BLACK, self), Knight(7, 1, Color.BLACK, self), Bishop(7, 2, Color.BLACK, self), Queen(7, 3, Color.BLACK, self), King(7, 4, Color.BLACK, self), Bishop(7, 5, Color.BLACK, self), Knight(7, 6, Color.BLACK, self), Rook(7, 7, Color.BLACK, self), ]
def __init__(self) -> None: self.field = [] self.current_color = Color.WHITE for i in range(self.FIELD_SIZE): self.field.append([None] * self.FIELD_SIZE) logging.debug( f'Создана шахматная доска с размерами: {self.FIELD_SIZE}x{self.FIELD_SIZE}' ) # стандартная расстановка self.field[0] = [ Rook(0, 0, Color.WHITE, self), Knight(0, 1, Color.WHITE, self), Bishop(0, 2, Color.WHITE, self), Queen(0, 3, Color.WHITE, self), King(0, 4, Color.WHITE, self), Bishop(0, 5, Color.WHITE, self), Knight(0, 6, Color.WHITE, self), Rook(0, 7, Color.WHITE, self), ] self.field[1] = [ Pawn(1, 0, Color.WHITE, self), Pawn(1, 1, Color.WHITE, self), Pawn(1, 2, Color.WHITE, self), Pawn(1, 3, Color.WHITE, self), Pawn(1, 4, Color.WHITE, self), Pawn(1, 5, Color.WHITE, self), Pawn(1, 6, Color.WHITE, self), Pawn(1, 7, Color.WHITE, self), ] self.field[6] = [ Pawn(6, 0, Color.BLACK, self), Pawn(6, 1, Color.BLACK, self), Pawn(6, 2, Color.BLACK, self), Pawn(6, 3, Color.BLACK, self), Pawn(6, 4, Color.BLACK, self), Pawn(6, 5, Color.BLACK, self), Pawn(6, 6, Color.BLACK, self), Pawn(6, 7, Color.BLACK, self), ] self.field[7] = [ Rook(7, 0, Color.BLACK, self), Knight(7, 1, Color.BLACK, self), Bishop(7, 2, Color.BLACK, self), Queen(7, 3, Color.BLACK, self), King(7, 4, Color.BLACK, self), Bishop(7, 5, Color.BLACK, self), Knight(7, 6, Color.BLACK, self), Rook(7, 7, Color.BLACK, self), ] logging.debug('Расстановка фигур завершена')
def test_legal_move(): cb = Chessboard(Game.WHITE_PIECES, Game.BLACK_PIECES) p = Pawn(0, 0, "W", "WP1") assert p.is_legal_move([1, 1], cb.status()) == True
def setUp(self): self.board = Board() self.pawn = Pawn(self.board, 'b', '2', 'white') self.black_pawn = Pawn(self.board, 'b', '7', 'black')