1

The image attached shows that all of the pieces are not formatted onto the correct square. Is there a coordinate/vector value in pygame? Where I am able to move the pieces to the correct squares?

Also, would pygame.transform.scale(image) work in order to move the pieces to the correct square?

    wrimage = load_image("white_rook.png")
    self.pieces[WHITE][ROOK] = Piece(wrimage, WHITE, ROOK, 5)
    wkimage = load_image("white_knight.png")
    self.pieces[WHITE][KNIGHT] = Piece(wkimage, WHITE, KNIGHT, 3)
    wbimage = load_image("white_bishop.png")
    self.pieces[WHITE][BISHOP] = Piece(wbimage, WHITE, BISHOP, 3)
    wqimage = load_image("white_queen.png")
    self.pieces[WHITE][QUEEN] = Piece(wqimage, WHITE, QUEEN, 9)
    wgimage = load_image("white_king.png")
    self.pieces[WHITE][KING] = Piece(wgimage, WHITE, KING, 1000)
    wpimage = load_image("white_pawn.png")
    self.pieces[WHITE][PAWN] = Piece(wpimage, WHITE, PAWN, 1)

def set_up_initial_board(self):
    """Set up the pieces, assign them to standard starting locations"""

    #BLACK
    #-----
    #Rooks
    self.board[0][0] = self.pieces[BLACK][ROOK]
    self.board[0][7] = self.pieces[BLACK][ROOK]
    #Knights
    self.board[0][1] = self.pieces[BLACK][KNIGHT]
    self.board[0][6] = self.pieces[BLACK][KNIGHT]
    #Bishops
    self.board[0][2] = self.pieces[BLACK][BISHOP]
    self.board[0][5] = self.pieces[BLACK][BISHOP]
    #Queen
    self.board[0][3] = self.pieces[BLACK][QUEEN]
    #King
    self.board[0][4] = self.pieces[BLACK][KING]
    #Pawns
    for col in range(SIZE):
        self.board[1][col] = self.pieces[BLACK][PAWN]

    #WHITE
    #-----
    #Rooks
    self.board[7][0] = self.pieces[WHITE][ROOK]
    self.board[7][7] = self.pieces[WHITE][ROOK]
    #Knights
    self.board[7][1] = self.pieces[WHITE][KNIGHT]
    self.board[7][6] = self.pieces[WHITE][KNIGHT]
    #Bishops
    self.board[7][2] = self.pieces[WHITE][BISHOP]
    self.board[7][5] = self.pieces[WHITE][BISHOP]
    #Queen
    self.board[7][3] = self.pieces[WHITE][QUEEN]
    #King
    self.board[7][4] = self.pieces[WHITE][KING]
    #Pawns
    for col in range(SIZE):
        self.board[6][col] = self.pieces[WHITE][PAWN] 

Is there a way to format the pieces to the correct squares, because the pawns should be moved to the next row, and the pieces behind the row of pawns shown in the image are off the chessboard.

(PS, the board size image is 320x320 pixels)

ethanw_8
  • 11
  • 1
  • write own function to convert `row, column` to `x,y` – furas Feb 27 '22 at 12:50
  • something like `x = (column-1) * square_size + left_margin` and `y = (row-1) * square_size + top_margin` and it should give top-left point in cell. If you want center point then add also `square_size//2` – furas Feb 27 '22 at 12:57
  • and if you numbering rows from bottom to top then you will need `(8-row)` instead of `(row-1)` – furas Feb 27 '22 at 13:01

0 Answers0