def test_promotions_with_capturable(self): pawn = Pawn(self.white, (4, 6)) rook = Rook(self.black, (3, 7)) self.board.add_piece(pawn) self.board.add_piece(rook) moves = list(pawn.moves(self.board)) self.assertTrue(len(moves), 8)
def __init__(self): self.pieces = [] self.selected_idx = None self._player_name = None for i in range(8): self.pieces += [Pawn(i, 1, 'black')] self.pieces += [Pawn(i, 6, 'white')] self.pieces += [ Rook(0, 0, 'black'), Rook(7, 0, 'black'), Knight(1, 0, 'black'), Knight(6, 0, 'black'), Bishop(2, 0, 'black'), Bishop(5, 0, 'black'), Queen(3, 0, 'black'), King(4, 0, 'black'), Rook(0, 7, 'white'), Rook(7, 7, 'white'), Knight(1, 7, 'white'), Knight(6, 7, 'white'), Bishop(2, 7, 'white'), Bishop(5, 7, 'white'), Queen(3, 7, 'white'), King(4, 7, 'white'), ]
def test_promotions_are_valid_with_capturable(self): pawn = Pawn(self.white, (4, 6)) rook = Rook(self.black, (3, 7)) self.board.add_piece(pawn) self.board.add_piece(rook) moves = list(pawn.moves(self.board)) self.assertTrue(all(move.promotion is not None for move in moves))
def __init__(self): self.rows = common.DIMENSION self.cols = common.DIMENSION self.current_color = "white" self.board_inst = {} for row in range(self.rows): for col in range(self.cols): self.board_inst[row, col] = Empty(row, col, None) self.board_inst[0, 0] = Rook(0, 0, 'black') self.board_inst[0, 1] = Knight(0, 1, 'black') self.board_inst[0, 2] = Bishop(0, 2, 'black') self.board_inst[0, 3] = Queen(0, 3, 'black') self.board_inst[0, 4] = King(0, 4, 'black') self.board_inst[0, 5] = Bishop(0, 5, 'black') self.board_inst[0, 6] = Knight(0, 6, 'black') self.board_inst[0, 7] = Rook(0, 7, 'black') self.board_inst[7, 0] = Rook(7, 0, 'white') self.board_inst[7, 1] = Knight(7, 1, 'white') self.board_inst[7, 2] = Bishop(7, 2, 'white') self.board_inst[7, 3] = Queen(7, 3, 'white') self.board_inst[7, 4] = King(7, 4, 'white') self.board_inst[7, 5] = Bishop(7, 5, 'white') self.board_inst[7, 6] = Knight(7, 6, 'white') self.board_inst[7, 7] = Rook(7, 7, 'white') for i in range(common.DIMENSION): self.board_inst[1, i] = Pawn(1, i, 'black') self.board_inst[6, i] = Pawn(6, i, 'white')
def test_crowning_perform_undo(self): '''Test performing a crowning move and then undoing it''' #init: board = Board(10, 10) pawn = Pawn(board.white) i, j = 0, 1 board[i, j].piece = pawn src_type = str(pawn).split(" ")[0].replace("<", "") move = filter(lambda x: x.type == "Crowning", pawn.get_moves((i, j), board))[0] #Preconditions: self.assertTrue(not board[i, j-1].piece) self.assertTrue(board[i, j].piece) move.perform(board) self.assertTrue(board[i, j-1].piece) self.assertTrue(not board[i, j].piece) self.assertTrue(move.performed) #compare piece types (should differ if crowning succeeded): dst_type = str(board[i, j-1].piece).split(" ")[0].replace("<","") self.assertTrue(src_type != dst_type) #undo move: move.undo(board) self.assertTrue(not board[i, j-1].piece) self.assertTrue(board[i, j].piece) self.assertTrue(not move.performed) #compare piece types (should be both pawns): dst_type = str(board[i, j].piece).split(" ")[0].replace("<","") self.assertTrue(src_type == dst_type)
def test_move_perform_undo(self): '''Test performing a move and then undoing it.''' #set up: board = Board(10, 10) pawn = Pawn(board.white) i, j = 0, 6 board[i, j].piece = pawn move = pawn.get_moves((i, j), board)[0] #initial conditions: self.assertTrue(not board[i, j-1].piece) self.assertTrue(board[i, j].piece) #test performing the move: move.perform(board) self.assertTrue(board[i, j-1].piece) self.assertTrue(not board[i, j].piece) self.assertTrue(not move.dst_piece) self.assertTrue(move.performed) #test undoing the move: move.undo(board) self.assertTrue(not board[i, j-1].piece) self.assertTrue(board[i, j].piece) self.assertTrue(not move.performed)
def __init__(self): #setup board and pieces self.blackPieces = [] self.whitePieces = [] self.blackPieces.append(King(4, 0, BLACK)) self.blackPieces.append(Queen(3, 0, BLACK)) self.blackPieces.append(Bishop(2, 0, BLACK)) self.blackPieces.append(Bishop(5, 0, BLACK)) self.blackPieces.append(Knight(1, 0, BLACK)) self.blackPieces.append(Knight(6, 0, BLACK)) self.blackPieces.append(Rook(0, 0, BLACK)) self.blackPieces.append(Rook(7, 0, BLACK)) for i in range(0, 8): self.blackPieces.append(Pawn(i, 1, BLACK)) self.whitePieces.append(King(4, 7, WHITE)) self.whitePieces.append(Queen(3, 7, WHITE)) self.whitePieces.append(Bishop(2, 7, WHITE)) self.whitePieces.append(Bishop(5, 7, WHITE)) self.whitePieces.append(Knight(1, 7, WHITE)) self.whitePieces.append(Knight(6, 7, WHITE)) self.whitePieces.append(Rook(0, 7, WHITE)) self.whitePieces.append(Rook(7, 7, WHITE)) for i in range(0, 8): self.whitePieces.append(Pawn(i, 6, WHITE))
def test_pawn_valid_change_white_rank2(): current_square = Square('e', '2') piece = Pawn(Colour.WHITE) current_square.set_piece(piece) to_square = Square('e', '3') assert piece.valid_change(to_square, is_capture=False) to_square = Square('e', '4') assert piece.valid_change(to_square, is_capture=False)
def test_pawn_valid_change_black_any_rank(): current_square = Square('e', '6') piece = Pawn(Colour.BLACK) current_square.set_piece(piece) to_square = Square('e', '5') assert piece.valid_change(to_square, is_capture=False) to_square = Square('e', '4') assert not piece.valid_change(to_square, is_capture=False)
def test_cant_en_passant(self): pawn1 = Pawn(self.white, (4, 4)) pawn2 = Pawn(self.black, (3, 5)) self.board.add_piece(pawn1) self.board.add_piece(pawn2) move = Move(pawn2, pawn2.location, (3, 4)) self.game._make_move(move) moves = [m for m in pawn1.moves(self.board)] self.assertEqual(len(moves), 1)
def test_moves_captureable_enemy(self): king = King(self.white, (0, 4)) pawn = Pawn(self.white, (4, 4)) bishop = Bishop(self.black, (5, 5)) self.board.add_piece(king) self.board.add_piece(pawn) self.board.add_piece(bishop) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 2, moves)
def setup_game(self): for position in range(0, 8): self.pieces[position] = STARTING_POSITIONS[position]('white', position) for position in range(8, 16): self.pieces[position] = Pawn('white', position) for position in range(48, 56): self.pieces[position] = Pawn('black', position) for position in range(56, 64): self.pieces[position] = STARTING_POSITIONS[position]('black', position)
def __init__(self): self.state = [[EMPTY_SQUARE for y in range(BOARD_SIZE)] for x in range(BOARD_SIZE)] self.white_pieces = ROOK + HORSE + BISHOP + QUEEN + KING + PAWN self.black_pieces = self.white_pieces.lower() # White self.state[0] = [Rook(0, 0), Knight(0, 1), Bishop(0, 2), Queen(0, 3), King(0, 4), Bishop(0, 5), Knight(0, 6), Rook(0, 7)] self.state[1] = [Pawn(1, 0), Pawn(1, 1), Pawn(1, 2), Pawn(1, 3), Pawn(1, 4), Pawn(1, 5), Pawn(1, 6), Pawn(1, 7)] # Black self.state[6] = [Pawn(7, 0, False), Pawn(7, 1, False), Pawn(7, 2, False), Pawn(7, 3, False), Pawn(7, 4, False), Pawn(7, 5, False), Pawn(7, 6, False), Pawn(7, 7, False)] self.state[7] = [Rook(6, 0, False), Knight(6, 1, False), Bishop(6, 2, False), Queen(6, 3, False), King(6, 4, False), Bishop(6, 5, False), Knight(6, 6, False), Rook(6, 7, False)]
def __init__(self, player1, player2, graphic_interface, verbose = False) : self.board = [ Rook(Color.BLACK), Knight(Color.BLACK), Bishop(Color.BLACK), Queen(Color.BLACK), King(Color.BLACK), Bishop(Color.BLACK), Knight(Color.BLACK), Rook(Color.BLACK) ] self.board += [Pawn(Color.BLACK) for _ in range(8)] self.board += [Null() for _ in range(32)] self.board += [Pawn(Color.WHITE) for _ in range(8)] self.board += [ Rook(Color.WHITE), Knight(Color.WHITE), Bishop(Color.WHITE), Queen(Color.WHITE), King(Color.WHITE), Bishop(Color.WHITE), Knight(Color.WHITE), Rook(Color.WHITE) ] self.board_with_boundaries = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, 40, 41, 42, 43, 44, 45, 46, 47, -1, -1, 48, 49, 50, 51, 52, 53, 54, 55, -1, -1, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, -1, -1 ,-1 ,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] self.player1 = player1 self.player2 = player2 self.graphic_interface = graphic_interface self.selected_case = None self.selected_case_2 = None self.turn = Color.WHITE self.special_moves_authorization = [ True, #White castle True, #White castle (queen side) True, #Black castle True, #Black castle (queen side) -1, #White "en passant" capture -1 #Black "en passant" capture ] self.moves_played=[] self.end = False self.verbose = verbose
def test_ordinary_move_capture(): board = Board() white_pawn = Pawn(Colour.WHITE) black_pawn = Pawn(Colour.BLACK) board['e4'].set_piece(white_pawn) board['d5'].set_piece(black_pawn) move = CaptureMove(1, Colour.WHITE, 'e4', 'd5') move.apply(board) assert black_pawn.square is None assert board['d5'].piece is white_pawn assert board['e4'].piece is None
def __init__(self): self.board = ChessBoard(self) self.pieces = [Pawn(self, "white", item) for item in [i + "2" for i in "abcdefgh"]] self.pieces.extend([Pawn(self, "black", item) for item in [i + "7" for i in "abcdefgh"]]) self.pieces.extend([Rook(self, "white", item) for item in ("a1", "h1")]) self.pieces.extend([Rook(self, "black", item) for item in ("a8", "h8")]) self.pieces.extend([Bishop(self, "white", item) for item in ("c1", "f1")]) self.pieces.extend([Bishop(self, "black", item) for item in ("c8", "f8")]) self.pieces.extend([Knight(self, "white", item) for item in ("b1", "g1")]) self.pieces.extend([Knight(self, "black", item) for item in ("b8", "g8")]) self.pieces.extend([King(self, "white", "e1"), King(self, "black", "e8"), Queen(self, "white", "d1"), Queen(self, "black", "d8")]) self.players = []
def test_white_crowning(self): '''Test white crowning.''' board = Board(10, 10) pawn = Pawn(board.white) i, j = 1, 1 board[i, j].piece = pawn moves = pawn.get_moves((i, j), board) self.assertEquals(len(moves), 1) self.assertTrue(moves[0].type == "Crowning")
def test_basic_white_moves(self): '''Test basic white pawn movement (step and double-step).''' board = Board(10, 10) pawn = Pawn(board.white) i, j = 1, 6 board[i, j].piece = pawn moves = pawn.get_moves((i, j), board) self.assertEquals(len(moves), 2) self.assertTrue(Move((i,j), (i,j-1)) in moves) self.assertTrue(Move((i,j), (i,j-2)) in moves)
def __init__(self, rows, cols): self.rows = rows self.cols = cols self.turn = "w" self.winner = None self.last = None #player time self.time1 = 900 self.time2 = 900 """Places all the pieces on 2D Array Board & generate the board""" self.board = [[0 for x in range(8)] for _ in range(rows)] self.board[0][0] = Rook(0, 0, "b") self.board[0][1] = Knight(0, 1, "b") self.board[0][2] = Bishop(0, 2, "b") self.board[0][3] = Queen(0, 3, "b") self.board[0][4] = King(0, 4, "b") self.board[0][5] = Bishop(0, 5, "b") self.board[0][6] = Knight(0, 6, "b") self.board[0][7] = Rook(0, 7, "b") self.board[7][0] = Rook(7, 0, "w") self.board[7][1] = Knight(7, 1, "w") self.board[7][2] = Bishop(7, 2, "w") self.board[7][3] = Queen(7, 3, "w") self.board[7][4] = King(7, 4, "w") self.board[7][5] = Bishop(7, 5, "w") self.board[7][6] = Knight(7, 6, "w") self.board[7][7] = Rook(7, 7, "w") #faster way of setting pawns for colum in range(0, 8): self.board[1][colum] = Pawn(1, colum, "b") self.board[6][colum] = Pawn(6, colum, "w") #keep track of pieces move self.moveStack = [] self.turn = "w" self.time1 = 900 self.time2 = 900 self.storedTime1 = 0 self.storedTime2 = 0 self.winner = None self.startTime = time.time()
def __init__(self, grid, newBoard=False, whiteInCheck=False, blackInCheck=False): if (newBoard == True): self.mobility = 0 self.bMobility = 0 self.grid = [[None for x in range(0, 8)] for y in range(0, 8)] for i in range(0, 8): for j in range(0, 8): if (grid[i][j] == '_' or grid[i][j] == '-'): self.grid[i][j] = None elif (grid[i][j] == 'P'): self.grid[i][j] = Pawn(i, j, 'w', 'P') elif (grid[i][j] == 'p'): self.grid[i][j] = Pawn(i, j, 'b', 'p') elif (grid[i][j] == 'N'): self.grid[i][j] = Knight(i, j, 'w', 'N') elif (grid[i][j] == 'n'): self.grid[i][j] = Knight(i, j, 'b', 'n') elif (grid[i][j] == 'B'): self.grid[i][j] = Bishop(i, j, 'w', 'B') elif (grid[i][j] == 'b'): self.grid[i][j] = Bishop(i, j, 'b', 'b') elif (grid[i][j] == 'Q'): self.grid[i][j] = Queen(i, j, 'w', 'Q') elif (grid[i][j] == 'q'): self.grid[i][j] = Queen(i, j, 'b', 'q') elif (grid[i][j] == 'K'): self.grid[i][j] = King(i, j, 'w', 'K') elif (grid[i][j] == 'k'): self.grid[i][j] = King(i, j, 'b', 'k') elif (grid[i][j] == 'R'): self.grid[i][j] = Rook(i, j, 'w', 'R') elif (grid[i][j] == 'r'): self.grid[i][j] = Rook(i, j, 'b', 'r') self.whiteInCheck = whiteInCheck # change later maybe? self.blackInCheck = blackInCheck # change later maybe? else: self.mobility = 0 self.bMobility = 0 self.grid = grid self.whiteInCheck = whiteInCheck # change later maybe? self.blackInCheck = blackInCheck # change later maybe? self.evalValue = self.evaluationFunction()
def test_en_passant_left(self): '''Test en passant for black pawn.''' board = Board(10, 10) white_pawn = Pawn(board.white) black_pawn = Pawn(board.black) board[4, 4].piece = black_pawn board[3, 6].piece = white_pawn board.perform_move(Move((3,6), (3,4))) moves = black_pawn.get_moves((4, 4), board) self.assertEquals(2, len(moves)) self.assertTrue(Move((4,4),(4,5)) in moves) self.assertTrue(EnPassant((4,4), LEFT, board.black) in moves)
def test_white_crowning_attack(self): '''Test white crowning attack.''' board = Board(10, 10) pawn = Pawn(board.white) rook = Rook(board.black) i, j = 1, 1 board[i, j].piece = pawn board[0, 0].piece = rook moves = pawn.get_moves((i, j), board) self.assertEquals(2, len(moves)) self.assertTrue(Crowning((1,1),(1,0),Queen(board.white)) in moves) self.assertTrue(Crowning((1,1),(0,0),Queen(board.white)) in moves)
def test_white_attack_move(self): '''Test attack move for white pawn.''' board = Board(10, 10) white_pawn = Pawn(board.white) black_pawn = Pawn(board.black) i, j = 1, 6 board[i, j].piece = white_pawn board[i-1, j-1].piece = black_pawn board[i+1, j-1].piece = black_pawn moves = white_pawn.get_moves((i, j), board) self.assertEquals(4, len(moves)) self.assertTrue(Move((i,j),(i-1,j-1)) in moves) self.assertTrue(Move((i,j),(i+1,j-1)) in moves)
def generateGrid(): return { "whites": [Pawn(Vector(i, 6), "whites") for i in range(8)] + [Rook(Vector(0, 7), "whites"), Rook(Vector(7, 7), "whites")] + [Bishop(Vector(2, 7), "whites"), Bishop(Vector(5, 7), "whites")] + [Queen(Vector(3, 7), "whites")] + [Knight(Vector(1, 7), "whites"), Knight(Vector(6, 7), "whites")] + [King(Vector(4, 7), "whites")], "blacks": [Pawn(Vector(i, 1), "blacks") for i in range(8)] + [Rook(Vector(0, 0), "blacks"), Rook(Vector(7, 0), "blacks")] + [Bishop(Vector(2, 0), "blacks"), Bishop(Vector(5, 0), "blacks")] + [Queen(Vector(3, 0), "blacks")] + [Knight(Vector(1, 0), "blacks"), Knight(Vector(6, 0), "blacks")] + [King(Vector(4, 0), "blacks")] }
def setup_colour(self, reverse=False, colour='black'): royalty, pawns = [7, 6] if reverse else [0, 1] for i, piece in enumerate( [Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook]): self.table[royalty][i] = piece(colour=colour) self.table[pawns] = [Pawn(colour=colour) for i in range(8)]
def colour_pieces(colour): pieces = [Pawn(colour) for _ in range(8)] pieces += [Rook(colour) for _ in range(2)] pieces += [Knight(colour) for _ in range(2)] pieces += [Bishop(colour) for _ in range(2)] pieces += [Queen(colour)] pieces += [King(colour)] return pieces
def test_bad_moves_forward(self): pawn = Pawn(color='WHITE') pawn.first_move = False is_valid_move = pawn.validate_move((5,2),(3,2)) self.assertFalse(is_valid_move) pawn = Pawn(color='BLACK') pawn.first_move = False is_valid_move = pawn.validate_move((5,1),(4,1)) self.assertFalse(is_valid_move)
class PieceCanNotJump(unittest.TestCase): def test_rock_can_not_jump(self): self.r = Rock('w') self.assertFalse(self.r.can_jump()) def test_pawn_can_not_jump(self): self.p = Pawn('w') self.assertFalse(self.p.can_jump())
def test_pawn_valid_change_black_capture(): current_square = Square('e', '6') piece = Pawn(Colour.BLACK) current_square.set_piece(piece) to_square = Square('d', '5') to_square.set_piece(Pawn(Colour.BLACK)) assert piece.valid_change(to_square, is_capture=True) to_square = Square('f', '5') to_square.set_piece(Pawn(Colour.BLACK)) assert piece.valid_change(to_square, is_capture=True) to_square = Square('e', '4') to_square.set_piece(Pawn(Colour.BLACK)) assert not piece.valid_change(to_square, is_capture=True)
def is_Piece_threating_piece(board, piece, Piece): color_op = piece.color if Piece == Pawn: dir_op = 'down' if piece.rotate else 'up' piece = Pawn(piece.pos, color_op, dir_op) else: piece = Piece( piece.pos, color_op, ) moves = piece.all_possible_moves(board) pos_possible_piece = [None] * 2 for move in moves: pos_possible_piece[0] = piece.pos[0] + move[0] pos_possible_piece[1] = piece.pos[1] + move[1] if Rule.is_in_range(pos_possible_piece): possible_piece = board.arr[pos_possible_piece[1]][ pos_possible_piece[0]] if isinstance(possible_piece, Piece): return True return False
def test_bad_captures(self): pawn = Pawn(color='WHITE') is_valid_capture = pawn.validate_capture((5,1), (5,3)) self.assertFalse(is_valid_capture) pawn = Pawn(color='BLACK') is_valid_capture = pawn.validate_capture((4,2), (4,7)) self.assertFalse(is_valid_capture)
def piece_setup(self): for i in [0, 1]: for k in range(8): self.place(Pawn(0, k, 6)) self.place(Pawn(1, k, 1)) if i == 0: j = 7 else: j = 0 self.place(Rook(i, 0, j)) self.place(Rook(i, 7, j)) self.place(Knight(i, 1, j)) self.place(Knight(i, 6, j)) self.place(Bishop(i, 2, j)) self.place(Bishop(i, 5, j)) self.place(Queen(i, 3, j)) self.place(King(i, 4, j)) self.move_stack = []
def factory(piece, color): piece = piece.lower() color = color.lower() color = 'w' if color == 'white' else 'b' if piece == 'pawn': return Pawn(color) elif piece == 'rook': return Rook(color) elif piece == 'knight': return Knight(color) elif piece == 'bishop': return Bishop(color) elif piece == 'queen': return Queen(color) elif piece == 'king': return King(color)
def test_attacked_locations_black_none(self): pawn = Pawn(Location(5, 'd'), Player.BLACK, self.board) results = set() self.assertEquals(set(pawn.attacked_locations()), results)
def test_cant_validate_capture_as_move(self): pawn = Pawn(color='WHITE') is_valid_move = pawn.validate_move((6,1),(5,2)) self.assertFalse(is_valid_move)
def _row_of_pawns(color): return [Pawn(color) for _ in range(0, 9)]
def test_promotions(self): pawn = Pawn(self.white, (4, 6)) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 4, moves)
def test_cant_move_backward(self): pawn = Pawn(color='WHITE') is_valid_move = pawn.validate_move((6,1),(7,1)) self.assertFalse(is_valid_move)
def __init__(self, pos, color, dir, size, rotate=False): img = 'pawn-{}.png'.format(color) Pawn.__init__(self, pos, color, dir, rotate) DrawablePiece.__init__(self, pos, color, img, size, rotate)
def test_attacked_locations_white(self): pawn = Pawn(Location(5, 'd'), Player.WHITE, self.board) queen = Queen(Location(6, 'c'), Player.BLACK, self.board) knight = Knight(Location(6, 'e'), Player.BLACK, self.board) results = {Location(6, 'c'), Location(6, 'e')} self.assertEquals(set(pawn.attacked_locations()), results)
def test_can_capture_diagonally_forward_to_left(self): pawn = Pawn(color='WHITE') is_valid_capture = pawn.validate_capture((5,2),(4,1)) self.assertTrue(is_valid_capture)
def test_promotions_are_valid(self): pawn = Pawn(self.white, (4, 6)) moves = list(pawn.moves(self.board)) self.assertTrue(all(move.promotion is not None for move in moves))
def copy(self): return Pawn(self.pos, self.color, self.dir, self.rotate)
def test_moves_center(self): pawn = Pawn(self.white, (4, 4)) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 1, moves)
def __init__(self, rows, cols): self.rows = rows self.cols = cols self.ready = False self.last = None self.copy = True self.board = [[0 for x in range(8)] for _ in range(rows)] self.board[0][0] = Rook(0, 0, "b") self.board[0][1] = Knight(0, 1, "b") self.board[0][2] = Bishop(0, 2, "b") self.board[0][3] = Queen(0, 3, "b") self.board[0][4] = King(0, 4, "b") self.board[0][5] = Bishop(0, 5, "b") self.board[0][6] = Knight(0, 6, "b") self.board[0][7] = Rook(0, 7, "b") self.board[1][0] = Pawn(1, 0, "b") self.board[1][1] = Pawn(1, 1, "b") self.board[1][2] = Pawn(1, 2, "b") self.board[1][3] = Pawn(1, 3, "b") self.board[1][4] = Pawn(1, 4, "b") self.board[1][5] = Pawn(1, 5, "b") self.board[1][6] = Pawn(1, 6, "b") self.board[1][7] = Pawn(1, 7, "b") self.board[7][0] = Rook(7, 0, "w") self.board[7][1] = Knight(7, 1, "w") self.board[7][2] = Bishop(7, 2, "w") self.board[7][3] = Queen(7, 3, "w") self.board[7][4] = King(7, 4, "w") self.board[7][5] = Bishop(7, 5, "w") self.board[7][6] = Knight(7, 6, "w") self.board[7][7] = Rook(7, 7, "w") self.board[6][0] = Pawn(6, 0, "w") self.board[6][1] = Pawn(6, 1, "w") self.board[6][2] = Pawn(6, 2, "w") self.board[6][3] = Pawn(6, 3, "w") self.board[6][4] = Pawn(6, 4, "w") self.board[6][5] = Pawn(6, 5, "w") self.board[6][6] = Pawn(6, 6, "w") self.board[6][7] = Pawn(6, 7, "w") self.p1Name = "Player 1" self.p2Name = "Player 2" self.turn = "w" self.time1 = 900 self.time2 = 900 self.storedTime1 = 0 self.storedTime2 = 0 self.winner = None self.startTime = time.time()
def test_moves_start(self): pawn = Pawn(self.white, (4, 1)) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 2, moves)
def test_pawn_can_not_jump(self): self.p = Pawn('w') self.assertFalse(self.p.can_jump())
def test_moves_start_blocked(self): pawn = Pawn(self.white, (4, 1)) bishop = Bishop(self.white, (4, 3)) self.board.add_piece(bishop) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 1, moves)
def test_can_reach_pawn2(self): king = King(self.white, (4, 0)) pawn = Pawn(self.white, (4, 1)) self.board.add_piece(king) self.board.add_piece(pawn) self.assertTrue(pawn.can_reach(self.board, (4, 3)))
def test_moves_blocked_enemy(self): pawn = Pawn(self.white, (4, 4)) bishop = Bishop(self.black, (4, 5)) self.board.add_piece(bishop) moves = list(pawn.moves(self.board)) self.assertEquals(len(moves), 0, moves)