Complete the following function to validate the move of a given chess piece and return True (boolean) if the move is valid or False(boolean) if the move is invalid. The chessboard is given below for your reference. Function takes 3 arguments piece can be a "Knight" or "Bishop" currentpos(a string) is a combination of row and column it be anything between "a1" to "h8". currentpos represents the cell on the chessboard where the piece is currently located nextpos(a string) is also a combination of row and column and can also be between from "a1" to "h8". nextpos represents the cell to which the piece is intended to be moved I have a hard time understanding this question. Can anyone tell me the correct approach for this problem implementing bishop and knight?
def valid_move_or_not(piece,currentpos,nextpos): if currentpos == nextpos: return False if piece == 'Rook': return (currentpos[0] == nextpos[0]) or (currentpos[1] == nextpos[1]) if __name__=='__main__': #you can run your tests here print(valid_move_or_not("Knight","a1","a2"))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)