The code shown works, can you show the code that does not work.
you can also give some more efficient mechanism for identify d piece on chess board.
Each piece type should be represented by a class which probably should all inherit from a base class eg ChessPiece . The class type will then be the piece identifier and there could be a method eg isWhite() to determine which side the piece belongs too. Each piece class could also have methods to determine things such as all possible legal moves from the current position; handling of special rules such as castling, en passant and promotion etc.